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, MenuBar.Command command) 

Source Link

Document

Add a new item to the menu bar.

Usage

From source file:it.vige.greenarea.bpm.custom.ui.mainlayout.GreenareaMainMenuBar.java

License:Apache License

protected void initProfileButton() {

    if (useProfile()) {
        final LoggedInUser user = get().getLoggedInUser();

        // User name + link to profile
        MenuBar profileMenu = new MenuBar();
        UserConverter userConverter = new UserConverter();
        List<Group> groups = get().getLoggedInUser().getGroups();
        if (userConverter.isUserInGroup(groups, OPERATORE_LOGISTICO))
            profileMenu.addStyleName(STYLE_OPERATORE_LOGISTICO_HEADER_PROFILE_BOX);
        else if (userConverter.isUserInGroup(groups, SOCIETA_DI_TRASPORTO))
            profileMenu.addStyleName(STYLE_SOCIETA_DI_TRASPORTO_HEADER_PROFILE_BOX);
        else if (userConverter.isUserInGroup(groups, TRASPORTATORE_AUTONOMO))
            profileMenu.addStyleName(STYLE_SOCIETA_DI_TRASPORTO_HEADER_PROFILE_BOX);
        else/*from   w ww  . ja  va 2  s  . c om*/
            profileMenu.addStyleName(STYLE_PA_HEADER_PROFILE_BOX);
        profileMenu.setHeight(14, UNITS_PIXELS);
        MenuItem rootItem = profileMenu.addItem(user.getFirstName() + " " + user.getLastName(), null);
        rootItem.setStyleName(STYLE_HEADER_PROFILE_MENU);

        // Show profile
        rootItem.addItem(i18nManager.getMessage(PROFILE_SHOW), new Command() {
            private static final long serialVersionUID = 8748698561304992624L;

            public void menuSelected(MenuItem selectedItem) {
                get().getViewManager().showProfilePopup(user.getId());
            }
        });

        // Edit profile
        rootItem.addItem(i18nManager.getMessage(PROFILE_EDIT), new Command() {
            private static final long serialVersionUID = -5815196339877745007L;

            public void menuSelected(MenuItem selectedItem) {
                // TODO: Show in edit-mode
                get().getViewManager().showProfilePopup(user.getId());
            }
        });

        // Change password
        rootItem.addItem(i18nManager.getMessage(PASSWORD_CHANGE), new Command() {
            private static final long serialVersionUID = -1060329084309607294L;

            public void menuSelected(MenuItem selectedItem) {
                get().getViewManager().showPopupWindow(new ChangePasswordPopupWindow());
            }
        });

        rootItem.addSeparator();

        // Logout
        rootItem.addItem(i18nManager.getMessage(HEADER_LOGOUT), new Command() {
            private static final long serialVersionUID = 1221427524106192724L;

            public void menuSelected(MenuItem selectedItem) {
                get().close();
            }
        });

        addComponent(profileMenu);
        // header.setComponentAlignment(profileMenu, TOP_RIGHT);
    }
}

From source file:module.pandabox.presentation.PandaBox.java

License:Open Source License

Layout getMenuBarPreviews() {
    Layout grid = getPreviewLayout("Menu bars");

    MenuBar menubar = new MenuBar();
    final MenuBar.MenuItem file = menubar.addItem("File", null);
    final MenuBar.MenuItem newItem = file.addItem("New", null);
    file.addItem("Open file...", null);
    file.addSeparator();/*from w w  w . j a va2  s  .  c o  m*/

    newItem.addItem("File", null);
    newItem.addItem("Folder", null);
    newItem.addItem("Project...", null);

    file.addItem("Close", null);
    file.addItem("Close All", null);
    file.addSeparator();

    file.addItem("Save", null);
    file.addItem("Save As...", null);
    file.addItem("Save All", null);

    final MenuBar.MenuItem edit = menubar.addItem("Edit", null);
    edit.addItem("Undo", null);
    edit.addItem("Redo", null).setEnabled(false);
    edit.addSeparator();

    edit.addItem("Cut", null);
    edit.addItem("Copy", null);
    edit.addItem("Paste", null);
    edit.addSeparator();

    final MenuBar.MenuItem find = edit.addItem("Find/Replace", null);

    // Actions can be added inline as well, of course
    find.addItem("Google Search", null);
    find.addSeparator();
    find.addItem("Find/Replace...", null);
    find.addItem("Find Next", null);
    find.addItem("Find Previous", null);

    final MenuBar.MenuItem view = menubar.addItem("View", null);
    view.addItem("Show/Hide Status Bar", null);
    view.addItem("Customize Toolbar...", null);
    view.addSeparator();

    view.addItem("Actual Size", null);
    view.addItem("Zoom In", null);
    view.addItem("Zoom Out", null);

    grid.addComponent(menubar);

    return grid;
}

