Search in sources :

Example 1 with Handler

use of com.google.gwt.event.logical.shared.AttachEvent.Handler in project rstudio by rstudio.

the class EventBus method addHandler.

/**
    * Similar to 2-arg form of addHandler, but automatically removes handler
    * when the HasAttachHandlers object detaches.
    *
    * If the HasAttachHandlers object detaches and reattaches, the handler
    * will NOT automatically resubscribe.
    */
public <H extends EventHandler> void addHandler(HasAttachHandlers removeWhenDetached, Type<H> type, H handler) {
    final HandlerRegistration reg = addHandler(type, handler);
    removeWhenDetached.addAttachHandler(new Handler() {

        @Override
        public void onAttachOrDetach(AttachEvent event) {
            if (!event.isAttached())
                reg.removeHandler();
        }
    });
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) AttachEvent(com.google.gwt.event.logical.shared.AttachEvent) EventHandler(com.google.gwt.event.shared.EventHandler) Handler(com.google.gwt.event.logical.shared.AttachEvent.Handler)

Aggregations

AttachEvent (com.google.gwt.event.logical.shared.AttachEvent)1 Handler (com.google.gwt.event.logical.shared.AttachEvent.Handler)1 EventHandler (com.google.gwt.event.shared.EventHandler)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1