@Override public void setCaption(VCaption caption) { VCaption oldCaption = getCaption(); if (oldCaption != null) { getLayoutManager().unregisterDependency(layout, oldCaption.getElement()); } super.setCaption(caption); if (caption != null) { getLayoutManager() .registerDependency((ManagedLayout) child.getParent(), caption.getElement()); } }
/** Update caption for given widget */ public void updateCaption(ComponentConnector paintable) { Widget widget = paintable.getWidget(); VCaptionWrapper wrapper = childWidgetToCaptionWrapper.get(widget); if (VCaption.isNeeded(paintable.getState())) { if (wrapper == null) { // Add a wrapper between the layout and the child widget final String loc = getLocation(widget); super.remove(widget); wrapper = new VCaptionWrapper(paintable, client); super.add(wrapper, locationToElement.get(loc)); childWidgetToCaptionWrapper.put(widget, wrapper); } wrapper.updateCaption(); } else { if (wrapper != null) { // Remove the wrapper and add the widget directly to the layout final String loc = getLocation(widget); super.remove(wrapper); super.add(widget, locationToElement.get(loc)); childWidgetToCaptionWrapper.remove(widget); } } }
@Override public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); getWidget().disableOnClick = getState().disableOnClick; focusHandlerRegistration = EventHelper.updateFocusHandler(this, focusHandlerRegistration); blurHandlerRegistration = EventHelper.updateBlurHandler(this, blurHandlerRegistration); // Set text VCaption.setCaptionText(getWidget(), getState()); // handle error if (null != getState().errorMessage) { if (getWidget().errorIndicatorElement == null) { getWidget().errorIndicatorElement = DOM.createSpan(); getWidget().errorIndicatorElement.setClassName("v-errorindicator"); } getWidget() .getElement() .insertBefore(getWidget().errorIndicatorElement, getWidget().captionElement); } else if (getWidget().errorIndicatorElement != null) { getWidget().getElement().removeChild(getWidget().errorIndicatorElement); getWidget().errorIndicatorElement = null; } if (getWidget().icon != null) { getWidget().getElement().removeChild(getWidget().icon.getElement()); getWidget().icon = null; } Icon icon = getIcon(); if (icon != null) { getWidget().icon = icon; getWidget().getElement().insertBefore(icon.getElement(), getWidget().captionElement); icon.setAlternateText(getState().iconAltText); } }
@Override protected int getCaptionWidth() { VCaption caption = getCaption(); return caption != null ? getLayoutManager().getOuterWidth(caption.getElement()) : 0; }