Search in sources :

Example 1 with Icon

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\">&#x25BA;</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();
}
Also used : Icon(com.vaadin.client.ui.Icon)

Example 2 with Icon

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);
            }
        }
    }
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) Icon(com.vaadin.client.ui.Icon)

Example 3 with Icon

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();
    }
}
Also used : AbstractComponentConnector(com.vaadin.client.ui.AbstractComponentConnector) Icon(com.vaadin.client.ui.Icon)

Example 4 with Icon

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());
        }
    }
}
Also used : URLReference(com.vaadin.shared.communication.URLReference) AbstractFieldState(com.vaadin.shared.AbstractFieldState) AbstractFieldConnector(com.vaadin.client.ui.AbstractFieldConnector) Icon(com.vaadin.client.ui.Icon) CaptionPosition(com.vaadin.client.ui.orderedlayout.CaptionPosition)

Example 5 with Icon

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);
        }
    }
}
Also used : Icon(com.vaadin.client.ui.Icon)

Aggregations

Icon (com.vaadin.client.ui.Icon)5 AbstractComponentConnector (com.vaadin.client.ui.AbstractComponentConnector)1 AbstractFieldConnector (com.vaadin.client.ui.AbstractFieldConnector)1 CaptionPosition (com.vaadin.client.ui.orderedlayout.CaptionPosition)1 AbstractFieldState (com.vaadin.shared.AbstractFieldState)1 URLReference (com.vaadin.shared.communication.URLReference)1 JsonArray (elemental.json.JsonArray)1 JsonObject (elemental.json.JsonObject)1