Example usage for com.vaadin.ui MenuBar MenuBar

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

Introduction

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

Prototype

public MenuBar() 

Source Link

Document

Constructs an empty, horizontal menu.

Usage

From source file:org.balisunrise.vaadin.components.header.ModuleMenu.java

private void init() {
    setHeight("100%");
    setWidthUndefined();/*from  ww  w .j  a  v  a2 s.c  o m*/

    menuBar = new MenuBar();
    menuBar.setStyleName("b-module-menu");

    setCompositionRoot(menuBar);

    MenuBar.MenuItem item;
    item = menuBar.addItem("Menu 1", new ItemCommand());
    item.setStyleName("b-module-menu-item");
    item.setDescription("1 Item do menu");

    MenuBar.MenuItem subMenu;
    subMenu = menuBar.addItem("Sub Menus 1", null);
    subMenu.setStyleName("b-module-menu-item");

    item = subMenu.addItem("Menu 2", new ItemCommand());
    item.setStyleName("b-module-menu-item");
    item.setDescription("2 Item do menu");

    item = subMenu.addItem("Menu 3", new ItemCommand());
    item.setStyleName("b-module-menu-item");
    item.setDescription("3 Item do menu");

    subMenu = menuBar.addItem("Sub Menus 2", null);
    subMenu.setStyleName("b-module-menu-item");

    MenuBar.MenuItem subMenu2;
    subMenu2 = subMenu.addItem("Sub Sub Menu 1", null);
    subMenu2.setStyleName("b-module-menu-item");

    item = subMenu2.addItem("Menu 4", new ItemCommand());
    item.setStyleName("b-module-menu-item");
    item.setDescription("4 Item do menu");

    item = subMenu2.addItem("Menu 5", new ItemCommand());
    item.setStyleName("b-module-menu-item");
    item.setDescription("5 Item do menu");

    subMenu2 = subMenu.addItem("Sub Sub Menu 2", null);
    subMenu2.setStyleName("b-module-menu-item");

    item = subMenu2.addItem("Menu 6", new ItemCommand());
    item.setStyleName("b-module-menu-item");
    item.setDescription("6 Item do menu");

    item = subMenu2.addItem("Menu 7", new ItemCommand());
    item.setStyleName("b-module-menu-item");
    item.setDescription("7 Item do menu");
}

From source file:org.bubblecloud.ilves.site.view.valo.DefaultValoView.java

License:Apache License

private CssLayout buildMenu() {

    final HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setWidth("100%");
    topLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    topLayout.addStyleName("valo-menu-title");
    menu.addComponent(topLayout);//from   www . j ava  2  s  . c o  m

    final Button showMenu = new Button("Menu", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.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>" + Site.getCurrent().localize(getViewVersion().getTitle()) + "</h3>",
            ContentMode.HTML);
    title.setSizeUndefined();
    topLayout.addComponent(title);
    topLayout.setExpandRatio(title, 1);

    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");

    final String user = Site.getCurrent().getSecurityProvider().getUser();
    final String userMenuCaption;
    final Resource userMenuIcon;
    if (user == null) {
        userMenuCaption = Site.getCurrent().localize("page-link-login");
        userMenuIcon = new ThemeResource("ilves_logo.png");
    } else {
        final URL gravatarUrl = GravatarUtil.getGravatarUrl(user, 64);
        userMenuIcon = new ExternalResource(gravatarUrl);
        userMenuCaption = ((SecurityProviderSessionImpl) Site.getCurrent().getSecurityProvider())
                .getUserFromSession().getFirstName();
    }

    final MenuBar.MenuItem settingsItem = settings.addItem(userMenuCaption, userMenuIcon, null);
    if (user != null) {
        settingsItem.addItem(Site.getCurrent().localize("page-link-account"), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                UI.getCurrent().getNavigator().navigateTo("account");
            }
        });
        settingsItem.addSeparator();
        settingsItem.addItem(Site.getCurrent().localize("button-logout"), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                LoginService.logout(Site.getCurrent().getSiteContext());
                final Company company = Site.getCurrent().getSiteContext().getObject(Company.class);
                getUI().getPage().setLocation(company.getUrl());
                getSession().getSession().invalidate();
                getSession().close();
            }
        });
    } else {
        settingsItem.addItem(Site.getCurrent().localize("page-link-login"), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                UI.getCurrent().getNavigator().navigateTo("login");
            }
        });
    }
    menu.addComponent(settings);

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

    final Site site = Site.getCurrent();
    final NavigationVersion navigationVersion = site.getCurrentNavigationVersion();

    for (final String pageName : navigationVersion.getRootPages()) {
        final ViewVersion pageVersion = site.getCurrentViewVersion(pageName);
        if (pageVersion == null) {
            throw new SiteException("Unknown page: " + pageName);
        }
        if (pageVersion.getViewerRoles().length > 0) {
            boolean roleMatch = false;
            for (final String role : pageVersion.getViewerRoles()) {
                if (site.getSecurityProvider().getRoles().contains(role)) {
                    roleMatch = true;
                    break;
                }
            }
            if (!roleMatch) {
                continue;
            }
        }

        if (navigationVersion.hasChildPages(pageName)) {

            final String localizedPageName = pageVersion.isDynamic() ? pageName
                    : site.localize("page-link-" + pageName);

            final Label label = new Label(localizedPageName, ContentMode.HTML);
            label.setPrimaryStyleName("valo-menu-subtitle");
            label.addStyleName("h4");
            label.setSizeUndefined();
            menuItemsLayout.addComponent(label);

            final List<String> childPages = navigationVersion.getChildPages(pageName);
            for (final String childPage : childPages) {
                addMenuLink(navigationVersion, childPage);
            }

            label.setValue(
                    label.getValue() + " <span class=\"valo-menu-badge\">" + childPages.size() + "</span>");
        } else {
            addMenuLink(navigationVersion, pageName);
        }
    }

    return menu;
}

