Example usage for com.vaadin.ui MenuBar.MenuItem addItem

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

Introduction

In this page you can find the example usage for com.vaadin.ui MenuBar.MenuItem 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:annis.gui.flatquerybuilder.FlatQueryBuilder.java

License:Apache License

private void initialize() {
    // try to remove all existing menus
    try {//from   w w  w  .jav a2s .  c  o  m
        language.removeComponent(addMenu);
        span.removeComponent(addMenuSpan);
        meta.removeComponent(addMenuMeta);
    } catch (Exception e) {
        log.error(null, e);
    }

    //init variables:
    final FlatQueryBuilder sq = this;
    Collection<String> annonames = getAvailableAnnotationNames();
    Collection<String> metanames = getAvailableMetaNames();

    //Code from btInitLanguage:    
    addMenu = new MenuBar();
    //addMenu.setDescription(INFO_INIT_LANG);
    addMenu.setAutoOpen(false);
    final MenuBar.MenuItem add = addMenu.addItem(ADD_LING_PARAM, null);
    for (final String annoname : annonames) {
        add.addItem(annoname, new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                if (!vnodes.isEmpty()) {
                    EdgeBox eb = new EdgeBox(sq);
                    languagenodes.addComponent(eb);
                    eboxes.add(eb);
                }
                VerticalNode vn = new VerticalNode(annoname, sq);
                languagenodes.addComponent(vn);
                vnodes.add(vn);
                addMenu.setAutoOpen(false);
            }
        });
    }
    language.removeComponent(btInitLanguage);
    language.addComponent(addMenu);

    //Code from btInitSpan:    
    addMenuSpan = new MenuBar();
    //addMenuSpan.setDescription(INFO_INIT_SPAN);
    addMenuSpan.setAutoOpen(false);
    final MenuBar.MenuItem addSpan = addMenuSpan.addItem(ADD_SPAN_PARAM, null);
    for (final String annoname : annonames) {
        addSpan.addItem(annoname, new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                sq.removeSpanBox();
                sq.addSpanBox(annoname);
                addMenuSpan.setAutoOpen(false);
            }
        });
    }
    spanMenu = addSpan;
    span.removeComponent(btInitSpan);
    span.addComponent(addMenuSpan);

    //Code from btInitMeta:    
    addMenuMeta = new MenuBar();
    //addMenuMeta.setDescription(INFO_INIT_META);  
    addMenuMeta.setAutoOpen(false);
    final MenuBar.MenuItem addMeta = addMenuMeta.addItem(ADD_META_PARAM, null);
    int i = 0;
    for (final String annoname : metanames) {
        addMeta.addItem(annoname, new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                MetaBox mb = new MetaBox(annoname, sq);
                meta.addComponent(mb);
                mboxes.add(mb);
                addMenuMeta.setAutoOpen(false);
                //addMeta.removeChild(selectedItem);
                selectedItem.setVisible(false);
            }
        });
    }
    meta.removeComponent(btInitMeta);
    meta.addComponent(addMenuMeta);
}

From source file:at.peppol.webgui.app.MainWindow.java

License:Mozilla Public License

