Example usage for com.vaadin.ui MenuBar setStyleName

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

Introduction

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

Prototype

@Override
    public void setStyleName(String style) 

Source Link

Usage

From source file:annis.gui.components.NavigateableSinglePage.java

License:Apache License

private MenuBar createMenubarFromHTML(File localFile, URI externalURI, Map<String, MenuItem> idToMenuItem) {

    MenuBar mbNavigation = new MenuBar();
    mbNavigation.setStyleName("huge");
    MenuItem navRoot = mbNavigation.addItem("Choose topic", null);
    navRoot.setStyleName("huge");

    try (FileInputStream input = new FileInputStream(localFile)) {
        Document doc = Jsoup.parse(input, "UTF-8", externalURI.toASCIIString());

        ArrayList<MenuItem> itemPath = new ArrayList<>();
        // find all headers that have an ID
        for (Element e : doc.getElementsByAttribute("id")) {
            Matcher m = regexHeader.matcher(e.tagName());
            if (m.matches()) {
                int level = Integer.parseInt(m.group(1)) - 1;

                // decide wether to expand the path (one level deeper) or to truncate
                if (level == 0) {
                    itemPath.clear();/*  ww w  .  j  a  va2  s .  c o  m*/
                } else if (itemPath.size() >= level) {
                    // truncate
                    itemPath = new ArrayList<>(itemPath.subList(0, level));
                }

                if (itemPath.isEmpty() && level > 0) {
                    // fill the path with empty elements
                    for (int i = 0; i < level; i++) {
                        itemPath.add(createItem(navRoot, itemPath, "<empty>", null));
                    }
                }
                MenuItem item = createItem(navRoot, itemPath, e.text(), e.id());
                itemPath.add(item);
                idToMenuItem.put(e.id(), item);
            }
        }
    } catch (IOException ex) {
        log.error("Could not parse iframe source", ex);
    }
    return mbNavigation;
}

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

License:Apache License

