Example usage for com.vaadin.ui MenuBar addItem

List of usage examples for com.vaadin.ui MenuBar addItem

Introduction

In this page you can find the example usage for com.vaadin.ui MenuBar addItem.

Prototype

public MenuBar.MenuItem addItem(String caption, Resource icon, MenuBar.Command command) 

Source Link

Document

Add a new item to the menu bar.

Usage

From source file:by.bigvova.MainUI.java

License:Apache License

private Component buildUserMenu() {
    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");
    final UserTo userTo = controller.getUserTo();
    settingsItem = settings.addItem("", resource, null);
    updateUserMenu(null);/*from   w w w  . java 2s .  co  m*/
    settingsItem.addItem("Edit Profile", new MenuBar.Command() {
        @Override
        public void menuSelected(final MenuBar.MenuItem selectedItem) {
            ProfilePreferencesWindow.open(userTo, resource, controller, pathToProfileImage);
        }
    });
    settingsItem.addSeparator();
    settingsItem.addItem("Sign Out", new MenuBar.Command() {
        @Override
        public void menuSelected(final MenuBar.MenuItem selectedItem) {
            vaadinSecurity.logout();
        }
    });
    return settings;
}

From source file:com.blogspot.markogronroos.MainUI.java

License:GNU General Public License

@Override
protected void init(VaadinRequest request) {

    final VerticalLayout main = new VerticalLayout();
    main.setMargin(true);//from   ww  w .j  a  va 2s. co m
    setContent(main);

    //Window main = new Window("Test Application");

    // Create a menu bar
    final MenuBar menubar = new MenuBar();
    main.addComponent(menubar);

    // A feedback component
    final Label selection = new Label("-");
    main.addComponent(selection);

    MenuBar.MenuItem menuitem1 = menubar.addItem("JPA Examples", null, null);

    MenuBar.MenuItem menuitem2 = menuitem1.addItem("Other Example", null, null);

    MenuBar.Command mycommand = new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            selection.setValue("Ordered a " + selectedItem.getText() + " from menu.");
            String selectedText = selectedItem.getText();
            if (selectedText.contains("1.1"))
                jpaContTable(main);
            else if (selectedText.contains("1.2"))
                jpaContTable2(main);
            else if (selectedText.contains("1.3"))
                jpaContForm1(main);
            else if (selectedText.contains("1.4"))
                pureJPAExample(main);
            //selectedItem.
        }
    };

    menuitem1.addItem("1.1 demo JPAContainer Table component", null, mycommand);
    menuitem1.addItem("1.2 demo JPAContainer Table component, explicit EntityManager", null, mycommand);
    menuitem1.addItem("1.3 demo JPAContainer Form", null, mycommand);

    menuitem1.addItem("1.4 demo JPA batch", null, mycommand);
    //menuitem1.addItem(menuitem2);

    // Define a common menu command for all the menu items.

    //  initEx2(request);
}

From source file:com.cavisson.gui.dashboard.components.controls.Panels.java

License:Apache License

