private void render() { if (iconPosition == IconPosition.LEFT) { getElement().insertAfter(icon.getElement(), inputElem); } else { getElement().insertAfter(icon.getElement(), null); } }
/* * (non-Javadoc) * * @see com.google.gwt.user.client.ui.Widget#onBrowserEvent(com.google.gwt * .user.client.Event) */ @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (DOM.eventGetType(event) == Event.ONLOAD && icon.getElement() == DOM.eventGetTarget(event)) { if (layout.getLayoutManager() != null) { layout.getLayoutManager().layoutLater(); } else { layout.updateCaptionOffset(caption); } } }
private void updateItem(VCheckBox widget, JsonObject item, boolean requireInitialization) { String itemHtml = item.getString(ListingJsonConstants.JSONKEY_ITEM_VALUE); if (!isHtmlContentAllowed()) { itemHtml = WidgetUtil.escapeHTML(itemHtml); } String iconUrl = item.getString(ListingJsonConstants.JSONKEY_ITEM_ICON); if (iconUrl != null && iconUrl.length() != 0) { Icon icon = client.getIcon(iconUrl); itemHtml = icon.getElement().getString() + itemHtml; } widget.setHTML(itemHtml); widget.setValue(item.getBoolean(ListingJsonConstants.JSONKEY_ITEM_SELECTED)); setOptionEnabled(widget, item); if (requireInitialization) { widget.addStyleName(CLASSNAME_OPTION); widget.addClickHandler(this); getWidget().add(widget); } optionsToItems.put(widget, item); }
/** * Set the caption of the slot * * @param captionText The text of the caption * @param iconUrl The icon URL * @param styles The style names * @param error The error message * @param showError Should the error message be shown * @param required Is the (field) required * @param enabled Is the component enabled */ public void setCaption( String captionText, String iconUrl, List<String> styles, String error, boolean showError, boolean required, boolean enabled) { // TODO place for optimization: check if any of these have changed // since last time, and only run those changes // Caption wrappers if (captionText != null || iconUrl != null || error != null || required) { if (caption == null) { caption = DOM.createDiv(); captionWrap = DOM.createDiv(); captionWrap.addClassName(StyleConstants.UI_WIDGET); captionWrap.addClassName("v-has-caption"); getElement().appendChild(captionWrap); captionWrap.appendChild(getWidget().getElement()); } } else if (caption != null) { getElement().appendChild(getWidget().getElement()); captionWrap.removeFromParent(); caption = null; captionWrap = null; } // Caption text if (captionText != null) { if (this.captionText == null) { this.captionText = DOM.createSpan(); this.captionText.addClassName("v-captiontext"); caption.appendChild(this.captionText); } if (captionText.trim().equals("")) { this.captionText.setInnerHTML(" "); } else { this.captionText.setInnerText(captionText); } } else if (this.captionText != null) { this.captionText.removeFromParent(); this.captionText = null; } // Icon if (iconUrl != null) { if (icon == null) { icon = new Icon(); caption.insertFirst(icon.getElement()); } icon.setUri(iconUrl); } else if (icon != null) { icon.getElement().removeFromParent(); icon = null; } // Required if (required) { if (requiredIcon == null) { requiredIcon = DOM.createSpan(); // TODO decide something better (e.g. use CSS to insert the // character) requiredIcon.setInnerHTML("*"); requiredIcon.setClassName("v-required-field-indicator"); // The star should not be read by the screen reader, as it is // purely visual. Required state is set at the element level for // the screen reader. Roles.getTextboxRole().setAriaHiddenState(requiredIcon, true); } caption.appendChild(requiredIcon); } else if (requiredIcon != null) { requiredIcon.removeFromParent(); requiredIcon = null; } // Error if (error != null && showError) { if (errorIcon == null) { errorIcon = DOM.createSpan(); errorIcon.setClassName("v-errorindicator"); } caption.appendChild(errorIcon); } else if (errorIcon != null) { errorIcon.removeFromParent(); errorIcon = null; } if (caption != null) { // Styles caption.setClassName("v-caption"); if (styles != null) { for (String style : styles) { caption.addClassName("v-caption-" + style); } } if (enabled) { caption.removeClassName("v-disabled"); } else { caption.addClassName("v-disabled"); } // Caption position if (captionText != null || iconUrl != null) { setCaptionPosition(CaptionPosition.TOP); } else { setCaptionPosition(CaptionPosition.RIGHT); } } }