From source file:org.characterbuilder.navigation.ChargenMenu.java

public ChargenMenu() {
    this.leftMenu = new MenuBar();
    this.rightMenu = new MenuBar();

    MenuBar.MenuItem trudvangMenu = leftMenu.addItem("Trudvang", null);

    MenuBar.MenuItem mutantMenu = leftMenu.addItem("Mutant: UA", null);

    rightMenu.addItem("Logout", new LogoutCommand());

    leftMenu.setWidth("100%");
    setExpandRatio(leftMenu, 1);/*from  w  w w. ja v a  2  s  .c o  m*/
    setExpandRatio(rightMenu, 0);
    setSizeFull();

    addComponent(leftMenu);
    addComponent(rightMenu);
}

From source file:org.eclipse.hawkbit.ui.menu.DashboardMenu.java

License:Open Source License

private Component buildUserMenu(final UiProperties uiProperties) {
    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");
    settings.setHtmlContentAllowed(true);

    final MenuItem settingsItem = settings.addItem("", getImage(uiProperties.isGravatar()), null);

    final String formattedTenant = UserDetailsFormatter.formatCurrentTenant();
    if (!StringUtils.isEmpty(formattedTenant)) {
        settingsItem.setText(formattedTenant);
        UserDetailsFormatter.getCurrentTenant()
                .ifPresent(tenant -> settingsItem.setDescription(i18n.getMessage("menu.user.description",
                        tenant, UserDetailsFormatter.getCurrentUser().getUsername())));
    } else {//from www. j a va  2 s .  co m
        settingsItem.setText("...");
    }

    settingsItem.setStyleName("user-menuitem");

    final String logoutUrl = generateLogoutUrl();

    settingsItem.addItem(i18n.getMessage("label.sign.out"),
            selectedItem -> Page.getCurrent().setLocation(logoutUrl));
    return settings;
}

From source file:org.icrisat.gdms.ui.GDMSMain.java