public Panels() {
    setMargin(true);/*from   w w w  .  ja v a2  s . c o m*/

    Label h1 = new Label("Panels & Layout panels");
    h1.addStyleName("h1");
    addComponent(h1);

    HorizontalLayout row = new HorizontalLayout();
    row.addStyleName("wrapping");
    row.setSpacing(true);
    addComponent(row);
    TestIcon testIcon = new TestIcon(60);

    Panel panel = new Panel("Normal");
    panel.setIcon(testIcon.get());
    panel.setContent(panelContent());
    row.addComponent(panel);

    panel = new Panel("Sized");
    panel.setIcon(testIcon.get());
    panel.setWidth("10em");
    panel.setHeight("250px");
    panel.setContent(panelContent());
    row.addComponent(panel);

    panel = new Panel("Custom Caption");
    panel.setIcon(testIcon.get());
    panel.addStyleName("color1");
    panel.setContent(panelContent());
    row.addComponent(panel);

    panel = new Panel("Custom Caption");
    panel.setIcon(testIcon.get());
    panel.addStyleName("color2");
    panel.setContent(panelContent());
    row.addComponent(panel);

    panel = new Panel("Custom Caption");
    panel.setIcon(testIcon.get());
    panel.addStyleName("color3");
    panel.setContent(panelContent());
    row.addComponent(panel);

    panel = new Panel("Borderless style");
    panel.setIcon(testIcon.get());
    panel.addStyleName("borderless");
    panel.setContent(panelContent());
    row.addComponent(panel);

    panel = new Panel("Borderless + scroll divider");
    panel.setIcon(testIcon.get());
    panel.addStyleName("borderless");
    panel.addStyleName("scroll-divider");
    panel.setContent(panelContentScroll());
    panel.setHeight("17em");
    row.addComponent(panel);

    panel = new Panel("Well style");
    panel.setIcon(testIcon.get());
    panel.addStyleName("well");
    panel.setContent(panelContent());
    row.addComponent(panel);

    CssLayout layout = new CssLayout();
    layout.setIcon(testIcon.get());
    layout.setCaption("Panel style layout");
    layout.addStyleName("card");
    layout.addComponent(panelContent());
    row.addComponent(layout);

    layout = new CssLayout();
    layout.addStyleName("card");
    row.addComponent(layout);
    HorizontalLayout panelCaption = new HorizontalLayout();
    panelCaption.addStyleName("v-panel-caption");
    panelCaption.setWidth("100%");
    // panelCaption.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    Label label = new Label("Panel style layout");
    panelCaption.addComponent(label);
    panelCaption.setExpandRatio(label, 1);

    Button action = new Button();
    action.setIcon(FontAwesome.PENCIL);
    action.addStyleName("borderless-colored");
    action.addStyleName("small");
    action.addStyleName("icon-only");
    panelCaption.addComponent(action);
    MenuBar dropdown = new MenuBar();
    dropdown.addStyleName("borderless");
    dropdown.addStyleName("small");
    MenuItem addItem = dropdown.addItem("", FontAwesome.CHEVRON_DOWN, null);
    addItem.setStyleName("icon-only");
    addItem.addItem("Settings", null);
    addItem.addItem("Preferences", null);
    addItem.addSeparator();
    addItem.addItem("Sign Out", null);
    panelCaption.addComponent(dropdown);

    layout.addComponent(panelCaption);
    layout.addComponent(panelContent());
    layout.setWidth("14em");

    layout = new CssLayout();
    layout.setIcon(testIcon.get());
    layout.setCaption("Well style layout");
    layout.addStyleName("well");
    layout.addComponent(panelContent());
    row.addComponent(layout);
}

From source file:com.cavisson.gui.dashboard.components.controls.ValoThemeUI.java

License:Apache License

