Required Information

Version(s) of Ext GWT
GXT 3.0.4

Browser versions and OS
(and desktop environment, if applicable)
  • Internet Explorer 9, Windows 7
  • Firefox latest, Windows 7
  • Chrome latest, Windows 7

Virtual Machine
N/A

Description
I've been struggling with a derivative of the PagingToolBar class that consistently is disabled when the user changes a checkbox filter (among other scenarios).

The situation is that the PagingToolBar does not handle multiple concurrent service requests well. The toolbar always ends up disabled and remains disabled no matter what.



Run mode
both development mode, production mode

Steps to reproduce the problem
  1. Start running in development mode in Eclipse
  2. Open app in browser
  3. specify select grid filter
  4. observe single connection to remote server
  5. modify select grid filter
  6. observe TWO connections to remote server
  7. observe paging toolbar is disabled.

Expected result
The paging toolbar be enabled after the second connection is complete.

Actual result
The paging toolbar is forever disabled.

Test case
These few lines of code

Code:
public void onBeforeLoad(final BeforeLoadEvent<PagingLoadConfig> event) {
     loading = true;
     savedEnableState = isEnabled();
     setEnabled(false);
essentially fail to trap the enabled state when called twice+ in a row prior to the return of the first call.


Helpful Information

Possible fix
building a reference counter that will end with the toolbar enabled after the last call.

Code:
	private LoaderHandler<PagingLoadConfig, ?> handler = new LoaderHandler<PagingLoadConfig, PagingLoadResult<?>>() {

		/**
		 * count the number of concurrent calls to Load in order to rescue the 
		 */
		private int concurrentLoaderCounter = 0;

		@Override
		public void onBeforeLoad(final BeforeLoadEvent<PagingLoadConfig> event) {
			concurrentLoaderCounter++;
			setEnabled(false);
			refresh.setIcon(appearance.loading());
			Scheduler.get().scheduleFinally(new ScheduledCommand() {

				@Override
				public void execute() {
					if (event.isCancelled()) {
						maybeEnableButton();
						OuaePagingToolbar.this.onLoad(new LoadEvent<PagingLoadConfig, PagingLoadResult<?>>(config, new PagingLoadResultBean<Object>(null, totalLength, start)));
					}
				}
			});
		}

		@Override
		public void onLoad(LoadEvent<PagingLoadConfig, PagingLoadResult<?>> event) {
			maybeEnableButton();
			OuaePagingToolbar.this.onLoad(event);
		}

		@Override
		public void onLoadException(LoadExceptionEvent<PagingLoadConfig> event) {
			maybeEnableButton();
		}
		
		/**
		 * decrement the concurrent load counter
		 * if last load, enable button and set icon
		 */
		private void maybeEnableButton() {
			if (--concurrentLoaderCounter < 1) {
				setEnabled(true);
				refresh.setIcon(appearance.refresh());
			}
		}
	};