private void createMenuBar() {

    topBarLayout.setMargin(false, false, false, false);
    topBarLayout.setSizeFull();//from w ww .j a va  2s.c  om
    // topBarLayout.setStyleName("v-menubar");
    topBarLayoutLeft = new HorizontalLayout();
    topBarLayoutRight = new HorizontalLayout();

    // Label pawgLabel = new Label("PAWG",Label.CONTENT_XHTML);
    // pawgLabel.setStyleName("v-menubar");
    // pawgLabel.addStyleName("v-label-big");
    // pawgLabel.setSizeFull();
    // topBarLayoutLeft.addComponent(pawgLabel);

    final MenuBar lMenuBar = new MenuBar();
    lMenuBar.setHtmlContentAllowed(true);
    lMenuBar.addItem("<b>PAWG<b>", new MenuBar.Command() {

        @Override
        public void menuSelected(final MenuItem selectedItem) {

            removeComponent(mainContentComponent);
            showInitialMainContent(um.getDrafts());
        }
    });
    final MenuBar.MenuItem docItem = lMenuBar.addItem("Document", null);
    lMenuBar.addItem("Preferences", null);
    lMenuBar.addItem("Logout", new MenuBar.Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            PawgApp.getInstance().logout();
            PawgApp.getInstance().showLoginWindow();
        }
    });
    lMenuBar.addItem("About", null);
    lMenuBar.setSizeFull();

    final MenuBar.MenuItem invItem = docItem.addItem("Invoice", null);
    final MenuBar.MenuItem orderItem = docItem.addItem("Order", null);
    invItem.addItem("New ...", new MenuBar.Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            showInvoiceForm();
            //showInvoiceForm (null);
        }
    });
    invItem.addItem("View ... ", new MenuBar.Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            showTestForm();
        }
    });
    invItem.addItem("Upload ...", new MenuBar.Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            showInvUploadWindow();
        }
    });

    orderItem.addItem("New", null);
    orderItem.addItem("View", null);
    orderItem.addItem("Upload ...", new MenuBar.Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            showOrdUploadWindow();
        }
    });

    topBarLayoutLeft.addComponent(lMenuBar);

    final IUser user = (IUser) PawgApp.getInstance().getUser();

    topBarLayoutLeft.setComponentAlignment(lMenuBar, Alignment.MIDDLE_CENTER);
    topBarLayoutLeft.setSpacing(false);
    topBarLayoutLeft.setSizeFull();
    topBarLayoutRight.setSizeUndefined();

    final MenuBar rMenuBar = new MenuBar();
    rMenuBar.setHtmlContentAllowed(true);
    final MenuBar.MenuItem userLabel = rMenuBar.addItem("<b>" + user.getEmailAddress() + "<b>", null);
    userLabel.addItem("Logout", new MenuBar.Command() {
        @Override
        public void menuSelected(final MenuItem selectedItem) {
            PawgApp.getInstance().logout();
        }
    });
    topBarLayoutRight.addComponent(rMenuBar);
    topBarLayout.addComponent(topBarLayoutLeft);
    topBarLayout.addComponent(topBarLayoutRight);
    topBarLayout.setComponentAlignment(topBarLayoutRight, Alignment.MIDDLE_RIGHT);
    topBarLayout.setExpandRatio(topBarLayoutLeft, 1);
    // topBarLayout.setExpandRatio(topBarLayoutRight, 1);
    addComponent(topBarLayout);

}

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

License:Apache License

static MenuBar getMenuBar() {
    Command click = new Command() {
        @Override//w w  w .  jav a  2s  .  c  om
        public void menuSelected(MenuItem selectedItem) {
            Notification.show("Clicked " + selectedItem.getText());
        }
    };

    MenuBar menubar = new MenuBar();
    menubar.setWidth("100%");
    final MenuBar.MenuItem file = menubar.addItem("File", null);
    final MenuBar.MenuItem newItem = file.addItem("New", null);
    file.addItem("Open file...", click);
    file.addSeparator();

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

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

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

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

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

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

    find.addItem("Google Search", click);
    find.addSeparator();
    find.addItem("Find/Replace...", click);
    find.addItem("Find Next", click);
    find.addItem("Find Previous", click);

    Command check = new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            Notification.show(selectedItem.isChecked() ? "Checked" : "Unchecked");
        }
    };

    final MenuBar.MenuItem view = menubar.addItem("View", null);
    view.addItem("Show Status Bar", check).setCheckable(true);
    MenuItem title = view.addItem("Show Title Bar", check);
    title.setCheckable(true);
    title.setChecked(true);
    view.addItem("Customize Toolbar...", click);
    view.addSeparator();

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

    TestIcon testIcon = new TestIcon(50);

    MenuItem fav = menubar.addItem("", check);
    fav.setIcon(testIcon.get());
    fav.setStyleName("icon-only");
    fav.setCheckable(true);
    fav.setChecked(true);

    fav = menubar.addItem("", check);
    fav.setIcon(testIcon.get());
    fav.setStyleName("icon-only");
    fav.setCheckable(true);
    fav.setCheckable(true);

    menubar.addItem("Attach", click).setIcon(FontAwesome.PAPERCLIP);
    menubar.addItem("Undo", click).setIcon(FontAwesome.UNDO);
    MenuItem redo = menubar.addItem("Redo", click);
    redo.setIcon(FontAwesome.REPEAT);
    redo.setEnabled(false);
    menubar.addItem("Upload", click).setIcon(FontAwesome.UPLOAD);

    return menubar;
}

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

License:Apache License

static MenuBar getMenuButton(String caption, boolean splitButton) {
    MenuBar split = new MenuBar();
    MenuBar.MenuItem dropdown = split.addItem(caption, null);
    if (splitButton) {
        dropdown = split.addItem("", null);
    }/*from w  ww . j  a  va 2s  .  c  om*/
    dropdown.addItem("Another Action", null);
    dropdown.addItem("Secondary Action", null);
    dropdown.addSeparator();
    dropdown.addItem("Last Action", null);

    return split;
}