Panel windows() {
    Panel p = new Panel("Dialogs");
    VerticalLayout content = new VerticalLayout() {
        final Window win = new Window("Window Caption");
        String prevHeight = "300px";
        boolean footerVisible = true;
        boolean autoHeight = false;
        boolean tabsVisible = false;
        boolean toolbarVisible = false;
        boolean footerToolbar = false;
        boolean toolbarLayout = false;
        String toolbarStyle = null;

        VerticalLayout windowContent() {
            VerticalLayout root = new VerticalLayout();

            if (toolbarVisible) {
                MenuBar menuBar = MenuBars.getToolBar();
                menuBar.setSizeUndefined();
                menuBar.setStyleName(toolbarStyle);
                Component toolbar = menuBar;
                if (toolbarLayout) {
                    menuBar.setWidth(null);
                    HorizontalLayout toolbarLayout = new HorizontalLayout();
                    toolbarLayout.setWidth("100%");
                    toolbarLayout.setSpacing(true);
                    Label label = new Label("Tools");
                    label.setSizeUndefined();
                    toolbarLayout.addComponents(label, menuBar);
                    toolbarLayout.setExpandRatio(menuBar, 1);
                    toolbarLayout.setComponentAlignment(menuBar, Alignment.TOP_RIGHT);
                    toolbar = toolbarLayout;
                }// ww  w .  j  a  v a  2  s  .c o m
                toolbar.addStyleName("v-window-top-toolbar");
                root.addComponent(toolbar);
            }

            Component content = null;

            if (tabsVisible) {
                TabSheet tabs = new TabSheet();
                tabs.setSizeFull();
                VerticalLayout l = new VerticalLayout();
                l.addComponent(new Label(
                        "<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
                        ContentMode.HTML));
                l.setMargin(true);
                tabs.addTab(l, "Selected");
                tabs.addTab(new Label("&nbsp;", ContentMode.HTML), "Another");
                tabs.addTab(new Label("&nbsp;", ContentMode.HTML), "One more");
                tabs.addStyleName("padded-tabbar");
                tabs.addSelectedTabChangeListener(new SelectedTabChangeListener() {
                    @Override
                    public void selectedTabChange(final SelectedTabChangeEvent event) {
                        try {
                            Thread.sleep(600);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                });
                content = tabs;
            } else if (!autoHeight) {
                Panel p = new Panel();
                p.setSizeFull();
                p.addStyleName("borderless");
                if (!toolbarVisible || !toolbarLayout) {
                    p.addStyleName("scroll-divider");
                }
                VerticalLayout l = new VerticalLayout();
                l.addComponent(new Label(
                        "<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
                        ContentMode.HTML));
                l.setMargin(true);
                p.setContent(l);
                content = p;
            } else {
                content = new Label(
                        "<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
                        ContentMode.HTML);
                root.setMargin(true);
            }

            root.addComponent(content);

            if (footerVisible) {
                HorizontalLayout footer = new HorizontalLayout();
                footer.setWidth("100%");
                footer.setSpacing(true);
                footer.addStyleName("v-window-bottom-toolbar");

                Label footerText = new Label("Footer text");
                footerText.setSizeUndefined();

                Button ok = new Button("OK");
                ok.addStyleName("primary");

                Button cancel = new Button("Cancel");

                footer.addComponents(footerText, ok, cancel);
                footer.setExpandRatio(footerText, 1);

                if (footerToolbar) {
                    MenuBar menuBar = MenuBars.getToolBar();
                    menuBar.setStyleName(toolbarStyle);
                    menuBar.setWidth(null);
                    footer.removeAllComponents();
                    footer.addComponent(menuBar);
                }

                root.addComponent(footer);
            }

            if (!autoHeight) {
                root.setSizeFull();
                root.setExpandRatio(content, 1);
            }

            return root;
        }

        {
            setSpacing(true);
            setMargin(true);
            win.setWidth("380px");
            win.setHeight(prevHeight);
            win.setClosable(false);
            win.setResizable(false);
            win.setContent(windowContent());
            win.setCloseShortcut(KeyCode.ESCAPE, null);

            Command optionsCommand = new Command() {
                @Override
                public void menuSelected(final MenuItem selectedItem) {
                    if (selectedItem.getText().equals("Footer")) {
                        footerVisible = selectedItem.isChecked();
                    }
                    if (selectedItem.getText().equals("Auto Height")) {
                        autoHeight = selectedItem.isChecked();
                        if (!autoHeight) {
                            win.setHeight(prevHeight);
                        } else {
                            prevHeight = win.getHeight() + win.getHeightUnits().toString();
                            win.setHeight(null);
                        }
                    }
                    if (selectedItem.getText().equals("Tabs")) {
                        tabsVisible = selectedItem.isChecked();
                    }

                    if (selectedItem.getText().equals("Top")) {
                        toolbarVisible = selectedItem.isChecked();
                    }

                    if (selectedItem.getText().equals("Footer")) {
                        footerToolbar = selectedItem.isChecked();
                    }

                    if (selectedItem.getText().equals("Top layout")) {
                        toolbarLayout = selectedItem.isChecked();
                    }

                    if (selectedItem.getText().equals("Borderless")) {
                        toolbarStyle = selectedItem.isChecked() ? "borderless" : null;
                    }

                    win.setContent(windowContent());
                }
            };

            MenuBar options = new MenuBar();
            options.setCaption("Content");
            options.addItem("Auto Height", optionsCommand).setCheckable(true);
            options.addItem("Tabs", optionsCommand).setCheckable(true);
            MenuItem option = options.addItem("Footer", optionsCommand);
            option.setCheckable(true);
            option.setChecked(true);
            options.addStyleName("small");
            addComponent(options);

            options = new MenuBar();
            options.setCaption("Toolbars");
            options.addItem("Footer", optionsCommand).setCheckable(true);
            options.addItem("Top", optionsCommand).setCheckable(true);
            options.addItem("Top layout", optionsCommand).setCheckable(true);
            options.addItem("Borderless", optionsCommand).setCheckable(true);
            options.addStyleName("small");
            addComponent(options);

            Command optionsCommand2 = new Command() {
                @Override
                public void menuSelected(final MenuItem selectedItem) {
                    if (selectedItem.getText().equals("Caption")) {
                        win.setCaption(selectedItem.isChecked() ? "Window Caption" : null);
                    } else if (selectedItem.getText().equals("Closable")) {
                        win.setClosable(selectedItem.isChecked());
                    } else if (selectedItem.getText().equals("Resizable")) {
                        win.setResizable(selectedItem.isChecked());
                    } else if (selectedItem.getText().equals("Modal")) {
                        win.setModal(selectedItem.isChecked());
                    }
                }
            };

            options = new MenuBar();
            options.setCaption("Options");
            MenuItem caption = options.addItem("Caption", optionsCommand2);
            caption.setCheckable(true);
            caption.setChecked(true);
            options.addItem("Closable", optionsCommand2).setCheckable(true);
            options.addItem("Resizable", optionsCommand2).setCheckable(true);
            options.addItem("Modal", optionsCommand2).setCheckable(true);
            options.addStyleName("small");
            addComponent(options);

            final Button show = new Button("Open Window", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    getUI().addWindow(win);
                    win.center();
                    win.focus();
                    event.getButton().setEnabled(false);
                }
            });
            show.addStyleName("primary");
            addComponent(show);

            final CheckBox hidden = new CheckBox("Hidden");
            hidden.addValueChangeListener(new ValueChangeListener() {
                @Override
                public void valueChange(final ValueChangeEvent event) {
                    win.setVisible(!hidden.getValue());
                }
            });
            addComponent(hidden);

            win.addCloseListener(new CloseListener() {
                @Override
                public void windowClose(final CloseEvent e) {
                    show.setEnabled(true);
                }
            });
        }
    };
    p.setContent(content);
    return p;

}

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

