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:org.jumpmind.vaadin.ui.sqlexplorer.DefaultButtonBar.java

License:Open Source License

protected void populate(MenuBar menuBar) {
    executeAtCursorButton = menuBar.addItem("", FontAwesome.PLAY, new Command() {

        private static final long serialVersionUID = 1L;

        @Override/*from   w w  w . jav a2  s  .c o m*/
        public void menuSelected(MenuItem selectedItem) {
            queryPanel.execute(false);
        }
    });
    executeAtCursorButton.setDescription("Run sql under cursor (CTRL+ENTER)");

    executeScriptButton = menuBar.addItem("", FontAwesome.FORWARD, new Command() {

        private static final long serialVersionUID = 1L;

        @Override
        public void menuSelected(MenuItem selectedItem) {
            queryPanel.execute(true);
        }
    });
    executeScriptButton.setDescription("Run as script");

    commitButton = menuBar.addItem("", FontAwesome.ARROW_CIRCLE_O_RIGHT, new Command() {

        private static final long serialVersionUID = 1L;

        @Override
        public void menuSelected(MenuItem selectedItem) {
            queryPanel.commit();
        }
    });
    commitButton.setStyleName("green");
    commitButton.setDescription("Commit");
    commitButton.setEnabled(false);

    rollbackButton = menuBar.addItem("", FontAwesome.ARROW_CIRCLE_O_LEFT, new Command() {

        private static final long serialVersionUID = 1L;

        @Override
        public void menuSelected(MenuItem selectedItem) {
            queryPanel.rollback();
        }
    });
    rollbackButton.setStyleName("red");
    rollbackButton.setDescription("Rollback");
    rollbackButton.setEnabled(false);

    historyButton = menuBar.addItem("", FontAwesome.SEARCH, new Command() {

        private static final long serialVersionUID = 1L;

        @Override
        public void menuSelected(MenuItem selectedItem) {
            new SqlHistoryDialog(settingsProvider, queryPanel).showAtSize(0.6);
        }
    });
    historyButton.setDescription("Sql History");
    historyButton.setEnabled(true);

    MenuItem optionsButton = menuBar.addItem("", FontAwesome.TASKS, null);
    optionsButton.setDescription("Options");

    importButton = optionsButton.addItem("DB Import", FontAwesome.DOWNLOAD, new Command() {

        private static final long serialVersionUID = 1L;

        @Override
        public void menuSelected(MenuItem selectedItem) {
            new DbImportDialog(db.getPlatform()).showAtSize(0.6);
        }
    });

    exportButton = optionsButton.addItem("DB Export", FontAwesome.UPLOAD, new Command() {

        private static final long serialVersionUID = 1L;

        @Override
        public void menuSelected(MenuItem selectedItem) {
            new DbExportDialog(db.getPlatform(), queryPanel).showAtSize(0.6);
        }
    });

    fillButton = optionsButton.addItem("DB Fill", FontAwesome.BEER, new Command() {

        private static final long serialVersionUID = 1L;

        @Override
        public void menuSelected(MenuItem selectedItem) {
            new DbFillDialog(db.getPlatform(), queryPanel).showAtSize(0.6);
        }
    });

    for (IDbMenuItem item : additionalMenuItems) {
        optionsButton.addItem(item.getCaption(), item.getIcon(), item.getCommand());
    }
}

From source file:org.ripla.web.internal.menu.ExtendibleMenuFactory.java

License:Open Source License

@Override
public MenuItem createMenu(final MenuBar inMenuBar, final Resource inSubMenuIcon,
        final Map<Integer, IMenuCommand> inMap, final Command inCommand, final Authorization inAuthorization) {
    if (!checkPermissions(menu.getPermission(), inAuthorization)) {
        return null;
    }//from w w w .j a v a2  s. co m

    final MenuItem outItem = inMenuBar.addItem(menu.getLabel(), null, inCommand);
    outItem.setIcon(inSubMenuIcon);

    boolean lFirst = true;
    for (final IExtMenuItem lItem : contributions) {
        if (lItem.isMarker()) {
            continue;
        }

        final IExtendibleMenuContribution lContribution = lItem.getContribution();

        // check the permission the item needs to be displayed
        if (!checkPermissions(lContribution.getPermission(), inAuthorization)) {
            continue;
        }

        final MenuItem lMenuItem = outItem.addItem(lContribution.getLabel(), null, inCommand);
        addCommand(inMap, lMenuItem, createMenuCommand(lContribution.getControllerName()));
        if (lFirst) {
            // clicking the menu has the same effect as clicking the first
            // sub menu item
            addCommand(inMap, outItem, createMenuCommand(lContribution.getControllerName()));
            lFirst = false;
        }

        // process sub menu
        final List<IMenuItem> lSubMenu = lContribution.getSubMenu();
        if (!lSubMenu.isEmpty()) {
            createSubMenu(lSubMenu, lMenuItem, inMap, inCommand, inAuthorization);
        }
    }
    return outItem;
}