HorizontalLayout getTopMenu() {
    HorizontalLayout horizontalLayout = new HorizontalLayout();

    MenuBar menubar = new MenuBar();

    MenuBar.Command menuCommand = new MenuBar.Command() {
        private static final long serialVersionUID = 1L;

        public void menuSelected(MenuItem selectedItem) {

            if (selectedItem.getText().equals("Login")) {
                openLoginWindow();//from  w w  w  .j a va2  s .c  o m
            } else if (selectedItem.getText().equals("Logout")) {

                _gdmsModel.setLoggedInUser(null);
                _loginMenu.setText("Login");
                setUser(null);
                _lblLoginMessage.setValue("");

                //buildUploadDataWindow.setEnabled(false);
                //buildRetrieveWindow.setEnabled(false);
                //buildDeleteWindow.setEnabled(false);

                if (buildWelcomeScreen == _tabsheet.getSelectedTab()) {
                    _tabsheet.getSelectedTab().setEnabled(true);
                } else {
                    _tabsheet.getSelectedTab().setEnabled(false);
                }

                _tabsheet.getTab(1).setEnabled(false);
                _tabsheet.getTab(2).setEnabled(false);
                _tabsheet.getTab(3).setEnabled(false);

                if (!getMainWindow().getChildWindows().contains(loginWindow)) {
                    getMainWindow().removeWindow(loginWindow);
                    loginWindow = null;
                }

            } else if (selectedItem.getText().equals("Contact")) {
                getMainWindow().showNotification("Functionality for Contact is yet to be added.",
                        Notification.TYPE_HUMANIZED_MESSAGE);
            } else if (selectedItem.getText().equals("Help")) {
                getMainWindow().showNotification("Functionality for Help menu-item is yet to be added.",
                        Notification.TYPE_HUMANIZED_MESSAGE);
            } else {
                _gdmsModel.setMenuItemSelected(null);
                updateAllTabComponents();
            }
        }
    };

    //_homeMenu = menubar.addItem("Home", null);
    _contactMenu = menubar.addItem("Contact", menuCommand);
    final MenuBar.MenuItem helpMenu = menubar.addItem("Help", menuCommand);
    Object user2 = getUser();
    if (null == user2) {
        _loginMenu = menubar.addItem("Login", menuCommand);
    } else {
        _loginMenu = menubar.addItem("Logout", menuCommand);
    }

    if (null != _gdmsModel.getLoggedInUser()) {
        _loginMenu.setEnabled(false);
        uploadLoginDetailsOnMainWindow();
    }

    horizontalLayout.addComponent(menubar);

    return horizontalLayout;
}

From source file:org.ikasan.dashboard.ui.framework.panel.LandingViewPanel.java

License:BSD License

private Component createContentWrapper(final Component content) {
    final CssLayout slot = new CssLayout();
    slot.setWidth("100%");
    slot.addStyleName("dashboard-panel-slot");

    CssLayout card = new CssLayout();
    card.setWidth("100%");
    card.addStyleName(ValoTheme.LAYOUT_CARD);

    HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.addStyleName("dashboard-panel-toolbar");
    toolbar.setWidth("100%");

    Label caption = new Label(content.getCaption());
    caption.addStyleName(ValoTheme.LABEL_H4);
    caption.addStyleName(ValoTheme.LABEL_COLORED);
    caption.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    content.setCaption(null);//from  w w w.  j  a  v  a2 s.c o m

    MenuBar tools = new MenuBar();
    tools.addStyleName(ValoTheme.MENUBAR_BORDERLESS);
    MenuItem max = tools.addItem("", VaadinIcons.EXPAND, new Command() {

        @Override
        public void menuSelected(final MenuItem selectedItem) {
            if (!slot.getStyleName().contains("max")) {
                selectedItem.setIcon(FontAwesome.COMPRESS);
                toggleMaximized(slot, true);
            } else {
                slot.removeStyleName("max");
                selectedItem.setIcon(FontAwesome.EXPAND);
                toggleMaximized(slot, false);
            }
        }
    });
    max.setStyleName("icon-only");
    MenuItem root = tools.addItem("", VaadinIcons.COG, null);
    root.addItem("Configure", new Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            Notification.show("Not implemented in this demo");
        }
    });
    root.addSeparator();
    root.addItem("Close", new Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            Notification.show("Not implemented in this demo");
        }
    });

    toolbar.addComponents(caption, tools);
    toolbar.setExpandRatio(caption, 1);
    toolbar.setComponentAlignment(caption, Alignment.MIDDLE_LEFT);

    card.addComponents(toolbar, content);
    slot.addComponent(card);
    return slot;
}

From source file:org.ikasan.dashboard.ui.monitor.component.MonitorPanel.java

License:BSD License

