public void setAttribute(String attr, String value) { if (widget != null) { AttachEvent.Handler handler = event -> { widget.getElement().setAttribute(attr, value); }; if (widget.isAttached()) { handler.onAttachOrDetach(null); } else { EventHelper.onAttachOnce(widget, handler); } } else { GWT.log("Please initialize the Target widget.", new IllegalStateException()); } }
handler.onAttachOrDetach(null); } else { attachHandler = componentWidget.addAttachHandler(handler);
handler.onAttachOrDetach(null); } else { attachHandler = componentWidget.addAttachHandler(handler);
/** * Add an {@code AttachHandler} for attachment events. * * @param handler Attach event handler. * @param oneTime Only execute this handler once, then detach handler. * @return The events handler registration. */ public HandlerRegistration addAttachHandler(final AttachEvent.Handler handler, boolean oneTime) { if (!oneTime) { return addAttachHandler(handler); } else { final HandlerRegistration[] registration = {null}; registration[0] = addAttachHandler(event -> { handler.onAttachOrDetach(event); if (registration[0] != null) { registration[0].removeHandler(); } }); return registration[0]; } }
/** * Add an {@code AttachHandler} for attachment events. * * @param handler Attach event handler. * @param oneTime Only execute this handler once, then detach handler. * @return The events handler registration. */ public HandlerRegistration addAttachHandler(final AttachEvent.Handler handler, boolean oneTime) { if (!oneTime) { return addAttachHandler(handler); } else { final HandlerRegistration[] registration = {null}; registration[0] = addAttachHandler(event -> { handler.onAttachOrDetach(event); if (registration[0] != null) { registration[0].removeHandler(); } }); return registration[0]; } }
public XScrollPanel(Panel container) { super("x-scroll"); add(scrollBar); AttachEvent.Handler handler = event -> { int barSize = JQueryExtension.scrollBarWidth(container.getElement()); if (barSize < 1) { barSize = 8; } super.setStyle("width: calc(100% - " + barSize + "px)"); setHeight(barSize + "px"); }; if(!container.isAttached()) { EventHelper.onAttachOnce(container, handler); } else { handler.onAttachOrDetach(null); } }
public static void onAttachOnce(HasAttachHandlers has, AttachEvent.Handler handler) { HandlerRegistration[] reg = new HandlerRegistration[1]; if (has.isAttached()) { handler.onAttachOrDetach(null); } else { reg[0] = has.addAttachHandler(event -> { if (event.isAttached()) { handler.onAttachOrDetach(event); if (reg[0] != null) { reg[0].removeHandler(); } } }); } } }
public XScrollPanel(Panel container) { super("x-scroll"); add(scrollBar); AttachEvent.Handler handler = event -> { int barSize = JQueryExtension.scrollBarWidth(container.getElement()); if (barSize < 1) { barSize = 8; } super.setStyle("width: calc(100% - " + barSize + "px)"); setHeight(barSize + "px"); }; if(!container.isAttached()) { EventHelper.onAttachOnce(container, handler); } else { handler.onAttachOrDetach(null); } }
public static void onAttachOnce(HasAttachHandlers has, AttachEvent.Handler handler) { HandlerRegistration[] reg = new HandlerRegistration[1]; if (has.isAttached()) { handler.onAttachOrDetach(null); } else { reg[0] = has.addAttachHandler(event -> { if (event.isAttached()) { handler.onAttachOrDetach(event); if (reg[0] != null) { reg[0].removeHandler(); } } }); } } }
public void setAttribute(String attr, String value) { if (widget != null) { AttachEvent.Handler handler = event -> { widget.getElement().setAttribute(attr, value); }; if (widget.isAttached()) { handler.onAttachOrDetach(null); } else { EventHelper.onAttachOnce(widget, handler); } } else { GWT.log("Please initialize the Target widget.", new IllegalStateException()); } }
@Test public void handleWindowReparenting() { lockManager.acquireLockOnDemand(); verify(lockDemandDetector, times(1)).getLockDemandEventTypes(); final ArgumentCaptor<AttachEvent.Handler> handlerCaptor = ArgumentCaptor.forClass(AttachEvent.Handler.class); verify(widget, times(1)).addAttachHandler(handlerCaptor.capture()); handlerCaptor.getValue().onAttachOrDetach(new AttachEvent(true) { }); verify(lockDemandDetector, times(2)).getLockDemandEventTypes(); }
@Override protected void dispatch(AttachEvent.Handler handler) { handler.onAttachOrDetach(this); } }
@Test public void handleWindowReparenting() { lockManager.acquireLockOnDemand(); verify(lockDemandDetector, times(1)).getLockDemandEventTypes(); final ArgumentCaptor<AttachEvent.Handler> handlerCaptor = ArgumentCaptor.forClass(AttachEvent.Handler.class); verify(widget, times(1)).addAttachHandler(handlerCaptor.capture()); handlerCaptor.getValue().onAttachOrDetach(new AttachEvent(true) { }); verify(lockDemandDetector, times(2)).getLockDemandEventTypes(); }
@Override protected void dispatch(AttachEvent.Handler handler) { handler.onAttachOrDetach(this); } }
@Override protected void dispatch(AttachEvent.Handler handler) { handler.onAttachOrDetach(this); } }