From source file:nz.co.senanque.bundle1.AppFactoryImpl.java

License:Apache License

@Override
public App createApp(Blackboard blackboard) {
    App ret = new App();
    final Layout layout = new Layout();
    layout.setBlackboard(blackboard);/*from   www  .j ava  2  s  . c om*/
    ret.setComponentContainer(layout);

    MenuBar menuBar = new MenuBar();
    final MenuBar.MenuItem file = menuBar.addItem("File", null);
    file.addItem("Close", new Command() {

        private static final long serialVersionUID = -1L;

        public void menuSelected(MenuItem selectedItem) {
            layout.close();

        }
    });
    final MenuBar.MenuItem save = menuBar.addItem("Edit", null);
    save.addItem("Save", new Command() {

        private static final long serialVersionUID = -1L;

        public void menuSelected(MenuItem selectedItem) {
            layout.close();

        }
    });

    ret.setMenuBar(menuBar);
    return ret;
}

From source file:nz.co.senanque.perspectivemanager.MenuCloner.java

License:Apache License

public static void merge(MenuBar target, MenuBar source, List<MenuBar.MenuItem> added) {
    if (source != null) {
        List<MenuBar.MenuItem> targetItems = target.getItems();
        for (MenuBar.MenuItem sourceItem : source.getItems()) {
            MenuBar.MenuItem targetItem = findItem(sourceItem.getText(), targetItems);
            if (targetItem == null) {
                targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand());
                fixMenuItem(targetItem, sourceItem);
                added.add(targetItem);/*from  www .j a v  a2s  . c  o m*/
            }
            merge(targetItem, sourceItem, added);
        }
    }
}

From source file:nz.co.senanque.perspectiveslibrary.MenuCloner.java

License:Apache License

public static void merge(MenuBar target, MenuBar source, List<MenuBar.MenuItem> added) {
    if (source != null) {
        List<MenuBar.MenuItem> targetItems = target.getItems();
        for (MenuBar.MenuItem sourceItem : source.getItems()) {
            MenuBar.MenuItem targetItem = findItem(sourceItem.getText(), targetItems);
            if (targetItem == null) {
                try {
                    int sizeOfTarget = target.getSize();
                    if (sizeOfTarget > 0) {
                        targetItem = target.addItemBefore(sourceItem.getText(), null, sourceItem.getCommand(),
                                target.getItems().get(sizeOfTarget - 1));
                    }/* ww  w  .jav a  2  s  .  co m*/
                } catch (Exception e) {
                }
                if (targetItem == null) {
                    targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand());
                }
                fixMenuItem(targetItem, sourceItem);
                added.add(targetItem);
            }
            merge(targetItem, sourceItem, added);
        }
    }
}

From source file:nz.co.senanque.pizzabundle.AppFactoryImpl.java

License:Apache License

