tmpItem.setChecked(!tmpItem.isChecked()); if (null != tmpItem.getCommand()) { tmpItem.getCommand().menuSelected(tmpItem);
target.addAttribute("text", item.getText()); Command command = item.getCommand(); if (command != null) { target.addAttribute("command", true);
@Override public void bind(MenuItem field) { Command command = field.getCommand(); if (command != null && command instanceof CommandExt) { MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource); field.setText(messageSourceAccessor.getMessage(field.getText(), field.getText())); m_maduraSessionManager.register(field); m_menuItems.add(field); } else { throw new RuntimeException("Menu item command is not a CommandExt"); } if (getItemDataSource() == null) { return; } configureMenuItem(field); }
int sizeOfTarget = target.getChildren().size(); if (sizeOfTarget > 0) { targetItem = target.addItemBefore(sourceItem.getText(), null, sourceItem.getCommand(),target.getChildren().get(sizeOfTarget-1)); targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand());
public static void merge(MenuBar target, MenuBar source, List<MenuBar.MenuItem> added) { if (source != null) { List<MenuBar.MenuItem> targetItems = target.getItems(); for (MenuBar.MenuItem sourceItem:source.getItems()) { MenuBar.MenuItem targetItem = findItem(sourceItem.getText(),targetItems); if (targetItem == null) { try { int sizeOfTarget = target.getSize(); if (sizeOfTarget > 0) { targetItem = target.addItemBefore(sourceItem.getText(), null, sourceItem.getCommand(),target.getItems().get(sizeOfTarget-1)); } } catch (Exception e) { } if (targetItem == null) { targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand()); } fixMenuItem(targetItem,sourceItem); added.add(targetItem); } merge(targetItem,sourceItem,added); } } }
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); } } }
@Test @SuppressWarnings("ConstantConditions") public void build_branch_hidden() { //given userNavigationMenu = newMenu(); //re-instate as 'displayable' userSitemap.b11Node() .setPositionIndex(5); // hide the b branch userSitemap.bNode() .setPositionIndex(-1); //when userNavigationMenu.build(); //then MenuItem prvate = childWithText("Private", null); List<String> captions = menuCaptions(prvate); assertThat(captions).containsOnly("Private Home"); assertThat(prvate.getCommand()).isNull(); MenuItem privateHome = childWithText("Private Home", prvate); captions = menuCaptions(privateHome); assertThat(captions).containsOnly(); assertThat(privateHome.getCommand()).isNotNull(); MenuItem viewB = childWithText("ViewB", prvate); assertThat(viewB).isNull(); }
public static void merge(MenuBar target, MenuBar source, List<MenuBar.MenuItem> added) { if (source != null) { List<MenuBar.MenuItem> targetItems = target.getItems(); for (MenuBar.MenuItem sourceItem:source.getItems()) { 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); } } }
@Test @SuppressWarnings("ConstantConditions") public void userSelection() { // given userNavigationMenu = newMenu(); userNavigationMenu.build(); MenuItem pblic = childWithText("Public", null); MenuItem viewA = childWithText("ViewA", pblic); MenuItem viewA1 = childWithText("ViewA1", viewA); MenuItem viewA11 = childWithText("ViewA11", viewA1); MenuItem viewA112 = childWithText("ViewA112", viewA11); // when viewA112.getCommand() .menuSelected(viewA112); // then verify(navigator).navigateTo(userSitemap.getA112Node()); }
public void register(final MenuItem menuItem) { Command command = menuItem.getCommand(); if (command instanceof CommandExt) { CommandExt commandExt = (CommandExt)command; MenuItemPainter painter = commandExt.getPainter(); MaduraPropertyWrapper property = painter.getProperty(); if (property != null) { Hints hints = getHints(); hints.setCommonProperties(menuItem, property,m_messageSource); setPermissions(property, menuItem); } registerWidget(menuItem,painter); } }
public void register(final MenuItem menuItem) { Command command = menuItem.getCommand(); if (command instanceof CommandExt) { CommandExt commandExt = (CommandExt)command; MenuItemPainter painter = commandExt.getPainter(); MaduraPropertyWrapper property = painter.getProperty(); if (property != null) { Hints hints = getHints(); hints.setCommonProperties(menuItem, property,m_messageSource); setPermissions(property, menuItem); } registerWidget(menuItem,painter); } }
private void addItems(MenuBar menuBar) { for (MenuBar.MenuItem eachItem : menuBar.getItems()) { addItems(() -> this.addItem( eachItem.getText(), eachItem.getIcon(), (Command) selectedItem -> { if (eachItem.getCommand() != null) { eachItem.getCommand().menuSelected(eachItem); } }), eachItem); } }
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); } } }
private static void fixMenuItem(MenuBar.MenuItem targetItem, MenuBar.MenuItem sourceItem) { Command command = sourceItem.getCommand(); if (command != null && command instanceof CommandExt) { CommandExt commandExt = (CommandExt)command; MaduraSessionManager maduraSessionManager = commandExt.getMaduraSessionManager(); maduraSessionManager.register(targetItem, commandExt.getPainter()); maduraSessionManager.bind(targetItem, commandExt.getPainter().getProperties()); } }
public void bind (final MenuItem menuItem) { Command command = menuItem.getCommand(); if (command instanceof CommandExt) { CommandExt commandExt = (CommandExt)command; MenuItemPainter painter = commandExt.getPainter(); painter.paint(menuItem); } }
protected void configureMenuItem(MenuItem menuItem) { Command command = menuItem.getCommand(); if (command instanceof CommandExt) { CommandExt commandExt = (CommandExt)command; MenuItemPainter painter = commandExt.getPainter(); if (painter.getProperty() != null) { m_hints.setCommonProperties(menuItem, painter.getProperty(), m_messageSource); } painter.paint(menuItem); } }
private static void fixMenuItem(MenuBar.MenuItem targetItem, MenuBar.MenuItem sourceItem) { Command command = sourceItem.getCommand(); if (command != null && command instanceof CommandExt) { CommandExt commandExt = (CommandExt)command; MaduraSessionManager maduraSessionManager = commandExt.getMaduraSessionManager(); maduraSessionManager.register(targetItem); maduraSessionManager.bind(targetItem); } }
public void bind (final MenuItem menuItem, List<MaduraPropertyWrapper> properties) { Command command = menuItem.getCommand(); if (command instanceof CommandExt) { CommandExt commandExt = (CommandExt)command; MenuItemPainter painter = commandExt.getPainter(); painter.setProperties(properties); painter.paint(menuItem); } }
@Override public void itemClicked(int itemId) { MenuItem clickedItem = itemById.get(itemId); if (clickedItem != null) { if (clickedItem.isCheckable()) clickedItem.setChecked(!clickedItem.isChecked()); if (clickedItem.getCommand() != null) clickedItem.getCommand().menuSelected(clickedItem); } } });