List of usage examples for com.google.gwt.event.logical.shared HasAttachHandlers addAttachHandler
HandlerRegistration addAttachHandler(AttachEvent.Handler handler);
From source file:gwt.material.design.client.base.helper.EventHelper.java
License:Apache License
public static void onAttachOnce(HasAttachHandlers has, AttachEvent.Handler handler) { HandlerRegistration[] reg = new HandlerRegistration[1]; reg[0] = has.addAttachHandler(event -> { if (event.isAttached()) { handler.onAttachOrDetach(event); if (reg[0] != null) { reg[0].removeHandler();//from w w w.j a va 2 s . com } } }); }
From source file:org.rstudio.studio.client.application.events.EventBus.java
License:Open Source License
/** * 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./*from w ww. j a v a 2s . co m*/ */ 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(); } }); }