License:Apache License

/**
 * Inits the application menu bar./* ww  w.jav  a2 s . 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:de.gedoplan.webclients.vaadin.VaadinDemoUi.java

public MenuBar createMenu() {
    User user = userProvider.get();//from w  w  w .  jav a 2  s .c o  m
    MenuBar mainMenu = new MenuBar();
    mainMenu.setWidth(100, Unit.PERCENTAGE);
    mainMenu.setStyleName("main");
    mainMenu.addItem("", new ThemeResource("images/vaadin-logo.png"),
            e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_INDEX)).setStyleName("logo");
    if (user.isInRole(User.UserRole.ADMIN)) {
        mainMenu.addItem(Messages.menu_customer.value(),
                e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_CUSTOMERS));
    }
    mainMenu.addItem(Messages.menu_orders.value(), e -> navigator.navigateTo(Konstanten.VAADIN_VIEW_ORDERS));
    if (user.isInRole(User.UserRole.CUSTOMER)) {
        mainMenu.addItem(Messages.menu_customerdetails.value(), e -> navigator
                .navigateTo(Konstanten.VAADIN_VIEW_CUSTOMER_DETAILS + "/" + user.getCustomerID()));
    }
    MenuBar.MenuItem userMenu = mainMenu.addItem(user.getLogin(), null);
    userMenu.setStyleName("align-right");
    userMenu.addItem(Messages.logout.value(), e -> {
        try {
            JaasAccessControl.logout();
            VaadinSession.getCurrent().close();
            Page.getCurrent().setLocation(Konstanten.VAADIN_LOGIN_PATH);
        } catch (ServletException ex) {
            Logger.getLogger(VaadinDemoUi.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    return mainMenu;
}

From source file:fi.jasoft.draganddrop.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    Panel showcase = new Panel();
    showcase.setSizeUndefined();//  w ww.  jav a 2s .  c  om

    navigator = new Navigator(this, showcase);

    for (DemoView view : views) {
        navigator.addView(view.getViewPath(), view);
    }

    // default
    openView(views.get(0));

    MenuBar demos = new MenuBar();
    demos.setStyleName(ValoTheme.MENUBAR_BORDERLESS);

    for (final DemoView view : views) {
        demos.addItem(view.getViewCaption(), new Command() {

            @Override
            public void menuSelected(MenuItem selectedItem) {
                openView(view);
            }
        });
    }

    VerticalLayout root = new VerticalLayout(demos, showcase);
    root.setSizeFull();
    root.setExpandRatio(showcase, 1);
    root.setComponentAlignment(showcase, Alignment.MIDDLE_CENTER);
    setContent(root);

    HorizontalLayout sourceWrapperLayout = new HorizontalLayout();
    Label caption = new Label("Source code for example");
    caption.setStyleName("source-caption");
    sourceWrapperLayout.addComponent(caption);

    Panel sourceWrapper = new Panel(codeLabel);
    sourceWrapper.setStyleName(ValoTheme.PANEL_BORDERLESS);
    sourceWrapper.setHeight(getPage().getBrowserWindowHeight() + "px");
    sourceWrapperLayout.addComponent(sourceWrapper);
    sourceWrapperLayout.setExpandRatio(sourceWrapper, 1);

    Toolbox sourceBox = new Toolbox();
    sourceBox.setOrientation(ORIENTATION.RIGHT_CENTER);
    sourceBox.setContent(sourceWrapperLayout);
    sourceBox.setOverflowSize(30);
    root.addComponent(sourceBox);
}

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();/* www.jav  a 2s .  co m*/
    //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");
    }
}