Java Code Examples for com.vaadin.client.ui.VMenuBar#getItems()

The following examples show how to use com.vaadin.client.ui.VMenuBar#getItems() . 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 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 2
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();
                }
            }
        }
    }