protected Component createContentWrapper(final Component small, final Component large) {
    final CssLayout slot = new CssLayout();
    slot.setWidth("100%");
    slot.addStyleName("monitor-panel-slot");

    final CssLayout card1 = new CssLayout();
    card1.setWidth("100%");
    card1.addStyleName(ValoTheme.LAYOUT_CARD);

    final CssLayout card2 = new CssLayout();
    card2.setWidth("100%");
    card2.addStyleName(ValoTheme.LAYOUT_CARD);

    final HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.addStyleName("dashboard-panel-toolbar");
    toolbar.setWidth("100%");

    Label caption = new Label(large.getCaption());
    caption.addStyleName(ValoTheme.LABEL_H4);
    caption.addStyleName(ValoTheme.LABEL_COLORED);
    caption.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    large.setCaption(null);// www .  ja v  a  2 s .c o m

    MenuBar tools = new MenuBar();
    tools.addStyleName(ValoTheme.MENUBAR_BORDERLESS);
    MenuItem max = tools.addItem("", VaadinIcons.EXPAND, new Command() {

        @Override
        public void menuSelected(final MenuItem selectedItem) {
            if (!slot.getStyleName().contains("max")) {
                selectedItem.setIcon(FontAwesome.COMPRESS);
                slot.removeAllComponents();
                card2.removeAllComponents();
                card2.addComponents(toolbar, large);
                slot.addComponents(card2);
                toggleMaximized(slot, true);
            } else {
                slot.removeStyleName("max");
                selectedItem.setIcon(FontAwesome.EXPAND);
                toggleMaximized(slot, false);
                card1.removeAllComponents();
                card1.addComponents(toolbar, small);
                slot.removeAllComponents();
                slot.addComponents(card1);
            }
        }
    });
    max.setStyleName("icon-only");
    MenuItem root = tools.addItem("", VaadinIcons.COG, null);
    root.addItem("Configure", new Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            Notification.show("Not implemented in this demo");
        }
    });
    root.addSeparator();
    root.addItem("Close", new Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            Notification.show("Not implemented in this demo");
        }
    });

    toolbar.addComponents(caption, tools);
    toolbar.setExpandRatio(caption, 1);
    toolbar.setComponentAlignment(caption, Alignment.MIDDLE_LEFT);

    card1.addComponents(toolbar, small);
    //        card2.addComponents(toolbar, large);
    slot.addComponent(card1);
    return slot;
}

From source file:org.jpos.qi.Header.java

License:Open Source License

@SuppressWarnings("unchecked")
private MenuBar createMenu() {
    menuOptions = new LinkedHashMap<>();
    MenuBar mb = new MenuBar();
    mb.addStyleName(ValoTheme.MENUBAR_SMALL);
    mb.addStyleName(ValoTheme.MENUBAR_BORDERLESS);
    mb.setHtmlContentAllowed(true);/*from www  .  ja v a2  s.c  o  m*/
    Element cfg = app.getXmlConfiguration();
    if (cfg != null) {
        Element menubar = cfg.getChild("menubar");
        if (menubar != null) {
            for (Element e : menubar.getChildren()) {
                addMenubarItem(mb, e);
            }
        }
    }
    userMenuItem = mb.addItem(app.getUser().getNick(), null);
    userMenuItem.setIcon(VaadinIcons.USER);
    userMenuItem.addItem("Profile", selectedItem -> {
        removeSelected();
        app.navigateTo("/profile");
    });
    userMenuItem.addItem("Log Out", selectedItem -> app.logout());
    return mb;
}

From source file:org.jumpmind.metl.ui.common.TopBar.java

License:Open Source License

