@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); for (MenuItem item : getItems()) { design.appendChild(createMenuElement(item, designContext)); } // in many cases there seems to be an empty more menu item if (getMoreMenuItem() != null && !getMoreMenuItem().getText().isEmpty()) { Element moreMenu = createMenuElement(getMoreMenuItem(), designContext); moreMenu.attr("more", true); design.appendChild(moreMenu); } if (!htmlContentAllowed) { design.attr(DESIGN_ATTR_PLAIN_TEXT, true); } }
public void addMenuItem(MenuItem item, int index) { if (item.getText() == null) { throw new IllegalArgumentException("MenuItem caption cannot be null"); } menuItems.add(index, item); markAsDirty(); }
public void addMenuItem(MenuItem item) { if (item.getText() == null) { throw new IllegalArgumentException("MenuItem caption cannot be null"); } menuItems.add(item); markAsDirty(); }
@Test @SuppressWarnings("ConstantConditions") public void localeChange() { // given userNavigationMenu = newMenu(); userNavigationMenu.build(); // when currentLocale.setLocale(Locale.GERMANY); // then List<String> captions = menuCaptions(null); assertThat(captions).containsOnly("Öffentlich", "Privat"); String txt = translate.from(LabelKey.Public); MenuItem pblic = childWithText(txt, null); MenuItem publicHome = childWithText("Öffentliche Startseite", pblic); assertThat(publicHome.getText()).isEqualTo("Öffentliche Startseite"); }
@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); }
private static MenuBar.MenuItem findItem(String name, List<MenuBar.MenuItem> items) { if (items != null) { for (MenuBar.MenuItem item: items) { if (item.getText().equals(name)) { return item; } } } return null; }
private MenuItem childWithText(String text, MenuItem parentItem) { List<MenuItem> items = childrenOf(parentItem); if (items == null) { return null; } for (MenuItem item : items) { if (item.getText() .equals(text)) { return item; } } return null; }
private static MenuBar.MenuItem findItem(String name, List<MenuBar.MenuItem> items) { if (items != null) { for (MenuBar.MenuItem item: items) { if (item.getText().equals(name)) { return item; } } } return null; }
@Override public String getCaption() { return delegateItem.getText(); }
private List<String> menuCaptions(MenuItem parentItem) { List<MenuItem> items = childrenOf(parentItem); List<String> captions = new ArrayList<>(); if (items != null) { for (MenuItem item : items) { captions.add(item.getText()); } } return captions; }
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 void addItems(MenuBar menuBar) { for (MenuBar.MenuItem eachItem : menuBar.getItems()) { addItems(() -> this.addItem(eachItem.getText(), eachItem.getIcon()), eachItem); } }
@Override public void addChildItem(MenuItem menuItem, int index) { MenuBar.MenuItem childItem = ((MenuItemImpl) menuItem).getDelegateItem(); if (childItem.getText() == null) { throw new IllegalArgumentException("Caption cannot be null"); } MenuBar.MenuItem delegateItem = this.getDelegateItem(); childItem.setParent(delegateItem); delegateItem.getChildren().add(index, childItem); menu.registerMenuItem(menuItem); menu.getComponent().markAsDirty(); }
@Override public void addChildItem(MenuItem menuItem) { MenuBar.MenuItem childItem = ((MenuItemImpl) menuItem).getDelegateItem(); if (childItem.getText() == null) { throw new IllegalArgumentException("Caption cannot be null"); } MenuBar.MenuItem delegateItem = this.getDelegateItem(); childItem.setParent(delegateItem); delegateItem.getChildren().add(childItem); menu.registerMenuItem(menuItem); menu.getComponent().markAsDirty(); }
target.addAttribute("separator", true); } else { target.addAttribute("text", item.getText());
item.getStyleName(), def.getStyleName(), String.class, context); menuElement.append(item.getText());
/** Paint (serialize) the component for the client. */ @Override public void paintContent(PaintTarget target) throws PaintException { target.addAttribute(MenuBarConstants.OPEN_ROOT_MENU_ON_HOWER, openRootOnHover); if (isHtmlContentAllowed()) { target.addAttribute(MenuBarConstants.HTML_CONTENT_ALLOWED, true); } target.startTag("options"); if (getWidth() > -1) { target.startTag("moreItem"); target.addAttribute("text", moreItem.getText()); if (moreItem.getIcon() != null) { target.addAttribute("icon", moreItem.getIcon()); } target.endTag("moreItem"); } target.endTag("options"); target.startTag("items"); // This generates the tree from the contents of the menu for (MenuItem item : menuItems) { paintItem(target, item); } target.endTag("items"); }