/** * Wraps the given {@code widget} with a ScollPanel and builds an * {@link AdapterField} for it. * * @param label * The field label. If {@code blank}, label separator is * automatically disabled. * @param widget * The widget wrapped into the scroll panel and into the adapter * field. * @param width * Width of the given widget. * @param height * Height of the scroll panel. * @return The field. */ public static AdapterField adapterWithScrollbars(final String label, final IsWidget widget, final int width, final int height) { final ScrollPanel scrollPanel = new ScrollPanel(); scrollPanel.setWidget(Widget.asWidgetOrNull(widget)); scrollPanel.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { scrollPanel.setWidth(width + "px"); } }); scrollPanel.setHeight(height + "px"); return adapter(label, scrollPanel); }
/** * @see com.google.gwt.user.client.ui.Image#setUrl(com.google.gwt.safehtml.shared * .SafeUri) */ @Override public void setUrl(final SafeUri url) { if ( isHiddenAndAttached() ) { super.setUrl(url); } else { // Do this later to avoid problems in IE hide(); this.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { setUrl(url); } }); } }
public OLCesiumPanel(OLCesiumOptions options) { super(); final Element element = getElement(); // Some strange, but ol-cesium set style for div's elements to absolute. Fix this. element.getStyle().setProperty("position", "relative"); options.target = element; RootPanel.getBodyElement().appendChild(element); olCesium = new OLCesium(options); super.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent attachEvent) { if (!attachEvent.isAttached()) { element.removeAllChildren(); element.removeFromParent(); } } }); }
public OwnerJobTrend(){ date=new DateField(); date.setEditable(false); date.setAllowBlank(false); date.setValue(new Date()); HorizontalLayoutContainer form=new HorizontalLayoutContainer(); form.add(new FieldLabel(date,"日期"),new HorizontalLayoutData()); form.add(submit,new HorizontalLayoutData()); container.add(form,new VerticalLayoutData(1,30)); container.addAttachHandler(new Handler() { public void onAttachOrDetach(AttachEvent event) { submit.fireEvent(new SelectEvent()); } }); }
public RunningJobTrend(){ start=new DateField(); start.setEditable(false); start.setValue(new Date(new Date().getTime()-7*24*60*60*1000L)); end=new DateField(); end.setEditable(false); end.setValue(new Date()); HorizontalLayoutContainer form=new HorizontalLayoutContainer(); form.add(new FieldLabel(start, "起始日期"),new HorizontalLayoutData(0.3,1)); form.add(new FieldLabel(end,"截止日期"),new HorizontalLayoutData(0.3, 1)); form.add(submit,new HorizontalLayoutData(-1,-1)); container.add(form,new VerticalLayoutData(1, 30)); container.addAttachHandler(new Handler() { public void onAttachOrDetach(AttachEvent event) { submit.fireEvent(new SelectEvent()); } }); }
/** * 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 ArchiveEntryImagePanel(ArchiveEntryCollectionRef arc, ArchiveEntry entry) { _arc = arc; _entry = entry; _ap = new AbsolutePanel(); _ap.fitToParent(); _ap.setOverflow(Overflow.HIDDEN); initWidget(_ap); addAttachHandler(new Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { loadImage(); } } }); }
private void setupDefaultHandlers() { //Prevent DOMElements scrolling into view when they receive the focus domElementContainer.addDomHandler(new ScrollHandler() { @Override public void onScroll(final ScrollEvent scrollEvent) { domElementContainer.getElement().setScrollTop(0); domElementContainer.getElement().setScrollLeft(0); } }, ScrollEvent.getType()); addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(final AttachEvent event) { if (event.isAttached()) { onResize(); } } }); addMouseDownHandler((e) -> setFocus(true)); }
@Override public void acquireLockOnDemand() { if (lockTarget == null) { return; } final Widget widget = getLockTargetWidget(); final Element element = widget.getElement(); acquireLockOnDemand(element); widget.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { // Handle widget reattachment/reparenting if (event.isAttached()) { acquireLockOnDemand(element); } } }); }
@Override public void setContent(Widget widget) { if (widget instanceof LayoutPanel) { mainPanel = (LayoutPanel)widget; mainPanel.insert(headerPanel, 0); if (toolbar != null) { setToolbar(toolbar); } } mainPanel.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { // The mainPanel is the widget which being added and not this view, // so the onAttach and onDetach of the view will not be invoked if (event.isAttached()) { onAttach(); } else { onDetach(); } } }); }
/** * Called after construction. */ @PostConstruct protected void postConstruct() { addAttachHandler(new Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { cid = generateUniqueCid(); getElement().addClassName(cid); initPicker(cid,DEFAULT_DATE_TIME_FORMAT); } else { removePicker(cid); } } }); }
/** * Called after construction. */ @PostConstruct protected void postConstruct() { addAttachHandler(new Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { cid = generateUniqueCid(); getElement().addClassName(cid); init(cid); } else { remove(cid); } } }); }
protected void addWidgetDetachHandler() { if (this.widget != null) { detachHandler = this.widget.addAttachHandler(new AttachEvent.Handler() { boolean detaching = false; @Override public void onAttachOrDetach(AttachEvent event) { if (!detaching) { detaching = true; if (!event.isAttached() && getParent() instanceof HasWidgets) { ((HasWidgets) getParent()).remove((Widget) event.getSource()); } widget = null; if (detachHandler != null) { detachHandler.removeHandler(); detachHandler = null; } setParentWidget(null); removeFromParent(); } } }); } }
public SimulationPresenter(final String simulationId, final String instanceId, final long iteration, ManagerClientFactory clientFactory) { this.notificationBar = clientFactory.getNotificationBar(); this.view = clientFactory.getSimulationView(); view.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { loadState(simulationId, instanceId, iteration); addScrollHandler(); } else { updateTimer.cancel(); if (scrollHandler != null) { scrollHandler.removeHandler(); scrollHandler = null; } } } }); }
@Override protected boolean createFieldWidget() { initWidget(uiBinder.createAndBindUi(this)); field = textArea; toolbar.initToolBar(textArea); textArea.addAttachHandler(new Handler() { @Override public void onAttachOrDetach(AttachEvent event) { AtomTools.log(Level.FINE, "textArea.onAttachOrDetach - " + event.toDebugString(), this); fixIFrameDefaultFont(true); } }); fixIFrameDefaultFont(true); return false; }
private void updateVerticalScrollGridDelegation() { // register scroll handler to Gantt widget ganttScrollHandlerRegistration = getWidget().addDomHandler(ganttScrollHandler, ScrollEvent.getType()); scrollDelegateHandlerRegistration = delegateScrollGridTarget.addScrollHandler(gridScrollDelegateTargetHandler); // add detach listener to unregister scroll handler when its // detached. delegateScrollGridTarget.addAttachHandler(new Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (!event.isAttached() && scrollDelegateHandlerRegistration != null) { scrollDelegateHandlerRegistration.removeHandler(); } } }); }
private void updateVerticalScrollTableDelegation() { // register scroll handler to Gantt widget ganttScrollHandlerRegistration = getWidget().addDomHandler(ganttScrollHandler, ScrollEvent.getType()); // register a scroll handler to 'delegation' scroll panel. scrollDelegateHandlerRegistration = delegateScrollPanelTarget.addScrollHandler(scrollDelegateTargetHandler); // add detach listener to unregister scroll handler when its // detached. delegateScrollPanelTarget.addAttachHandler(new Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (!event.isAttached() && scrollDelegateHandlerRegistration != null) { scrollDelegateHandlerRegistration.removeHandler(); } } }); }
public GuidedDecisionTableEditorViewImpl() { initWidget( uiBinder.createAndBindUi( this ) ); //Disable LockManager's default "Lock on Demand" behaviour container.getElement().setAttribute( "data-uf-lock", "false" ); addAttachHandler( new AttachEvent.Handler() { @Override public void onAttachOrDetach( final AttachEvent event ) { if ( event.isAttached() ) { getElement().getParentElement().getStyle().setHeight( 100.0, Style.Unit.PCT ); getElement().getParentElement().getStyle().setWidth( 100.0, Style.Unit.PCT ); } } } ); }
/** * Called after construction. */ @PostConstruct protected void postConstruct() { addAttachHandler(new Handler() { @Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { cid = generateUniqueCid(); getElement().addClassName(cid); initPicker(cid); } else { removePicker(cid); } } }); }
/** * Creates a new TimeSlider object. * * @param params - Parameters for the time slider object. * @param loadHandler - handler to fire when dijit is created. All method calls will fail untill this * event fires. */ public TimeSlider(Parameters params, DijitLoadHandler handler) { if( !assertLoaded() ) return; loadHandler = handler; parameters = params; initWidget(panel); addAttachHandler(new Handler(){ @Override public void onAttachOrDetach(AttachEvent event) { if( event.isAttached() && jso == null ) { jso = _create(parameters, panel.getElement()); if( loadHandler != null ) loadHandler.onLoad(); } } }); }
/** * Creates a new Attribute Inspector object. * * @param params - input parameters */ public AttributeInspector(Parameters params) { if( !assertLoaded() ) return; parameters = params; initWidget(panel); addAttachHandler(new Handler(){ @Override public void onAttachOrDetach(AttachEvent event) { if(jso == null ) jso = create(parameters); } }); }
/** * Creates a new Editor object. * * @param params - Parameters that define the functionality of the editor widget. Create a * new settings object to pass to the widget */ public Editor(Parameters params) { if( !assertLoaded() ) return; parameters = params; initWidget(panel); addAttachHandler(new Handler(){ @Override public void onAttachOrDetach(AttachEvent event) { if( jso == null ) jso = create(parameters); } }); }
/** * Creates a new Legend dijit. Should be called after all the layers have been loaded in the map, * typically in the map's onLayerAddResult event. * * @param params - Parameters used to configure the dijit. See the list below for details. */ public Legend(Parameters params) { if( !assertLoaded() ) return; parameters = params; initWidget(panel); addAttachHandler(new Handler(){ @Override public void onAttachOrDetach(AttachEvent event) { if( jso == null ) jso = create(parameters); } }); }
/** * Creates a new TemplatePicker object that displays a gallery of templates * from the input feature layers or items. A symbol and label is displayed * for each template. The symbol is defined by the template's feature type. * The label is the template's name. * * @param params - FeatureLayers or items are required all other parameters * are optional. See options list. */ public TemplatePicker(Parameters params) { if( !assertLoaded() ) return; parameters = params; initWidget(panel); addAttachHandler(new Handler(){ @Override public void onAttachOrDetach(AttachEvent event) { if( jso == null ) jso = create(parameters); } }); }
/** * Creates a new BasemapGallery dijit. * * @param params - Parameters used to configure the widgit. See the list below for details. */ public BasemapGallery(Parameters params) { if( !assertLoaded() ) return; initWidget(panel); parameters = params; addAttachHandler(new Handler(){ @Override public void onAttachOrDetach(AttachEvent event) { if( jso == null ) jso = create(parameters); } }); }
@Override public void onAttachOrDetach(AttachEvent event) { if (!wasChecked) { checkStylesAndShowError(); wasChecked = true; } }
@Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { final HandlerRegistration pauseHandlerRegistration = registerPauseHandlerOnPageChange(); this.handlerRegistration = Optional.of(pauseHandlerRegistration); } else { clearHandler(); } }
@Test public void shouldRegisterHandlerAtFirstAttachEvent() { // given AttachEvent attachEvent = mock(AttachEvent.class); when(attachEvent.isAttached()).thenReturn(Boolean.TRUE); HandlerRegistration handlerRegistration = mock(HandlerRegistration.class); when(eventsBus.addHandler(eq(PlayerEvent.getType(PlayerEventTypes.PAGE_CHANGE)), any(AutoPauseOnPageChangeHandler.class))).thenReturn( handlerRegistration); // when testObj.onAttachOrDetach(attachEvent); // then verify(eventsBus).addHandler(eq(PlayerEvent.getType(PlayerEventTypes.PAGE_CHANGE)), any(AutoPauseOnPageChangeHandler.class)); }
@Test public void shouldRemoveHandlerAtSecondAttachEvent() { // given HandlerRegistration handlerRegistration = callFirstAttachEvent(); AttachEvent event = mock(AttachEvent.class); when(event.isAttached()).thenReturn(Boolean.FALSE); // when testObj.onAttachOrDetach(event); // then verify(handlerRegistration).removeHandler(); }
private HandlerRegistration callFirstAttachEvent() { AttachEvent attachEvent = mock(AttachEvent.class); when(attachEvent.isAttached()).thenReturn(Boolean.TRUE); HandlerRegistration handlerRegistration = mock(HandlerRegistration.class); when(eventsBus.addHandler(eq(PlayerEvent.getType(PlayerEventTypes.PAGE_CHANGE)), any(AutoPauseOnPageChangeHandler.class))).thenReturn( handlerRegistration); testObj.onAttachOrDetach(attachEvent); return handlerRegistration; }
@Override public void setResource(final ImageResource resource) { if ( isHiddenAndAttached() ) { super.setResource(resource); } else { // Do this later to avoid problems in IE hide(); this.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent event) { setResource(resource); } }); } }
public CesiumWidgetPanel(CesiumWidgetOptions options) { super(); Element element = getElement(); RootPanel.getBodyElement().appendChild(element); _cesiumWidget = new CesiumWidget(element, options); super.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent attachEvent) { if (!attachEvent.isAttached()) { _cesiumWidget.destroy(); } } }); }
public ViewerPanel(ViewerOptions options) { super(); Element element = getElement(); RootPanel.getBodyElement().appendChild(element); _viewer = new Viewer(element, options); super.addAttachHandler(new AttachEvent.Handler() { @Override public void onAttachOrDetach(AttachEvent attachEvent) { if (!attachEvent.isAttached()) { _viewer.destroy(); } } }); }
@Override public void onAttachOrDetach(AttachEvent attachEvent) { if (attachEvent.isAttached()) { textField.getElement().getParentElement() .insertAfter(resetButtonElement, textField.getElement()); updateResetButtonVisibility(); addResetButtonClickListener(resetButtonElement); } else { Element parentElement = resetButtonElement.getParentElement(); if (parentElement != null) { parentElement.removeChild(resetButtonElement); } removeResetButtonClickListener(resetButtonElement); } }
public CodeMirror(final CodeMirrorConfig config){ setElement(DOM.createDiv()); addAttachHandler(new Handler() { public void onAttachOrDetach(AttachEvent event) { if(event.isAttached()){ cm=create(getElement(), config.toJsObject(CodeMirror.this)); } } }); sinkEvents(Event.MOUSEEVENTS|Event.ONCLICK); }
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(); } } }); }
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); } } }
@Override protected void onAttach() { if (isAttached()) { throw new IllegalStateException("Text is already attached!"); } isAttached = true; onLoad(); AttachEvent.fire(this, isAttached); }