Package com.vaadin.ui.MenuBar

Examples of com.vaadin.ui.MenuBar.MenuItem


     */
    protected MenuItem createCategory(String category, String parentCategory) {
        if (hasCategory(category)) {
            return categoryToMenuItem.get(category);
        }
        MenuItem item;
        if (parentCategory == null) {
            item = mainMenu.addItem(category, null);
        } else {
            item = getCategoryMenuItem(parentCategory).addItem(category, null);
        }
View Full Code Here


        if (!hasCategory(categoryId)) {
            throw new IllegalArgumentException("Category '" + categoryId
                    + "' does not exist");
        }

        MenuItem item = getCategoryMenuItem(categoryId);
        Object[] children = item.getChildren().toArray();
        for (Object child : children) {
            if (menuItemToCategory.containsKey(child)) {
                removeCategory(menuItemToCategory.get(child));
            }
        }
        // Detach from parent
        item.getParent().removeChild(item);
        // Clean mappings
        categoryToMenuItem.remove(categoryId);
        menuItemToCategory.remove(item);

    }
View Full Code Here

        }
    }

    protected String getText(MenuItem item) {
        String path = "";
        MenuItem parent = item.getParent();
        while (!isCategory(parent)) {
            path = parent.getText() + "/" + path;
            parent = parent.getParent();
        }

        return path + "/" + item.getText();
    }
View Full Code Here

            String category,
            LinkedHashMap<String, TYPE> options,
            com.vaadin.tests.components.ComponentTestCase.Command<T, TYPE> command,
            Object data) {

        MenuItem categoryItem = getCategoryMenuItem(category);
        MenuItem mainItem = categoryItem.addItem(caption, null);

        for (String option : options.keySet()) {
            MenuBar.Command cmd = menuClickCommand(command,
                    options.get(option), data);
            mainItem.addItem(option, cmd);
        }
    }
View Full Code Here

            LinkedHashMap<String, TYPE> options,
            String initialValue,
            com.vaadin.tests.components.ComponentTestCase.Command<T, TYPE> command,
            Object data) {

        MenuItem parentItem = getCategoryMenuItem(category);
        MenuItem mainItem = parentItem.addItem(caption, null);

        parentOfSelectableMenuItem.add(mainItem);
        for (String option : options.keySet()) {
            MenuBar.Command cmd = singleSelectMenuCommand(command,
                    options.get(option), data);
            MenuItem item = mainItem.addItem(option, cmd);
            if (option.equals(initialValue)) {
                cmd.menuSelected(item);
            }
        }
    }
