use of com.vaadin.client.ui.Icon in project cuba by cuba-platform.
the class CubaMenuBarWidget method buildItemHTML.
@Override
public String buildItemHTML(UIDL item) {
// Construct html from the text and the optional icon
// Haulmont API : Added support for shortcuts
StringBuilder itemHTML = new StringBuilder();
if (item.hasAttribute("separator")) {
itemHTML.append("<span>---</span><span>---</span>");
} else {
itemHTML.append("<span class=\"").append(getStylePrimaryName()).append("-menuitem-caption\">");
Icon icon = client.getIcon(item.getStringAttribute("icon"));
if (icon != null) {
itemHTML.append(icon.getElement().getString());
}
String itemText = item.getStringAttribute("text");
if (!htmlContentAllowed) {
itemText = WidgetUtil.escapeHTML(itemText);
}
itemHTML.append(itemText);
itemHTML.append("</span>");
// Add submenu indicator
if (item.getChildCount() > 0) {
String bgStyle = "";
itemHTML.append("<span class=\"").append(getStylePrimaryName()).append("-submenu-indicator\"").append(bgStyle).append("><span class=\"").append(getStylePrimaryName()).append("-submenu-indicator-icon\"").append("><span class=\"text\">►</span></span></span>");
} else {
itemHTML.append("<span class=\"");
String shortcut = "";
if (item.hasAttribute("shortcut")) {
shortcut = item.getStringAttribute("shortcut");
} else {
itemHTML.append(getStylePrimaryName()).append("-menuitem-empty-shortcut ");
}
itemHTML.append(getStylePrimaryName()).append("-menuitem-shortcut\">").append(shortcut).append("</span");
}
}
return itemHTML.toString();
}
use of com.vaadin.client.ui.Icon in project cuba by cuba-platform.
the class CubaSideMenuWidget method addItems.
protected void addItems(JsonArray items, HasWidgets container) {
for (int i = 0; i < items.length(); i++) {
JsonObject itemJson = items.getObject(i);
Icon icon = null;
String iconId = itemJson.getString("icon");
if (menuItemIconSupplier != null && iconId != null) {
icon = menuItemIconSupplier.apply(iconId);
}
boolean captionAsHtml = false;
if (itemJson.hasKey("captionAsHtml")) {
captionAsHtml = itemJson.getBoolean("captionAsHtml");
}
MenuItemWidget menuItemWidget = new MenuItemWidget(this, itemJson.getString("id"), icon, itemJson.getString("styleName"), itemJson.getString("caption"), captionAsHtml);
menuItemWidget.setDescription(itemJson.getString("description"));
menuItemWidget.setCubaId(itemJson.getString("cubaId"));
menuItemWidget.setBadgeText(itemJson.getString("badgeText"));
container.add(menuItemWidget);
JsonArray childrenItemsJson = itemJson.getArray("children");
if (childrenItemsJson != null) {
MenuContainerWidget menuContainerWidget = new MenuContainerWidget(this, menuItemWidget);
addItems(childrenItemsJson, menuContainerWidget);
container.add(menuContainerWidget);
menuItemWidget.setSubMenu(menuContainerWidget);
if (itemJson.hasKey("expanded") && itemJson.getBoolean("expanded")) {
menuContainerWidget.setExpanded(true);
}
}
}
}
use of com.vaadin.client.ui.Icon in project cuba by cuba-platform.
the class CubaFileUploadConnector method onStateChanged.
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
if (stateChangeEvent.hasPropertyChanged("caption") || stateChangeEvent.hasPropertyChanged("captionAsHtml")) {
VCaption.setCaptionText(getWidget().submitButton.captionElement, getState());
if ("".equals(getState().caption) || getState().caption == null) {
getWidget().submitButton.addStyleDependentName("empty-caption");
} else {
getWidget().submitButton.removeStyleDependentName("empty-caption");
}
}
if (stateChangeEvent.hasPropertyChanged("resources")) {
if (getWidget().submitButton.icon != null) {
getWidget().submitButton.wrapper.removeChild(getWidget().submitButton.icon.getElement());
getWidget().submitButton.icon = null;
}
Icon icon = getIcon();
if (icon != null) {
getWidget().submitButton.icon = icon;
if (getState().iconAltText != null) {
icon.setAlternateText(getState().iconAltText);
} else {
icon.setAlternateText("");
}
getWidget().submitButton.wrapper.insertBefore(icon.getElement(), getWidget().submitButton.captionElement);
}
}
if (stateChangeEvent.hasPropertyChanged("multiSelect")) {
getWidget().setMultiSelect(getState().multiSelect);
}
if (stateChangeEvent.hasPropertyChanged("iconAltText")) {
if (getWidget().submitButton.icon != null) {
Icon icon = getWidget().submitButton.icon;
if (getState().iconAltText != null) {
icon.setAlternateText(getState().iconAltText);
} else {
icon.setAlternateText("");
}
}
}
if (stateChangeEvent.hasPropertyChanged("progressWindowCaption")) {
getWidget().progressWindowCaption = getState().progressWindowCaption;
}
if (stateChangeEvent.hasPropertyChanged("cancelButtonCaption")) {
getWidget().cancelButtonCaption = getState().cancelButtonCaption;
}
if (stateChangeEvent.hasPropertyChanged("unableToUploadFileMessage")) {
getWidget().unableToUploadFileMessage = getState().unableToUploadFileMessage;
}
if (stateChangeEvent.hasPropertyChanged("accept")) {
getWidget().setAccept(getState().accept);
}
if (stateChangeEvent.hasPropertyChanged("fileSizeLimit")) {
getWidget().fileSizeLimit = getState().fileSizeLimit;
}
if (stateChangeEvent.hasPropertyChanged("permittedExtensions")) {
getWidget().permittedExtensions = getState().permittedExtensions;
}
if (stateChangeEvent.hasPropertyChanged("dropZone")) {
ComponentConnector dropZone = (ComponentConnector) getState().dropZone;
getWidget().setDropZone(dropZone != null ? dropZone.getWidget() : null, getState().dropZonePrompt);
}
if (stateChangeEvent.hasPropertyChanged("pasteZone")) {
ComponentConnector pasteZone = (ComponentConnector) getState().pasteZone;
getWidget().setPasteZone(pasteZone != null ? pasteZone.getWidget() : null);
}
if (!isEnabled() || isReadOnly()) {
getWidget().disableUpload();
} else {
getWidget().enableUpload();
}
}
use of com.vaadin.client.ui.Icon in project cuba by cuba-platform.
the class CubaOrderedActionsLayoutConnector method updateCaptionInternal.
@Override
protected void updateCaptionInternal(ComponentConnector child) {
// CAUTION copied from superclass
CubaOrderedLayoutSlot slot = (CubaOrderedLayoutSlot) getWidget().getSlot(child.getWidget());
String caption = child.getState().caption;
URLReference iconUrl = child.getState().resources.get(ComponentConstants.ICON_RESOURCE);
String iconUrlString = iconUrl != null ? iconUrl.getURL() : null;
Icon icon = child.getConnection().getIcon(iconUrlString);
List<String> styles = child.getState().styles;
String error = child.getState().errorMessage;
boolean showError = error != null;
if (child.getState() instanceof AbstractFieldState) {
AbstractFieldState abstractFieldState = (AbstractFieldState) child.getState();
showError = showError && !abstractFieldState.hideErrors;
}
boolean required = false;
if (child instanceof AbstractFieldConnector) {
required = ((AbstractFieldConnector) child).isRequired();
}
boolean enabled = child.isEnabled();
if (slot.hasCaption() && null == caption) {
slot.setCaptionResizeListener(null);
}
// Haulmont API
boolean contextHelpIconEnabled = isContextHelpIconEnabled(child.getState());
// Haulmont API
slot.setCaption(caption, contextHelpIconEnabled, icon, styles, error, showError, required, enabled, child.getState().captionAsHtml);
AriaHelper.handleInputRequired(child.getWidget(), required);
AriaHelper.handleInputInvalid(child.getWidget(), showError);
AriaHelper.bindCaption(child.getWidget(), slot.getCaptionElement());
if (slot.hasCaption()) {
CaptionPosition pos = slot.getCaptionPosition();
slot.setCaptionResizeListener(slotCaptionResizeListener);
if (child.isRelativeHeight() && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM)) {
getWidget().updateCaptionOffset(slot.getCaptionElement());
} else if (child.isRelativeWidth() && (pos == CaptionPosition.LEFT || pos == CaptionPosition.RIGHT)) {
getWidget().updateCaptionOffset(slot.getCaptionElement());
}
}
}
use of com.vaadin.client.ui.Icon in project cuba by cuba-platform.
the class CubaUploadConnector method onStateChanged.
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
if (stateChangeEvent.hasPropertyChanged("accept")) {
getWidget().setAccept(getState().accept);
}
if (stateChangeEvent.hasPropertyChanged("resources")) {
if (getWidget().submitButton.icon != null) {
getWidget().submitButton.wrapper.removeChild(getWidget().submitButton.icon.getElement());
getWidget().submitButton.icon = null;
}
Icon icon = getIcon();
if (icon != null) {
getWidget().submitButton.icon = icon;
getWidget().submitButton.wrapper.insertBefore(icon.getElement(), getWidget().submitButton.captionElement);
}
}
}
Aggregations