From source file:org.ripla.web.internal.menu.MenuFactory.java

License:Open Source License

/**
 * Creates the menu for the use case and adds it to the specified menu bar.
 * //from   w  ww .j  a v a  2  s  .c o m
 * @param inMenuBar
 *            {@link MenuBar}
 * @param inIcon
 *            {@link Resource} the resource for the icon to indicate a
 *            submenu, may be <code>null</code>
 * @param inMap
 *            Map<Integer, IMenuCommand> the map to register the menu's
 *            command
 * @param inCommand
 *            {@link Command} the Vaadin menu bar command
 * @param inAuthorization
 *            {@link Authorization} the authorization object
 * @return MenuItem the Vaadin menu item
 */
public MenuItem createMenu(final MenuBar inMenuBar, final Resource inIcon,
        final Map<Integer, IMenuCommand> inMap, final Command inCommand, final Authorization inAuthorization) {
    if (!checkPermissions(menu.getPermission(), inAuthorization)) {
        return null;
    }

    final MenuItem outItem = inMenuBar.addItem(menu.getLabel(), null, inCommand);
    outItem.setStyleName("ripla-menu-item"); //$NON-NLS-1$
    outItem.setIcon(inIcon);
    addCommand(inMap, outItem, menu);

    final List<IMenuItem> lSubMenu = menu.getSubMenu();
    if (!lSubMenu.isEmpty()) {
        createSubMenu(lSubMenu, outItem, inMap, inCommand, inAuthorization);
    }

    return outItem;
}

From source file:org.vaadin.addons.sitekit.viewlet.anonymous.MenuNavigationViewlet.java

License:Apache License

public void refresh() {
    final MenuBar menuBar = new MenuBar();
    menuBar.setStyleName("menu-bar-navigation");
    menuBar.setSizeFull();/*from   w ww.j ava  2 s. c  om*/
    //menuBar.setHeight(32, Unit.PIXELS);
    setCompositionRoot(menuBar);

    final NavigationVersion navigationVersion = getSite().getCurrentNavigationVersion();

    for (final String pageName : navigationVersion.getRootPages()) {
        processRootPage(navigationVersion, menuBar, pageName);
    }

    if (getSite().getSecurityProvider().getUser() != null) {
        final String localizedPageName = getSite().localize("button-logout");
        final Resource iconResource = getSite().getIcon("page-icon-logout");

        menuBar.addItem(localizedPageName, iconResource, new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                final Company company = getSite().getSiteContext().getObject(Company.class);
                getUI().getPage().setLocation(company.getUrl());
                getSession().close();
            }
        }).setStyleName("navigation-logout");
    }
}

From source file:org.vaadin.addons.sitekit.viewlet.anonymous.MenuNavigationViewlet.java

License:Apache License