CssLayout buildMenu() {
    // Add items/*from ww w. j ava2  s.  c o m*/
    menuItems.put("common", "Common UI Elements");
    menuItems.put("labels", "Labels");
    menuItems.put("buttons-and-links", "Buttons & Links");
    menuItems.put("textfields", "Text Fields");
    menuItems.put("datefields", "Date Fields");
    menuItems.put("comboboxes", "Combo Boxes");
    menuItems.put("selects", "Selects");
    menuItems.put("checkboxes", "Check Boxes & Option Groups");
    menuItems.put("sliders", "Sliders & Progress Bars");
    menuItems.put("colorpickers", "Color Pickers");
    menuItems.put("menubars", "Menu Bars");
    menuItems.put("trees", "Trees");
    menuItems.put("tables", "Tables");
    menuItems.put("dragging", "Drag and Drop");
    menuItems.put("panels", "Panels");
    menuItems.put("splitpanels", "Split Panels");
    menuItems.put("tabs", "Tabs");
    menuItems.put("accordions", "Accordions");
    menuItems.put("popupviews", "Popup Views");
    // menuItems.put("calendar", "Calendar");
    menuItems.put("forms", "Forms");

    final HorizontalLayout top = new HorizontalLayout();
    top.setWidth("100%");
    top.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    top.addStyleName("valo-menu-title");
    menu.addComponent(top);
    menu.addComponent(createThemeSelect());

    final Button showMenu = new Button("Menu", new ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            if (menu.getStyleName().contains("valo-menu-visible")) {
                menu.removeStyleName("valo-menu-visible");
            } else {
                menu.addStyleName("valo-menu-visible");
            }
        }
    });
    showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY);
    showMenu.addStyleName(ValoTheme.BUTTON_SMALL);
    showMenu.addStyleName("valo-menu-toggle");
    showMenu.setIcon(FontAwesome.LIST);
    menu.addComponent(showMenu);

    final Label title = new Label("<h3>Vaadin <strong>Valo Theme</strong></h3>", ContentMode.HTML);
    title.setSizeUndefined();
    top.addComponent(title);
    top.setExpandRatio(title, 1);

    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");
    final StringGenerator sg = new StringGenerator();
    final MenuItem settingsItem = settings.addItem(
            sg.nextString(true) + " " + sg.nextString(true) + sg.nextString(false),
            new ThemeResource("../tests-valo/img/profile-pic-300px.jpg"), null);
    settingsItem.addItem("Edit Profile", null);
    settingsItem.addItem("Preferences", null);
    settingsItem.addSeparator();
    settingsItem.addItem("Sign Out", null);
    menu.addComponent(settings);

    menuItemsLayout.setPrimaryStyleName("valo-menuitems");
    menu.addComponent(menuItemsLayout);

    Label label = null;
    int count = -1;
    for (final Entry<String, String> item : menuItems.entrySet()) {
        if (item.getKey().equals("labels")) {
            label = new Label("Components", ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);
        }
        if (item.getKey().equals("panels")) {
            label.setValue(label.getValue() + " <span class=\"valo-menu-badge\">" + count + "</span>");
            count = 0;
            label = new Label("Containers", ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);
        }
        if (item.getKey().equals("forms")) {
            label.setValue(label.getValue() + " <span class=\"valo-menu-badge\">" + count + "</span>");
            count = 0;
            label = new Label("Other", ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);
        }
        final Button b = new Button(item.getValue(), new ClickListener() {
            @Override
            public void buttonClick(final ClickEvent event) {
                navigator.navigateTo(item.getKey());
            }
        });
        if (count == 2) {
            b.setCaption(b.getCaption() + " <span class=\"valo-menu-badge\">123</span>");
        }
        b.setHtmlContentAllowed(true);
        b.setPrimaryStyleName("valo-menu-item");
        b.setIcon(testIcon.get());
        menuItemsLayout.addComponent(b);
        count++;
    }
    label.setValue(label.getValue() + " <span class=\"valo-menu-badge\">" + count + "</span>");

    return menu;
}

From source file:com.github.moscaville.contactsdb.ValoSideBarUI.java

License:Apache License