From source file:com.example.themes.valo.MenuBars.java

License:Apache License

static MenuBar getMenuBar() {
    Command click = new Command() {
        @Override// www  .j a  v  a 2s.c om
        public void menuSelected(MenuItem selectedItem) {
            Notification.show("Clicked " + selectedItem.getText());
        }
    };

    MenuBar menubar = new MenuBar();
    menubar.setWidth("100%");
    final MenuBar.MenuItem file = menubar.addItem("Draft", null);
    final MenuBar.MenuItem newItem = file.addItem("New", null);
    file.addItem("Open file...", click);
    file.addSeparator();

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

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

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

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

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

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

    find.addItem("Google Search", click);
    find.addSeparator();
    find.addItem("Find/Replace...", click);
    find.addItem("Find Next", click);
    find.addItem("Find Previous", click);

    Command check = new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            Notification.show(selectedItem.isChecked() ? "Checked" : "Unchecked");
        }
    };

    final MenuBar.MenuItem view = menubar.addItem("View", null);
    view.addItem("Show Status Bar", check).setCheckable(true);
    MenuItem title = view.addItem("Show Title Bar", check);
    title.setCheckable(true);
    title.setChecked(true);
    view.addItem("Customize Toolbar...", click);
    view.addSeparator();

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

    TestIcon testIcon = new TestIcon(50);

    MenuItem fav = menubar.addItem("", check);
    fav.setIcon(testIcon.get());
    fav.setStyleName("icon-only");
    fav.setCheckable(true);
    fav.setChecked(true);

    fav = menubar.addItem("", check);
    fav.setIcon(testIcon.get());
    fav.setStyleName("icon-only");
    fav.setCheckable(true);
    fav.setCheckable(true);

    menubar.addItem("Attach", click).setIcon(FontAwesome.PAPERCLIP);
    menubar.addItem("Undo", click).setIcon(FontAwesome.UNDO);
    MenuItem redo = menubar.addItem("Redo", click);
    redo.setIcon(FontAwesome.REPEAT);
    redo.setEnabled(false);
    menubar.addItem("Upload", click).setIcon(FontAwesome.UPLOAD);

    return menubar;
}

From source file:com.expressui.core.view.menu.MenuBarNode.java

License:Open Source License

private void populate(MenuBar.MenuItem menuItem) {
    for (MenuBarNode child : children.values()) {
        if (child.isViewAllowed() && child.isVisible()) {
            MenuBar.MenuItem childMenuItem = menuItem.addItem(child.caption, child.command);
            child.populate(childMenuItem);
        }//from  w  w  w  . jav  a 2s.  c  om
    }
}

From source file:com.parship.roperty.ui.LoginUI.java

License:Apache License

/**
 * The constructor should first build the main layout, set the
 * composition root and then do any custom initialization.
 * The constructor will not be automatically regenerated by the
 * visual editor./*  w w  w.j  a  v a 2 s. co  m*/
 */
public LoginUI() {
    buildMainLayout();
    setCompositionRoot(mainLayout);

    // Set Logo
    // Find the application directory
    String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
    FileResource resourceLogo = new FileResource(new File(basepath + "/WEB-INF/images/roperty-logo.png"));
    logoImage.setSource(resourceLogo);

    /* MenuBar */
    // About
    MenuBar.MenuItem about = menuBar.addItem("About Roperty", null);
    about.addItem("Visit Website", null);
    about.addItem("Team", null);

    // Debug
    MenuBar.MenuItem debug = menuBar.addItem("Debug", null);
    debug.addItem("Logout", new LogoutCommand());

    // Enter-Listener for login
    ShortcutListener enterListener = new ShortcutListener("ENTER", ShortcutAction.KeyCode.ENTER, null) {

        private static final long serialVersionUID = 1L;

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == passTextField || target == userTextField) {
                buttonClick(null);
            }
        }
    };

    this.userTextField.addShortcutListener(enterListener);
    this.passTextField.addShortcutListener(enterListener);

    this.userTextField.setInputPrompt("Username");
    this.passTextField.setInputPrompt("Password");

    String prevUser = RopertyUiSession.getPreviousUserName();
    if (prevUser != null) {
        this.userTextField.setValue(prevUser);
        this.passTextField.focus();
    } else {
        this.userTextField.focus();
    }

    String rememberMe = RopertyUiSession.wasRememberMe();
    if (rememberMe != null && rememberMe.equals("true")) {
        this.keeploggedinLabel.setValue(true);
    }

    this.loginButton.addClickListener(this);

    if (UserManager.isLoggedIn()) {
        buttonClick(null);
    }

}