View Full Code Here

        // Populate the menu bar
        for (int i = 0; i < 6; i++) {
            itemList.add(menuBar.addItem(new String("Menu " + i), null, null));
        }

        MenuItem first = itemList.get(0);

        for (int i = 0; i < 5; i++) {
            first.addItem(new String("Submenu item" + i), null, new Command() {

                @Override
                public void menuSelected(MenuItem selected) {
                    main.showNotification("Action " + selected.getText());
                }
            });
        }

        MenuItem firstSubItem1 = first.getChildren().get(1);

        for (int i = 0; i < 3; i++) {
            firstSubItem1.addItem(new String("Subsubmenu item" + i), null,
                    new Command() {

                        @Override
                        public void menuSelected(MenuItem selected) {
                            main.showNotification("Action "
                                    + selected.getText());
                        }
                    });
        }
        MenuItem firstSubItem2 = first.getChildren().get(3);

        for (int i = 0; i < 3; i++) {
            firstSubItem2.addItem(new String("Subsubmenu item" + i), null,
                    new Command() {

                        @Override
                        public void menuSelected(MenuItem selected) {
                            main.showNotification("Action "
                                    + selected.getText());
                        }
                    });
        }

        MenuItem second = menuBar.getItems().get(1);

        for (int i = 0; i < 5; i++) {
            second.addItem(new String("Second submenu item" + i), null,
                    new Command() {

                        @Override
                        public void menuSelected(MenuItem selected) {
                            main.showNotification("Action "
                                    + selected.getText());
                        }
                    });
        }

        MenuItem third = menuBar.getItems().get(2);
        third.setIcon(new ThemeResource("icons/16/document.png"));

        for (int i = 2; i <= 3; i++) {
            (menuBar.getItems().get(i)).setCommand(new Command() {

                @Override
                public void menuSelected(MenuItem selectedItem) {
                    main.showNotification("Action " + selectedItem.getText());
                }
            });
        }

        final MenuItem fourth = menuBar.getItems().get(3);
        fourth.setText("Add new item");

        fourth.setCommand(new Command() {
            @Override
            public void menuSelected(MenuItem selected) {
                menuBar.addItem("Newborn", null, null);
            }
        });

        final MenuItem fifth = menuBar.getItems().get(4);
        for (int i = 0; i < 5; i++) {
            fifth.addItem("Another subitem " + i, null);
        }

        final MenuItem last = menuBar.getItems().get(menuBar.getSize() - 1);
        last.setText("Remove me!");

        // A command for removing the selected menuitem
        Command removeCommand = new Command() {

            @Override
            public void menuSelected(MenuItem selected) {
                MenuItem parent = selected.getParent();
                if (parent != null) {
                    parent.removeChild(selected);
                } else {
                    menuBar.removeItem(selected);
                }
            }
        };
View Full Code Here

    }

    private MenuBar getMenubar() {
        MenuBar menubar = new MenuBar();
        menubar.setAutoOpen(true);
        MenuItem item = menubar.addItem("auto-open", null);
        item.addItem("sub-item 1", new MenuBar.Command() {

            @Override
            public void menuSelected(MenuItem selectedItem) {
                Notification notification = new Notification("Test",
                        Type.HUMANIZED_MESSAGE);
View Full Code Here

    }

    private Component buildMenu() {
        MenuBar menu = new MenuBar();
        MenuItem item = menu.addItem("Menu", null);

        item.addItem("Item 1", null).setDescription("TOOLTIP 1");
        item.addItem("Item 2", null).setDescription("TOOLTIP 2");
        item.addItem("Item 3", null).setDescription("TOOLTIP 3");
        item.addItem("Item 4", null).setDescription("TOOLTIP 4");

        return menu;
    }
View Full Code Here

            if (subMenuSeparatorDensity != null && i > 0
                    && i % subMenuSeparatorDensity == 0) {
                parent.addSeparator();
            }

            MenuItem subMenuItem = parent.addItem("Sub menu " + parent.getId()
                    + "/" + (i + 1), menuCommand);

            if (disabledDensity != null && i % disabledDensity == 0) {
                subMenuItem.setEnabled(false);
            }
            if (invisibleDensity != null && i % invisibleDensity == 0) {
                subMenuItem.setVisible(false);
            }

            if (i % subMenuDensity == 0 && level < subLevels) {
                subMenuItem.setCommand(null);
                createSubItems(subMenuItem, level + 1);
            }

            if (!subMenuItem.hasChildren() && level > 0
                    && checkableDensity != null && i % checkableDensity == 0) {
                subMenuItem.setCheckable(true);
            }
        }

    }
View Full Code Here

    protected void createRootItems(MenuBar c) {
        // Remove all existing items
        c.removeItems();
        for (int i = 0; i < rootItems; i++) {
            MenuItem rootItem = c.addItem("Root menu " + (i + 1), null);
            if (disabledDensity != null && i % disabledDensity == 0) {
                rootItem.setEnabled(false);
            }
            if (invisibleDensity != null && i % invisibleDensity == 0) {
                rootItem.setVisible(false);
            }
        }
        createSubItems(c);

    }
View Full Code Here

TOP

Related Classes of com.vaadin.ui.MenuBar.MenuItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.