@Override public MenuItem createMenuItem(String id, String caption, @Nullable String icon, @Nullable Consumer<MenuItem> command) { checkNotNullArgument(id); checkItemIdDuplicate(id); MenuItemImpl menuItem = new MenuItemImpl(this, id); Resource iconResource = null; if (icon != null) { iconResource = AppBeans.get(IconResolver.class).getIconResource(icon); } MenuBar.MenuItem delegateItem = component.createMenuItem(caption, iconResource, null); if (command != null) { @SuppressWarnings("UnnecessaryLocalVariable") Consumer<MenuItem> nonnullCommand = command; delegateItem.setCommand(selectedItem -> nonnullCommand.accept(menuItem)); } menuItem.setDelegateItem(delegateItem); menuItem.setCaption(caption); menuItem.setIcon(icon); menuItem.setCommand(command); return menuItem; }
private static MenuBar.MenuItem addItem(ItemAddBehaviour<MenuBar.MenuItem> behaviour, MenuItem eachChildElement, List<VertexRef> targets, OperationContext operationContext, List<Runnable> hooks) { boolean visibility = eachChildElement.isVisible(targets, operationContext); if (visibility) { // only add item if it is actually visible final MenuBar.MenuItem childMenuItem = behaviour.addItem(); final boolean enabled = eachChildElement.isEnabled(targets, operationContext); final boolean checkable = eachChildElement.isCheckable(); childMenuItem.setEnabled(enabled); childMenuItem.setCheckable(checkable); if (checkable) { boolean checked = eachChildElement.isChecked(targets, operationContext); childMenuItem.setChecked(checked); } // Add click behaviour if leaf element if (!eachChildElement.getChildren().isEmpty() && eachChildElement.getCommand() != null) { LOG.warn("The MenuItem {} is not a leaf but defines a command. The command is ignored.", removeLabelProperties(eachChildElement.getLabel())); } else { if (eachChildElement.getCommand() != null) { childMenuItem.setCommand((MenuBar.Command) selectedItem -> { eachChildElement.getCommand().execute(targets, operationContext); hooks.forEach(Runnable::run); }); } } return childMenuItem; } return null; } }
private static MenuBar.MenuItem addItem(ItemAddBehaviour<MenuBar.MenuItem> behaviour, MenuItem eachChildElement, List<VertexRef> targets, OperationContext operationContext, List<Runnable> hooks) { boolean visibility = eachChildElement.isVisible(targets, operationContext); if (visibility) { // only add item if it is actually visible final MenuBar.MenuItem childMenuItem = behaviour.addItem(); final boolean enabled = eachChildElement.isEnabled(targets, operationContext); final boolean checkable = eachChildElement.isCheckable(); childMenuItem.setEnabled(enabled); childMenuItem.setCheckable(checkable); if (checkable) { boolean checked = eachChildElement.isChecked(targets, operationContext); childMenuItem.setChecked(checked); } // Add click behaviour if leaf element if (!eachChildElement.getChildren().isEmpty() && eachChildElement.getCommand() != null) { LOG.warn("The MenuItem {} is not a leaf but defines a command. The command is ignored.", removeLabelProperties(eachChildElement.getLabel())); } else { if (eachChildElement.getCommand() != null) { childMenuItem.setCommand((MenuBar.Command) selectedItem -> { eachChildElement.getCommand().execute(targets, operationContext); hooks.forEach(Runnable::run); }); } } return childMenuItem; } return null; } }
info.setButtonWidget(rightSide); rightSide.addComponent(menu); main.setCommand(new Command() {
private void doSetLeaf(UserSitemapNode sourceNode, MenuItem targetNode) { NavigationCommand command = new NavigationCommand(navigator, sourceNode); targetNode.setCommand(command); }
private void doSetLeaf(UserSitemapNode sourceNode, MenuItem targetNode) { NavigationCommand command = new NavigationCommand(navigator, sourceNode); targetNode.setCommand(command); }
@Override public void setCommand(Consumer<MenuItem> command) { this.command = command; if (command != null) { delegateItem.setCommand(this::menuSelected); } else { delegateItem.setCommand(null); } }
public ActionMenuItemWrapper(MenuItem menuItem, boolean showIconsForPopupMenuActions) { this.menuItem = menuItem; this.showIconsForPopupMenuActions = showIconsForPopupMenuActions; this.menuItem.setCommand((MenuBar.Command) selectedItem -> { if (action != null) { performAction(action); } }); }