I realize this is a bit of an old thread; however, I ran across a use
case where I would like to be able to modify HandlerManager. In our
application we would like to be able to "stop" an event from being
fired further.
One example, we have three event handlers that can be added A, B, C
(validation, required check, and save rpc). We add the handlers to a
button in that order when needed (sub class determine which handlers
to add). We want to be able to specify in A or B handler that the
event should stop propagating to other handlers.
We tried a couple of different things (including starting to add our
own event handling logic) and we settled on two changes to GWT
itself. We added a method to GWTEvent:
- public void stop(); /* record that the event should not be passed
to more handlers */
- public void isStopped(); /* is the event stopped for further
processing */
- public void unStop(); /* reset the stop flag to be false - did in
case event is reused */
In our event handlers we can now call event.stop() to stop further
propagation.
In HandlerManager.HandlerRegister we modified
private <H extends EventHandler> void fireEvent(GwtEvent<H> event,
boolean isReverseOrder) {
Type<H> type = event.getAssociatedType();
int count = getHandlerCount(type);
if (isReverseOrder) {
for (int i = count - 1; i >= 0; i--) {
H handler = this.<H> getHandler(type, i);
event.dispatch(handler);
if(event.isStopped()) { // CUSTOM: event stop processing
event.unStop(); // did this in case events are reused
break;
}
}
} else {
for (int i = 0; i < count; i++) {
H handler = this.<H> getHandler(type, i);
event.dispatch(handler);
if(event.isStopped()) { // CUSTOM: event stop processing
event.unStop(); // did this in case events are reused
break;
}
}
}
}
Just thought I would send a quick note in case future changes are
being considered for HandlerManager (realizing 2.0 time frame is
probably off the table).
Chris....