private void processRootPage(final NavigationVersion navigationVersion, final MenuBar menuBar,
        final String pageName) {
    final ViewVersion pageVersion = getSite().getCurrentViewVersion(pageName);
    if (pageVersion == null) {
        throw new SiteException("Unknown page: " + pageName);
    }/*from   www  . j  a va2  s  . co m*/
    if (pageVersion.getViewerRoles().length > 0) {
        boolean roleMatch = false;
        for (final String role : pageVersion.getViewerRoles()) {
            if (getSite().getSecurityProvider().getRoles().contains(role)) {
                roleMatch = true;
                break;
            }
        }
        if (!roleMatch) {
            return;
        }
    }

    final String localizedPageName = pageVersion.isDynamic() ? pageName
            : getSite().localize("page-link-" + pageName);
    final Resource iconResource = pageVersion.isDynamic()
            ? navigationVersion.hasChildPages(pageName) ? getSite().getIcon("page-icon-folder")
                    : getSite().getIcon("page-icon-page")
            : getSite().getIcon("page-icon-" + pageName);

    final MenuBar.MenuItem menuItem = menuBar.addItem(localizedPageName, iconResource,
            navigationVersion.hasChildPages(pageName) ? null : new MenuBar.Command() {
                @Override
                public void menuSelected(MenuBar.MenuItem selectedItem) {
                    UI.getCurrent().getNavigator().navigateTo(pageName);
                }
            });
    menuItem.setStyleName("navigation-" + pageName);

    if (navigationVersion.hasChildPages(pageName)) {
        for (final String childPage : navigationVersion.getChildPages(pageName)) {
            processChildPage(navigationVersion, menuItem, childPage);
        }
    }
}

From source file:org.vaadin.spring.samples.sidebar.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);/* w  ww  . j  a v  a  2 s . c  om*/

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

    MenuBar.MenuItem useLargeIconsItem = settingsItem.addItem("Use large icons", new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            sideBar.setLargeIcons(selectedItem.isChecked());
        }
    });
    useLargeIconsItem.setCheckable(true);

    MenuBar.MenuItem showLogoItem = settingsItem.addItem("Show logo", new MenuBar.Command() {

        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            if (selectedItem.isChecked()) {
                showLogo();
            } else {
                hideLogo();
            }
        }
    });
    showLogoItem.setCheckable(true);

    sideBar.setHeader(header);
}

From source file:rs.co.micro.bwNet.navigationMenu.java

public navigationMenu() {

    //Main Panel/*from   w w  w. j  a v  a 2 s  . c o  m*/
    setResponsive(true);
    setSpacing(true);
    setMargin(false);

    HorizontalLayout topMenu = new HorizontalLayout();
    topMenu.setSizeFull();

    //Logout Dugme
    MenuBar logout = new MenuBar();
    logout.setId("logoutDugme");
    logout.setSizeFull();
    logout.setResponsive(true);
    logout.setDescription("Izadjite iz programa");

    MenuBar.MenuItem logoutDugme = logout.addItem("Logout", FontAwesome.SIGN_OUT, new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            getUI().getSession().close();
            navigator.addView("login", new login());
            navigator.navigateTo("login");
        }
    });

    //Navigacioni meni
    MenuBar navMeni = new MenuBar();
    navMeni.setId("navMeni");
    navMeni.setSizeFull();
    navMeni.setResponsive(true);

    // A top-level menu item that opens a submenu
    MenuBar.MenuItem uvidi = navMeni.addItem("Uvidi", null, null);
    //Nesto poput click listenera
    MenuBar.Command mycommand = new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            Notification.show("radi");
        }
    };

    //        karticaPartnera.addItem("Tea",
    //                FontAwesome.DROPBOX, mycommand);
    //        karticaPartnera.addItem("Coffee",
    //                FontAwesome.COFFEE, mycommand);
    // Another top-level item
    MenuBar.MenuItem snacks = navMeni.addItem("Snacks", null, null);
    snacks.addItem("Weisswurst", null, mycommand);
    snacks.addItem("Bratwurst", null, mycommand);
    snacks.addItem("Currywurst", null, mycommand);
    snacks.addItem("Test1", null, mycommand);
    snacks.addItem("test2", null, mycommand);

    // Yet another top-level item
    MenuBar.MenuItem servs = navMeni.addItem("Services", null, null);
    servs.addItem("Car Service", null, mycommand);

    topMenu.addComponents(navMeni, logout);
    addComponents(topMenu);

    // Kreira Kartica Partnera submeni i pokazuje Karticu 
    MenuBar.MenuItem karticaPartnera;
    karticaPartnera = uvidi.addItem("Kartica Partnera", null, new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {

            try {
                navigator.addView("BWKarticaPartnera", new BWkarticaPartnera());

            } catch (SQLException ex) {
                System.out.println("Greska (BWnFinex klasa)" + SQLException.class);
            }
            navigator.navigateTo("BWKarticaPartnera");
        }
    });

    System.out.println("ubacen meni");
}