public App createApp(Blackboard blackboard) {
    // Explicitly fetch this bean to ensure it is not instantiated until the session has started.
    m_maduraSessionManager = m_beanFactory.getBean("maduraSessionManager", MaduraSessionManager.class);
    App ret = new App();
    MaduraFieldGroup fieldGroup = getMaduraSessionManager().createMaduraFieldGroup();
    final Layout layout = new Layout(m_maduraSessionManager, fieldGroup);
    layout.setBlackboard(blackboard);/* w w w  .  jav  a 2  s  .  c  om*/
    ret.setComponentContainer(layout);
    Pizza pizza = new Pizza();

    m_maduraSessionManager.getValidationSession().bind(pizza);
    MenuBar menuBar = new MenuBar();
    final MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource);
    final MenuBar.MenuItem edit = menuBar.addItem(messageSourceAccessor.getMessage("menu.edit", "Edit"), null);

    CommandExt command = fieldGroup.createMenuItemCommand(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show(messageSourceAccessor.getMessage("message.clicked.cancel"),
                    messageSourceAccessor.getMessage("message.noop"), Notification.Type.HUMANIZED_MESSAGE);

        }
    });
    MenuItem menuItemSave = edit.addItem("menu.cancel", command);
    fieldGroup.bind(menuItemSave);

    command = fieldGroup.createMenuItemCommandSubmit(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show(messageSourceAccessor.getMessage("message.clicked.submit"),
                    messageSourceAccessor.getMessage("message.noop"), Notification.Type.HUMANIZED_MESSAGE);

        }
    });
    MenuItem menuItemCancel = edit.addItem("menu.save", command);
    fieldGroup.bind(menuItemCancel);

    ret.setMenuBar(menuBar);

    layout.load(pizza);

    return ret;
}

From source file:org.activiti.explorer.ui.mainlayout.MainMenuBar.java

License:Apache License

protected void initProfileButton() {
    final LoggedInUser user = ExplorerApp.get().getLoggedInUser();

    // User name + link to profile 
    MenuBar profileMenu = new MenuBar();
    profileMenu.addStyleName(ExplorerLayout.STYLE_HEADER_PROFILE_BOX);
    MenuItem rootItem = profileMenu.addItem(user.getFirstName() + " " + user.getLastName(), null);
    rootItem.setStyleName(ExplorerLayout.STYLE_HEADER_PROFILE_MENU);

    if (useProfile()) {
        // Show profile
        rootItem.addItem(i18nManager.getMessage(Messages.PROFILE_SHOW), new Command() {
            public void menuSelected(MenuItem selectedItem) {
                ExplorerApp.get().getViewManager().showProfilePopup(user.getId());
            }// w  w  w .ja v  a 2s .c om
        });

        // Edit profile
        rootItem.addItem(i18nManager.getMessage(Messages.PROFILE_EDIT), new Command() {

            public void menuSelected(MenuItem selectedItem) {
                // TODO: Show in edit-mode
                ExplorerApp.get().getViewManager().showProfilePopup(user.getId());
            }
        });

        // Change password
        rootItem.addItem(i18nManager.getMessage(Messages.PASSWORD_CHANGE), new Command() {
            public void menuSelected(MenuItem selectedItem) {
                ExplorerApp.get().getViewManager().showPopupWindow(new ChangePasswordPopupWindow());
            }
        });

        rootItem.addSeparator();
    }

    // Logout
    rootItem.addItem(i18nManager.getMessage(Messages.HEADER_LOGOUT), new Command() {
        public void menuSelected(MenuItem selectedItem) {
            ExplorerApp.get().close();
        }
    });

    addComponent(profileMenu);
    setComponentAlignment(profileMenu, Alignment.TOP_RIGHT);
    setExpandRatio(profileMenu, 1.0f);
}

From source file:org.activiti.explorer.ui.MainMenuBar.java

License:Apache License

protected void initProfileButton() {
    final LoggedInUser user = ExplorerApp.get().getLoggedInUser();

    // User name + link to profile 
    MenuBar profileMenu = new MenuBar();
    profileMenu.addStyleName(ExplorerLayout.STYLE_HEADER_PROFILE_BOX);
    MenuItem rootItem = profileMenu.addItem(user.getFirstName() + " " + user.getLastName(), null);
    rootItem.setStyleName(ExplorerLayout.STYLE_HEADER_PROFILE_MENU);

    // Show profile
    rootItem.addItem(i18nManager.getMessage(Messages.PROFILE_SHOW), new Command() {
        public void menuSelected(MenuItem selectedItem) {
            ExplorerApp.get().getViewManager().showProfilePopup(user.getId());
        }//from ww  w .  j  a v a  2 s  .c o  m
    });

    // Edit profile
    rootItem.addItem(i18nManager.getMessage(Messages.PROFILE_EDIT), new Command() {

        public void menuSelected(MenuItem selectedItem) {
            // TODO: Show in edit-mode
            ExplorerApp.get().getViewManager().showProfilePopup(user.getId());
        }
    });

    // Change password
    rootItem.addItem(i18nManager.getMessage(Messages.PASSWORD_CHANGE), new Command() {
        public void menuSelected(MenuItem selectedItem) {
            ExplorerApp.get().getViewManager().showPopupWindow(new ChangePasswordPopupWindow());
        }
    });

    rootItem.addSeparator();
    // Logout
    rootItem.addItem(i18nManager.getMessage(Messages.HEADER_LOGOUT), new Command() {
        public void menuSelected(MenuItem selectedItem) {
            ExplorerApp.get().close();
        }
    });

    addComponent(profileMenu);
    setComponentAlignment(profileMenu, Alignment.TOP_RIGHT);
    setExpandRatio(profileMenu, 1.0f);
}