@Override
protected void init(VaadinRequest vaadinRequest) {
    super.init(vaadinRequest);
    CssLayout header = new CssLayout();

    MenuBar menuBar = new MenuBar();
    header.addComponent(menuBar);/* ww w  .jav a2  s  .  c om*/

    MenuBar.MenuItem settingsItem = menuBar.addItem("", FontAwesome.WRENCH, null);

    sideBar.setHeader(header);
    //categories = categoryController.loadItems(100, 0, new CategoryRecord());
    //representatives = representativeController.loadItems(100, 0, new RepresentativeRecord());
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl.AbstractMenuItemFactoryImpl.java

License:Apache License

/**
 * Inits the application menu bar./*  w  w  w  .  j ava 2s . c  o  m*/
 *
 * @param menuBar
 *            the menu bar
 */
protected final void initApplicationMenuBar(final MenuBar menuBar) {
    menuBar.removeItems();
    menuBar.setWidth("80%");
    menuBar.setStyleName("Header");
    final MenuItem mainViewItem = menuBar.addItem("Application", FontAwesome.SERVER, null);

    mainViewItem.addItem(START_TEXT, FontAwesome.STAR, COMMAND);

    final MenuItem mainItem = mainViewItem.addItem("Main", FontAwesome.STAR, null);

    mainItem.addItem(PAGE_VISIT_HISTORY_TEXT, FontAwesome.AREA_CHART, COMMAND18);

    if (UserContextUtil.allowRoleInSecurityContext(ROLE_ADMIN)
            || UserContextUtil.allowRoleInSecurityContext(ROLE_USER)) {
        mainViewItem.addItem(USERHOME, FontAwesome.USER, COMMAND2);
        createAdminMenu(mainViewItem);
        mainViewItem.addItem("Logout", FontAwesome.SIGN_OUT, COMMAND3);
    } else {
        mainViewItem.addItem("Login", FontAwesome.SIGN_IN, COMMAND4);
        mainViewItem.addItem("Register", FontAwesome.USER_PLUS, COMMAND5);
    }

}

From source file:com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl.ApplicationMenuItemFactoryImpl.java

License:Apache License

@Override
public void addRankingMenu(final MenuBar menuBar) {

    final MenuItem rankingsMenuItem = menuBar.addItem(RANKING_TEXT, FontAwesome.AREA_CHART, null);

    final MenuItem countryMenuItem = rankingsMenuItem.addItem(COUNTRY_RANKING_LINK_TEXT, FontAwesome.FLAG,
            COMMAND7);//from  ww  w .j av  a  2s .c  om

    countryMenuItemFactory.createCountryTopicMenu(countryMenuItem);

    final MenuItem parliamentMenuItem = rankingsMenuItem.addItem(PARLIAMENT_RANKING_LINK_TEXT,
            FontAwesome.INSTITUTION, COMMAND5);

    parliamentMenuItemFactory.createParliamentTopicMenu(parliamentMenuItem);

    final MenuItem politicianMenuItem = rankingsMenuItem.addItem(POLITICIAN_RANKING_LINK_TEXT, FontAwesome.USER,
            COMMAND);

    politicianRankingMenuItemFactory.createPoliticianRankingTopics(politicianMenuItem);

    final MenuItem partynMenuItem = rankingsMenuItem.addItem(PARTY_RANKING_LINK_TEXT, FontAwesome.GROUP,
            COMMAND2);

    partyRankingMenuItemFactory.createPartyRankingTopics(partynMenuItem);

    final MenuItem committeeMenuItem = rankingsMenuItem.addItem(COMMITTEE_RANKING_LINK_TEXT, FontAwesome.GROUP,
            COMMAND3);

    committeeRankingMenuItemFactory.createCommitteeRankingTopics(committeeMenuItem);

    final MenuItem ministryMenuItem = rankingsMenuItem.addItem(MINISTRY_RANKING_LINK_TEXT, FontAwesome.GROUP,
            COMMAND4);

    ministryRankingMenuItemFactory.createMinistryRankingTopics(ministryMenuItem);

}

From source file:com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl.BallotMenuItemFactoryImpl.java

License:Apache License

@Override
public void createBallotMenuBar(final MenuBar menuBar, final String pageId) {
    initApplicationMenuBar(menuBar);//from   w ww.  j  ava  2s.c  o  m

    menuBar.addItem(OVERVIEW_TEXT, FontAwesome.PIE_CHART,
            new PageModeMenuCommand(UserViews.BALLOT_VIEW_NAME, PageMode.OVERVIEW, pageId));
    menuBar.addItem(CHARTS_TEXT, FontAwesome.PIE_CHART,
            new PageModeMenuCommand(UserViews.BALLOT_VIEW_NAME, PageMode.CHARTS, pageId));
    menuBar.addItem(INDICATORS_TEXT, FontAwesome.PIE_CHART,
            new PageModeMenuCommand(UserViews.BALLOT_VIEW_NAME, PageMode.INDICATORS, pageId));

}

From source file:com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl.CommitteeMenuItemFactoryImpl.java

License:Apache License

@Override
public void createCommitteeeMenuBar(final MenuBar menuBar, final String pageId) {
    initApplicationMenuBar(menuBar);// w w w  .  j a v a 2  s .co  m

    applicationMenuItemFactory.addRankingMenu(menuBar);

    committeeRankingMenuItemFactory
            .createCommitteeRankingTopics(menuBar.addItem(COMMITTEE_RANKING_TEXT, FontAwesome.GROUP, null));

    final MenuItem committeeItem = menuBar.addItem("Committee " + pageId, FontAwesome.GROUP, null);

    committeeItem.addItem(OVERVIEW_TEXT, FontAwesome.GROUP,
            new PageModeMenuCommand(UserViews.COMMITTEE_VIEW_NAME, PageMode.OVERVIEW, pageId));
    committeeItem.addItem(CHARTS_TEXT, FontAwesome.GROUP,
            new PageModeMenuCommand(UserViews.COMMITTEE_VIEW_NAME, PageMode.CHARTS, pageId));
    committeeItem.addItem(INDICATORS_TEXT, FontAwesome.GROUP,
            new PageModeMenuCommand(UserViews.COMMITTEE_VIEW_NAME, PageMode.INDICATORS, pageId));

    final MenuItem rolesItem = committeeItem.addItem(ROLES_TEXT, FontAwesome.GROUP, null);

    rolesItem.addItem(CURRENT_MEMBERS_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(
            UserViews.COMMITTEE_VIEW_NAME, CommitteePageMode.CURRENT_MEMBERS.toString(), pageId));

    rolesItem.addItem(MEMBER_HISTORY_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(
            UserViews.COMMITTEE_VIEW_NAME, CommitteePageMode.MEMBERHISTORY.toString(), pageId));

    rolesItem.addItem(ROLE_GHANT_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(UserViews.COMMITTEE_VIEW_NAME,
            CommitteePageMode.ROLEGHANT.toString(), pageId));

    final MenuItem documentItem = committeeItem.addItem(DOCUMENTS_TEXT, FontAwesome.GROUP, null);

    documentItem.addItem(DOCUMENT_ACTIVITY_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(
            UserViews.COMMITTEE_VIEW_NAME, CommitteePageMode.DOCUMENTACTIVITY.toString(), pageId));

    documentItem.addItem(DOCUMENT_HISTORY_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(
            UserViews.COMMITTEE_VIEW_NAME, CommitteePageMode.DOCUMENT_HISTORY.toString(), pageId));

    final MenuItem ballotItem = committeeItem.addItem(BALLOTS_TEXT, FontAwesome.GROUP, null);

    ballotItem.addItem(BALLOT_DECISION_SUMMARY_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(
            UserViews.COMMITTEE_VIEW_NAME, CommitteePageMode.BALLOTDECISIONSUMMARY.toString(), pageId));

    ballotItem.addItem(DECISION_SUMMARY_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(
            UserViews.COMMITTEE_VIEW_NAME, CommitteePageMode.DECISIONSUMMARY.toString(), pageId));

    ballotItem.addItem(DECISION_TYPE_DAILY_SUMMARY_TEXT, FontAwesome.GROUP, new PageModeMenuCommand(
            UserViews.COMMITTEE_VIEW_NAME, CommitteePageMode.DECISIONTYPEDAILYSUMMARY.toString(), pageId));

    committeeItem.addItem(PAGE_VISIT_HISTORY_TEXT, FontAwesome.GROUP,
            new PageModeMenuCommand(UserViews.COMMITTEE_VIEW_NAME, PageMode.PAGEVISITHISTORY, pageId));

}

From source file:com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl.CommitteeRankingMenuItemFactoryImpl.java

License:Apache License

@Override
public void createCommitteeeRankingMenuBar(final MenuBar menuBar) {
    initApplicationMenuBar(menuBar);//from  w w  w.  j  av  a2s.  com

    applicationMenuItemFactory.addRankingMenu(menuBar);

    createCommitteeRankingTopics(menuBar.addItem(COMMITTEE_RANKING_TEXT, null, null));
}