if (isSeparator()) { throw new UnsupportedOperationException( "Cannot add items to a separator");
if (item.isSeparator()) { target.addAttribute("separator", true); } else {
.getDescriptionContentMode(); menuItemState.enabled = item.isEnabled(); menuItemState.separator = item.isSeparator(); menuItemState.icon = ResourceReference.create(item.getIcon(), this, "");
for (MenuBar.MenuItem sourceItem:source.getChildren()) if (sourceItem.isSeparator())
private static void merge(MenuBar.MenuItem target, MenuBar.MenuItem source, List<MenuBar.MenuItem> added) { if (source.hasChildren()) { List<MenuBar.MenuItem> targetItems = target.getChildren(); for (MenuBar.MenuItem sourceItem:source.getChildren()) { if (sourceItem.isSeparator()) { target.addSeparator(); } else { MenuBar.MenuItem targetItem = findItem(sourceItem.getText(),targetItems); if (targetItem == null) { targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand()); fixMenuItem(targetItem,sourceItem); added.add(targetItem); } merge(targetItem,sourceItem,added); } } } } private static void fixMenuItem(MenuBar.MenuItem targetItem, MenuBar.MenuItem sourceItem)
private void addItems(ItemAddBehaviour<com.vaadin.contextmenu.MenuItem> behaviour, MenuBar.MenuItem child) { com.vaadin.contextmenu.MenuItem contextMenuItem = behaviour.addItem(); contextMenuItem.setEnabled(child.isEnabled()); if (child.isSeparator()) { contextMenuItem.addSeparator(); } if (child.getCommand() != null) { contextMenuItem.setCommand((Command) contextMenuItemClickEvent -> child.getCommand().menuSelected(child)); } if (child.hasChildren()) { for (MenuBar.MenuItem eachChild : child.getChildren()) { addItems(() -> contextMenuItem.addItem( eachChild.getText(), eachChild.getIcon(), (Command) selectedItem -> { if (eachChild.getCommand() != null) { eachChild.getCommand().menuSelected(eachChild); } }), eachChild); } } }
private void addItems(ItemAddBehaviour<ContextMenuItem> behaviour, MenuBar.MenuItem child) { ContextMenuItem contextMenuItem = behaviour.addItem(); contextMenuItem.setEnabled(child.isEnabled()); contextMenuItem.setSeparatorVisible(child.isSeparator()); if (child.getCommand() != null) { contextMenuItem.addItemClickListener(contextMenuItemClickEvent -> child.getCommand().menuSelected(child)); } if (child.hasChildren()) { for (MenuBar.MenuItem eachChild : child.getChildren()) { addItems(() -> contextMenuItem.addItem(eachChild.getText(), eachChild.getIcon()), eachChild); } } }
def.isVisible(), boolean.class, context); DesignAttributeHandler.writeAttribute("separator", attr, item.isSeparator(), def.isSeparator(), boolean.class, context); DesignAttributeHandler.writeAttribute("checkable", attr, item.isCheckable(), def.isCheckable(), boolean.class, context);
/** * Checks if the item has children (if it is a sub-menu). * * @return True if this item has children */ public boolean hasChildren() { return !isSeparator() && itsChildren != null; }