From source file:org.azrul.langkuik.Langkuik.java

public void initLangkuik(final EntityManagerFactory emf, final UI ui,
        final RelationManagerFactory relationManagerFactory, List<Class<?>> customTypeInterfaces) {

    List<Class<?>> rootClasses = new ArrayList<>();
    for (ManagedType<?> entity : emf.getMetamodel().getManagedTypes()) {
        Class<?> clazz = entity.getJavaType();
        if (clazz.getAnnotation(WebEntity.class).isRoot() == true) {
            rootClasses.add(clazz);//from  w  ww  .ja  va  2 s  . c o m
        }
    }

    //Manage custom type
    if (customTypeInterfaces == null) {
        customTypeInterfaces = new ArrayList<>();
    }
    //add system level custom type
    customTypeInterfaces.add(AttachmentCustomType.class);
    //create DAOs for custom types
    final List<DataAccessObject<?>> customTypeDaos = new ArrayList<>();
    for (Class<?> clazz : customTypeInterfaces) {
        customTypeDaos.add(new HibernateGenericDAO(emf, clazz));
    }

    //Setup page
    VerticalLayout main = new VerticalLayout();
    VerticalLayout content = new VerticalLayout();
    final Navigator navigator = new Navigator(ui, content);
    final HorizontalLayout breadcrumb = new HorizontalLayout();

    MenuBar menubar = new MenuBar();
    menubar.setId("MENUBAR");
    main.addComponent(menubar);
    main.addComponent(breadcrumb);
    main.addComponent(content);

    final Deque<History> history = new ArrayDeque<>();
    final Configuration config = Configuration.getInstance();

    history.push(new History("START", "Start"));
    StartView startView = new StartView(history, breadcrumb);
    navigator.addView("START", startView);
    MenuBar.MenuItem create = menubar.addItem("Create", null);
    MenuBar.MenuItem view = menubar.addItem("View", null);

    final PageParameter pageParameter = new PageParameter(customTypeDaos, emf, relationManagerFactory, history,
            config, breadcrumb);

    for (final Class rootClass : rootClasses) {
        final WebEntity myObject = (WebEntity) rootClass.getAnnotation(WebEntity.class);
        final DataAccessObject<?> dao = new HibernateGenericDAO<>(emf, rootClass);
        create.addItem("New " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                Object object = dao.createNew(true);
                BeanView<Object, ?> createNewView = new BeanView<>(object, null, null, pageParameter);
                String targetView = "CREATE_NEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) createNewView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "Create new " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
        view.addItem("View " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                PlainTableView<?> seeApplicationView = new PlainTableView<>(rootClass, pageParameter);
                String targetView = "VIEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) seeApplicationView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "View " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
    }

    menubar.addItem("Logout", null).addItem("Logout", new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            ConfirmDialog.show(ui, "Please Confirm:", "Are you really sure you want to log out?", "I am",
                    "Not quite", new ConfirmDialog.Listener() {
                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                HttpServletRequest req = (HttpServletRequest) VaadinService.getCurrentRequest();
                                HttpServletResponse resp = (HttpServletResponse) VaadinService
                                        .getCurrentResponse();
                                Authentication auth = SecurityContextHolder.getContext().getAuthentication();
                                SecurityContextLogoutHandler ctxLogOut = new SecurityContextLogoutHandler();
                                ctxLogOut.logout(req, resp, auth);
                            }
                        }
                    });

        }
    });
    navigator.navigateTo("START");
    ui.setContent(main);
}

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 av a2  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;
}