From source file:com.parship.roperty.ui.NavigationViewUI.java

License:Apache License

/**
 * The constructor should first build the main layout, set the
 * composition root and then do any custom initialization.
 * The constructor will not be automatically regenerated by the
 * visual editor./*w w  w .  j a v  a  2 s  .  co  m*/
 */
public NavigationViewUI() {
    buildMainLayout();
    setCompositionRoot(mainLayout);

    /* Menu Bar */
    // User Menu
    User currentUser = UserManager.getCurrentUser();
    if (currentUser != null) {
        String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
        FileResource resourceCloudIcon = new FileResource(
                new File(basepath + "/WEB-INF/images/icons/111-user.png"));
        MenuBar.MenuItem userMenu = mainMenuBar.addItem(currentUser.getFullName(), null);
        userMenu.setIcon(resourceCloudIcon);
        userMenu.addItem("Logout", new LogoutCommand());
    }
}

From source file:com.siemens.ct.osgi.vaadin.pm.main.MainApplication.java

License:Open Source License

@SuppressWarnings("serial")
private MenuBar getMenu() {
    MenuBar menubar = new MenuBar();
    menubar.setWidth("100%");
    actionMenu = menubar.addItem("Action", null);

    actionMenu.addItem("Built-in Action...", new Command() {
        @Override//from   www .j  a v  a2s .  c o  m
        public void menuSelected(MenuItem selectedItem) {
            main.showNotification("Built-in Action executed!");
        }
    });
    actionMenu.addSeparator();

    final MenuBar.MenuItem viewMenu = menubar.addItem("Help", null);
    viewMenu.addItem("About...", new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            main.addWindow(getAboutDialog());
        }
    });

    return menubar;
}

From source file:com.yoncabt.ebr.ui.ReportWindow.java

private void createMenuBar(MenuBar.MenuItem mainItem, File dir) throws IOException, JRException {
    //FIXME baz kodlar servise taabilir
    String menuText = dir.getName();
    File folderConfig = new File(dir, EBRParams.FOLDER_EBR_JSON);
    if (folderConfig.exists()) {
        try {//from w w  w . jav  a  2  s.  c  o m
            JSONObject jo = new JSONObject(FileUtils.readFileToString(folderConfig, "utf-8"));
            menuText = jo.optString("label", menuText);
        } catch (IOException ex) {
            throw new IOException(folderConfig.getAbsolutePath(), ex);
        } catch (JSONException ex) {
            throw new JSONException(new RuntimeException(folderConfig.getAbsolutePath(), ex));
        }
    }
    MenuBar.MenuItem menuItem = mainItem.addItem(menuText, null);

    for (File file : dir.listFiles()) {
        if (file.getName().charAt(0) == '.') {
            continue;//gereksiz ama olduu belli olsun
        } else if (file.isDirectory()) {
            createMenuBar(menuItem, file);
        } else if (file.getName().endsWith(".sql") || file.getName().endsWith(".jrxml")) {
            BaseReport r = file.getName().endsWith(".sql") ? new SQLReport() : new JasperReport();
            context.getAutowireCapableBeanFactory().autowireBean(r);
            String text;
            try {
                text = r.loadDefinition(file).getCaption();
            } catch (ReportException ex) {
                Notification.show("Hata", Notification.Type.ERROR_MESSAGE);
                Logger.getLogger(ReportWindow.class.getName()).log(Level.SEVERE, null, ex);
                text = file.getName() + " ERROR";
            }
            menuItem.addItem(text, (MenuBar.MenuItem selectedItem) -> {
                System.out.println(r.getFile() + " altrlacak");
                String frag = StringUtils.removeStart(r.getFile().getAbsolutePath(),
                        EBRConf.INSTANCE.getValue(EBRParams.REPORTS_JRXML_PATH, ""));
                frag = StringUtils.removeStart(frag, "/");
                getPage().setUriFragment(frag);
            });
        } else if (file.getName().endsWith(".jrxml")) {//FIXME support for compiled jasper files
            final JasperReport r = new JasperReport();
            context.getAutowireCapableBeanFactory().autowireBean(r);
            String text = r.loadDefinition(file).getCaption();
            menuItem.addItem(text, (MenuBar.MenuItem selectedItem) -> {
                System.out.println(r.getFile() + " altrlacak");
                String frag = StringUtils.removeStart(r.getFile().getAbsolutePath(),
                        EBRConf.INSTANCE.getValue(EBRParams.REPORTS_JRXML_PATH, ""));
                frag = StringUtils.removeStart(frag, "/");
                getPage().setUriFragment(frag);
            });
        }
    }
}