Java Code Examples for com.vaadin.client.ui.VMenuBar#CustomMenuItem

The following examples show how to use com.vaadin.client.ui.VMenuBar#CustomMenuItem . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextMenuConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void updateItemFromState(VMenuBar.CustomMenuItem currentItem,
        ContextMenuItemState menuItemState) {
    currentItem.setSeparator(menuItemState.separator);
    currentItem.setEnabled(menuItemState.enabled);

    if (!menuItemState.separator && menuItemState.checked) {
        // if the selected attribute is present (either true or false),
        // the item is selectable
        currentItem.setCheckable(true);
        currentItem.setChecked(menuItemState.checked);
    } else {
        currentItem.setCheckable(false);
    }

    currentItem.setStyleName(menuItemState.styleName);

    currentItem.setDescription(menuItemState.description);
    currentItem.setDescriptionContentMode(
            menuItemState.descriptionContentMode);
    if (menuItemState.description != null) {
        currentItem.getElement().setAttribute("title",
                menuItemState.description);
    }

    currentItem.updateStyleNames();

}
 
Example 2
Source File: ContextMenuConnector.java    From context-menu with Apache License 2.0 5 votes vote down vote up
private void updateItemFromState(VMenuBar.CustomMenuItem currentItem,
        ContextMenuItemState menuItemState) {
    currentItem.setSeparator(menuItemState.separator);
    currentItem.setEnabled(menuItemState.enabled);

    if (!menuItemState.separator && menuItemState.checked) {
        // if the selected attribute is present (either true or false),
        // the item is selectable
        currentItem.setCheckable(true);
        currentItem.setChecked(menuItemState.checked);
    } else {
        currentItem.setCheckable(false);
    }

    currentItem.setStyleName(menuItemState.styleName);

    currentItem.setDescription(menuItemState.description);
    currentItem.setDescriptionContentMode(
            menuItemState.descriptionContentMode);
    if (menuItemState.description != null) {
        currentItem.getElement().setAttribute("title",
                menuItemState.description);
    }

    currentItem.updateStyleNames();

}
 
Example 3
Source File: CubaMenuBarConnector.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void assignAdditionalAttributes(VMenuBar.CustomMenuItem currentItem, UIDL item) {
    if (item.hasAttribute("cid")) {
        currentItem.getElement().setAttribute("cuba-id", item.getStringAttribute("cid"));
    }
}
 
Example 4
Source File: ContextMenuConnector.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void updateFromState(ContextMenuState state) {

        contextMenu.enabled = state.enabled;
        contextMenu.htmlContentAllowed = state.htmlContentAllowed;

        Stack<Iterator<ContextMenuItemState>> iteratorStack = new Stack<>();
        Stack<VMenuBar> menuStack = new Stack<>();
        VMenuBar currentMenu = contextMenuRoot.getSubMenu();
        currentMenu.clearItems();
        if (state.menuItems != null && !state.menuItems.isEmpty()) {
            Iterator<ContextMenuItemState> itr = state.menuItems.iterator();
            while (itr.hasNext()) {
                ContextMenuItemState menuItemState = itr.next();
                VMenuBar.CustomMenuItem currentItem;

                boolean itemHasCommand = menuItemState.command;
                boolean itemIsCheckable = menuItemState.checkable;

                String iconUrl = menuItemState.icon == null ? null
                        : menuItemState.icon.getURL();
                boolean subMenu = menuItemState.childItems != null
                        && !menuItemState.childItems.isEmpty();
                String itemHTML = contextMenu.buildItemHTML(
                        menuItemState.separator, subMenu, iconUrl,
                        menuItemState.text);

                Command cmd = null;
                if (!menuItemState.separator) {
                    if (itemHasCommand || itemIsCheckable) {
                        // Construct a command that fires onMenuClick(int) with
                        // the
                        // item's id-number
                        cmd = () -> contextMenu.onMenuClick(menuItemState.id);
                    }
                }

                currentItem = currentMenu.addItem(itemHTML, cmd);
                currentItem.setId("" + menuItemState.id);
                updateItemFromState(currentItem, menuItemState);

                if (subMenu) {
                    menuStack.push(currentMenu);
                    iteratorStack.push(itr);
                    itr = menuItemState.childItems.iterator();
                    currentMenu = new VContextMenu(true, currentMenu);
                    getConnection().getVTooltip()
                            .connectHandlersToWidget(currentMenu);
                    // this is the top-level style that also propagates to items
                    // -
                    // any item specific styles are set above in
                    // currentItem.updateFromUIDL(item, client)
                    if (ComponentStateUtil.hasStyles(getState())) {
                        for (String style : getState().styles) {
                            currentMenu.addStyleDependentName(style);
                        }
                    }
                    currentItem.setSubMenu(currentMenu);
                }

                while (!itr.hasNext() && !iteratorStack.empty()) {
                    boolean hasCheckableItem = false;
                    for (VMenuBar.CustomMenuItem menuItem : currentMenu
                            .getItems()) {
                        hasCheckableItem = hasCheckableItem
                                || menuItem.isCheckable();
                    }
                    if (hasCheckableItem) {
                        currentMenu.addStyleDependentName("check-column");
                    } else {
                        currentMenu.removeStyleDependentName("check-column");
                    }

                    itr = iteratorStack.pop();
                    currentMenu = menuStack.pop();
                }
            }
        }
    }
 