public TopBar(ViewManager vm, ApplicationContext context) {
    setWidth(100, Unit.PERCENTAGE);/*w  w w . ja va  2 s .  co m*/
    this.context = context;
    this.viewManager = vm;
    this.viewManager.addViewChangeListener(this);

    viewToButtonMapping = new HashMap<String, MenuItem>();

    menuBar = new MenuBar();
    menuBar.setWidth(100, Unit.PERCENTAGE);
    addComponent(menuBar);
    setExpandRatio(menuBar, 1.0f);

    String systemText = getGlobalSetting(GlobalSetting.SYSTEM_TEXT, "").getValue();
    if (isNotBlank(systemText)) {
        Button systemLabel = new Button(systemText, FontAwesome.WARNING);
        systemLabel.setHtmlContentAllowed(true);
        addComponent(systemLabel);
    }

    Button helpButton = new Button("Help", FontAwesome.QUESTION_CIRCLE);
    helpButton.addClickListener(event -> openHelp(event));
    addComponent(helpButton);

    Button settingsButton = new Button(context.getUser().getLoginId(), FontAwesome.GEAR);
    settingsButton.addClickListener((event) -> {
    });
    addComponent(settingsButton);

    Button logoutButton = new Button("Logout", FontAwesome.SIGN_OUT);
    logoutButton.addClickListener(event -> logout());
    addComponent(logoutButton);

    Map<Category, List<TopBarLink>> menuItemsByCategory = viewManager.getMenuItemsByCategory();
    Set<Category> categories = menuItemsByCategory.keySet();
    for (Category category : categories) {
        if (!context.getUser().hasPrivilege(category.name())) {
            log.info("'{}' does not have access to the {} menu tab", context.getUser(), category.name());
            continue;
        }
        List<TopBarLink> links = menuItemsByCategory.get(category);
        boolean needDefaultView = viewManager.getDefaultView() == null && links.size() > 0;
        MenuItem categoryItem = null;
        if (links.size() > 1) {
            categoryItem = menuBar.addItem(category.name(), null);
            categoryItems.add(categoryItem);
        }

        if (needDefaultView) {
            viewManager.setDefaultView(links.get(0).id());
        }

        for (final TopBarLink menuLink : links) {
            Command command = new Command() {

                private static final long serialVersionUID = 1L;

                @Override
                public void menuSelected(MenuItem selectedItem) {
                    uncheckAll();
                    selectedItem.setChecked(true);
                    viewManager.navigateTo(menuLink.id());
                }
            };
            MenuItem menuItem = null;
            if (categoryItem == null) {
                menuItem = menuBar.addItem(menuLink.name(), command);
            } else {
                menuItem = categoryItem.addItem(menuLink.name(), command);
            }
            menuItem.setCheckable(true);
            viewToButtonMapping.put(menuLink.id(), menuItem);
        }
    }
    viewManager.navigateTo(viewManager.getDefaultView());
}

From source file:org.jumpmind.metl.ui.views.AdminView.java

License:Open Source License

@PostConstruct
protected void init() {
    setSizeFull();//from   w ww.  j a  va  2  s .c o m

    tabbedPanel = new TabbedPanel();

    HorizontalSplitPanel leftSplit = new HorizontalSplitPanel();
    leftSplit.setSizeFull();
    leftSplit.setSplitPosition(AppConstants.DEFAULT_LEFT_SPLIT, Unit.PIXELS);

    VerticalLayout container = new VerticalLayout();
    container.setSizeFull();
    container.addComponent(tabbedPanel);
    leftSplit.setSecondComponent(container);

    table = new TreeTable();
    table.addStyleName(ValoTheme.TREETABLE_NO_HORIZONTAL_LINES);
    table.addStyleName(ValoTheme.TREETABLE_NO_STRIPES);
    table.addStyleName(ValoTheme.TREETABLE_NO_VERTICAL_LINES);
    table.addStyleName(ValoTheme.TREETABLE_BORDERLESS);
    table.setColumnHeaderMode(ColumnHeaderMode.HIDDEN);
    table.setSizeFull();
    table.setCacheRate(100);
    table.setPageLength(100);
    table.setImmediate(true);
    table.setSelectable(true);
    table.addItemClickListener(this);
    table.addStyleName("noselect");
    table.addContainerProperty("id", String.class, null);
    table.setVisibleColumns(new Object[] { "id" });
    table.setColumnExpandRatio("id", 1);
    addItem("Users", Icons.USER);
    addItem("Groups", Icons.GROUP);
    addItem("REST", Icons.REST);
    addItem("General Settings", Icons.SETTINGS);
    addItem("Mail Server", Icons.EMAIL);
    addItem("Notifications", Icons.NOTIFICATION);
    addItem("Logging", Icons.LOGGING);
    addItem("About", FontAwesome.QUESTION);

    VerticalLayout navigator = new VerticalLayout();
    navigator.addStyleName(ValoTheme.MENU_ROOT);
    navigator.setSizeFull();
    leftSplit.setFirstComponent(navigator);

    MenuBar leftMenuBar = new MenuBar();
    leftMenuBar.addStyleName(ValoTheme.MENUBAR_BORDERLESS);
    leftMenuBar.setWidth(100, Unit.PERCENTAGE);
    navigator.addComponent(leftMenuBar);

    navigator.addComponent(table);
    navigator.setExpandRatio(table, 1);

    addComponent(leftSplit);

}