Example 5
Source File: ContextMenuConnector.java    From context-menu with Apache License 2.0 4 votes vote down vote up
protected void updateFromState(ContextMenuState state) {

        contextMenu.enabled = state.enabled;
        contextMenu.htmlContentAllowed = state.htmlContentAllowed;

        Stack<Iterator<ContextMenuItemState>> iteratorStack = new Stack<>();
        Stack<VMenuBar> menuStack = new Stack<>();
        VMenuBar currentMenu = contextMenuRoot.getSubMenu();
        currentMenu.clearItems();
        if (state.menuItems != null && !state.menuItems.isEmpty()) {
            Iterator<ContextMenuItemState> itr = state.menuItems.iterator();
            while (itr.hasNext()) {
                ContextMenuItemState menuItemState = itr.next();
                VMenuBar.CustomMenuItem currentItem;

                boolean itemHasCommand = menuItemState.command;
                boolean itemIsCheckable = menuItemState.checkable;

                String iconUrl = menuItemState.icon == null ? null
                        : menuItemState.icon.getURL();
                boolean subMenu = menuItemState.childItems != null
                        && !menuItemState.childItems.isEmpty();
                String itemHTML = contextMenu.buildItemHTML(
                        menuItemState.separator, subMenu, iconUrl,
                        menuItemState.text);

                Command cmd = null;
                if (!menuItemState.separator) {
                    if (itemHasCommand || itemIsCheckable) {
                        // Construct a command that fires onMenuClick(int) with
                        // the
                        // item's id-number
                        cmd = () -> contextMenu.onMenuClick(menuItemState.id);
                    }
                }

                currentItem = currentMenu.addItem(itemHTML, cmd);
                currentItem.setId("" + menuItemState.id);
                updateItemFromState(currentItem, menuItemState);

                if (subMenu) {
                    menuStack.push(currentMenu);
                    iteratorStack.push(itr);
                    itr = menuItemState.childItems.iterator();
                    currentMenu = new VContextMenu(true, currentMenu);
                    getConnection().getVTooltip()
                            .connectHandlersToWidget(currentMenu);
                    // this is the top-level style that also propagates to items
                    // -
                    // any item specific styles are set above in
                    // currentItem.updateFromUIDL(item, client)
                    if (ComponentStateUtil.hasStyles(getState())) {
                        for (String style : getState().styles) {
                            currentMenu.addStyleDependentName(style);
                        }
                    }
                    currentItem.setSubMenu(currentMenu);
                }

                while (!itr.hasNext() && !iteratorStack.empty()) {
                    boolean hasCheckableItem = false;
                    for (VMenuBar.CustomMenuItem menuItem : currentMenu
                            .getItems()) {
                        hasCheckableItem = hasCheckableItem
                                || menuItem.isCheckable();
                    }
                    if (hasCheckableItem) {
                        currentMenu.addStyleDependentName("check-column");
                    } else {
                        currentMenu.removeStyleDependentName("check-column");
                    }

                    itr = iteratorStack.pop();
                    currentMenu = menuStack.pop();
                }
            }
        }
    }