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.opennms.features.topology.app.internal.MenuBarBuilder.java

License:Open Source License

@SuppressWarnings("unchecked")
public MenuBar get() {
    MenuBar menuBar = new MenuBar();

    Set<Entry<String, Object>> sortedEntrySet = getSortedMenuItems();
    for (Entry<String, Object> entry : sortedEntrySet) {
        if (entry.getValue() instanceof Map<?, ?>) {
            MenuBar.MenuItem menuItem = menuBar.addItem(entry.getKey(), null);
            addMenuItems(menuItem, (Map<String, Object>) entry.getValue());
        } else {//from   ww w. ja v  a  2 s  .c  om
            menuBar.addItem(entry.getKey(), (Command) entry.getValue());
        }

    }
    return menuBar;
}

From source file:org.opennms.features.vaadin.topology.MenuBarBuilder.java

License:Open Source License

public MenuBar get() {
    MenuBar menuBar = new MenuBar();

    for (Entry<String, Object> entry : m_menuBar.entrySet()) {
        if (entry.getValue() instanceof Map) {
            MenuBar.MenuItem menuItem = menuBar.addItem(entry.getKey(), null);
            addMenuItems(menuItem, (Map<String, Object>) entry.getValue());
        } else {// w w  w  .ja  v a2 s.com
            menuBar.addItem(entry.getKey(), (Command) entry.getValue());
        }

    }
    return menuBar;
}

From source file:org.ripla.web.controllers.RiplaBody.java

License:Open Source License

private Component createMenubar(final HorizontalLayout inMenuBarMedium, final HorizontalLayout inMenuBarLayout,
        final Resource inSubMenuIcon) {
    final HorizontalLayout outComponent = inMenuBarMedium == null ? getDftMenuBarLayout() : inMenuBarMedium;

    menuBar = new MenuBar();
    menuBar.setAutoOpen(true);/*  w w w. j ava  2 s.  c  om*/
    menuBar.setStyleName("ripla-menu"); //$NON-NLS-1$
    createMenu(menuBar, inSubMenuIcon);
    if (inMenuBarLayout == null) {
        outComponent.addComponent(menuBar);
    } else {
        inMenuBarLayout.removeAllComponents();
        inMenuBarLayout.addComponent(menuBar);
    }

    return outComponent;
}

From source file:org.semanticsoft.vaaclipse.presentation.renderers.MenuRenderer.java

License:Open Source License

@Override
public void createWidget(MUIElement element, MElementContainer<MUIElement> parent) {
    if (!(element instanceof MMenu) || !element.isToBeRendered())
        return;//from w ww . ja  va  2 s.  c  om

    if (MWindow.class.isAssignableFrom(parent.getClass())) {
        MenuBar menuBar = new MenuBar();
        element.setWidget(menuBar);
    } else {
        String text = ((MUILabel) element).getLocalizedLabel();
        if (text != null)
            text = text.trim();
        else
            text = "NoName";
        text = text.replaceAll("&", "");

        MUIElement nextRenderableAndVisible = findNextRendarableAndVisible(element, parent);
        MenuItem item = null;
        if (parent.getWidget() instanceof MenuBar) {
            if (nextRenderableAndVisible == null)
                item = ((MenuBar) parent.getWidget()).addItem(text, null, null);
            else
                item = ((MenuBar) parent.getWidget()).addItemBefore(text, null, null,
                        (MenuItem) nextRenderableAndVisible.getWidget());
        } else if (parent.getWidget() instanceof MenuItem) {
            if (nextRenderableAndVisible == null)
                item = ((MenuItem) parent.getWidget()).addItem(text, null, null);
            else
                item = ((MenuItem) parent.getWidget()).addItemBefore(text, null, null,
                        (MenuItem) nextRenderableAndVisible.getWidget());
        }

        element.setWidget(item);
    }
}

From source file:org.tltv.gantt.demo.DemoUI.java

License:Apache License

private MenuBar controlsMenuBar() {
    MenuBar menu = new MenuBar();
    MenuItem editItem = menu.addItem("Edit", null);
    MenuItem formatItem = menu.addItem("Format", null);
    MenuItem viewItem = menu.addItem("View", null);

    MenuItem item = editItem.addItem("Enabled", new Command() {

        @Override//from w  w  w.  j  av  a 2s.  c  o  m
        public void menuSelected(MenuItem selectedItem) {
            gantt.setEnabled(!gantt.isEnabled());
            selectedItem.setChecked(gantt.isEnabled());
        }
    });
    item.setCheckable(true);
    item.setChecked(gantt.isEnabled());

    item = editItem.addItem("Read-only", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setReadOnly(!gantt.isReadOnly());
            selectedItem.setChecked(gantt.isReadOnly());
        }
    });
    item.setCheckable(true);
    item.setChecked(gantt.isReadOnly());

    item = formatItem.addItem("Set 'MMM' month format", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setTimelineMonthFormat("MMM");
        }
    });
    item = formatItem.addItem("Set 'MMMM' month format", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setTimelineMonthFormat("MMMM");
        }
    });
    item = formatItem.addItem("Set 'yyyy MMMM' month format", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setTimelineMonthFormat("yyyy MMMM");
        }
    });
    item = formatItem.addItem("Set 'dd.' week format", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setTimelineWeekFormat("dd.");
        }
    });
    item = formatItem.addItem("Set week number week format", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setTimelineWeekFormat(null);
        }
    });
    item = formatItem.addItem("Set 'dd. EEEE' day format for Hour resolution", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setTimelineDayFormat("dd. EEEE");
        }
    });

    item = viewItem.addItem("Show years", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setYearsVisible(!gantt.isYearsVisible());
            selectedItem.setChecked(gantt.isYearsVisible());
        }
    });
    item.setCheckable(true);
    item.setChecked(gantt.isYearsVisible());

    item = viewItem.addItem("Show months", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            gantt.setMonthsVisible(!gantt.isMonthsVisible());
            selectedItem.setChecked(gantt.isMonthsVisible());
        }
    });
    item.setCheckable(true);
    item.setChecked(gantt.isMonthsVisible());

    item = viewItem.addItem("Show Gantt with Table", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            getPage().setLocation("#table");
            getPage().reload();
        }
    });
    item = viewItem.addItem("Show Gantt with TreeTable", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            getPage().setLocation("#treetable");
            getPage().reload();
        }
    });
    item = viewItem.addItem("Show Gantt alone", new Command() {

        @Override
        public void menuSelected(MenuItem selectedItem) {
            getPage().setLocation("#");
            getPage().reload();
        }
    });

    return menu;
}

From source file:org.vaadin.addon.ewopener.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    EnhancedBrowserWindowOpener opener1 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true);
    Button button1 = new Button("Click me");
    button1.addClickListener(e -> {/*from   w  w w  .j  a  va2s .  c  om*/
        opener1.open(generateResource());
    });
    opener1.extend(button1);

    EnhancedBrowserWindowOpener opener4 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true);
    Button button4 = new Button("Nothing to open here");
    button4.addClickListener(e -> {
        opener4.open((Resource) null);
    });
    opener4.extend(button4);

    Button button2 = new Button("Click me");
    button2.addClickListener(e -> {
        EnhancedBrowserWindowOpener.extendOnce(button2).open(generateResource());
    });

    Button button3 = new Button("Click me");
    EnhancedBrowserWindowOpener opener3 = new EnhancedBrowserWindowOpener().popupBlockerWorkaround(true)
            .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(button3);
    button3.addClickListener(opener3::open);

    Link link = new Link("Click me", null);
    new EnhancedBrowserWindowOpener().clientSide(true)
            .withGeneratedContent("myFileName.txt", this::generateContent).doExtend(link);

    Link link2 = new Link("Click me", null);
    new EnhancedBrowserWindowOpener().clientSide(true)
            .withGeneratedContent("myFileName.txt", this::generateContent, resource -> {
                resource.setCacheTime(0);
                resource.setFilename("runtimeFileName-" + Instant.now().getEpochSecond() + ".txt");
            }).doExtend(link2);

    EnhancedBrowserWindowOpener opener5 = new EnhancedBrowserWindowOpener(
            new ClassResource(DemoUI.class, "static.txt"));
    CssLayout hiddenComponent = new MCssLayout().withWidth("0").withHeight("0");
    opener5.extend(hiddenComponent);
    CompletableFuture.runAsync(this::doSomeLongProcessing).thenRun(() -> getUI().access(opener5::open));

    table = new Table("Select items to download",
            new BeanItemContainer<>(DummyService.Person.class, DummyService.data()));
    table.setImmediate(true);
    table.setVisibleColumns("name", "age");
    table.setColumnHeaders("Name", "Age");
    table.setWidth("100%");
    table.setPageLength(20);
    table.setMultiSelectMode(MultiSelectMode.DEFAULT);
    table.setMultiSelect(true);
    table.setSelectable(true);

    final MyPopupContent popupContent = new MyPopupContent();
    Button popupButton = new Button("Open modal", event -> {
        Window window = new Window("Test", popupContent);
        window.setWidth(40, Sizeable.Unit.PERCENTAGE);
        window.setHeight(200, Sizeable.Unit.PIXELS);
        window.setModal(true);
        window.setDraggable(false);
        window.setResizable(false);
        window.center();
        getUI().addWindow(window);
    });

    MenuBar.Command cmd = selectedItem -> Notification.show("Item clicked",
            "Item is " + selectedItem.getDescription(), Notification.Type.TRAY_NOTIFICATION);
    MenuBar menuBar = new MenuBar();
    menuBar.setSizeFull();
    EnhancedBrowserWindowOpener opener6 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-serverside.txt", this::generateContent)
            .popupBlockerWorkaround(true);
    EnhancedBrowserWindowOpener opener7 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-clientside-1.txt", this::generateContent).clientSide(true);
    EnhancedBrowserWindowOpener opener8 = new EnhancedBrowserWindowOpener()
            .withGeneratedContent("menu-item-clientside-2.txt", this::generateContent).clientSide(true);
    MenuBar.MenuItem menuItem = menuBar.addItem("Download from Menu (Client side)", selectedItem -> {
        System.out.println("OK, Invoked");
    });
    MenuBar.MenuItem subMenu = menuBar.addItem("Sub menu", null);
    subMenu.addItem("Item 1", cmd);
    subMenu.addItem("Item 2", cmd);
    MenuBar.MenuItem subItem = subMenu.addItem("Download (client side)", cmd);
    MenuBar.MenuItem subItem2 = subMenu.addItem("Download (server side)", selectedItem -> opener6.open());
    opener7.doExtend(menuBar, menuItem);
    opener6.doExtend(menuBar, subItem2);
    opener8.doExtend(menuBar, subItem);

    // Show it in the middle of the screen
    final Layout layout = new MVerticalLayout(
            new MLabel("Enhanced Window Opener Demo").withStyleName(ValoTheme.LABEL_COLORED,
                    ValoTheme.LABEL_H1),
            new MHorizontalLayout().add(table, 1)
                    .add(new MCssLayout(menuBar, readMarkdown("code_menu.md").withFullWidth(),
                            new MVerticalLayout(readMarkdown("code1.md"), button1)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code2.md"), button2)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code7.md"), button3)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code5.md"), link)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code6.md"), link2)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code3.md"), button4)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code8.md"), popupButton)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false),
                            new MVerticalLayout(readMarkdown("code4.md"), hiddenComponent)
                                    .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false))
                                            .withFullWidth().withStyleName("demo-samples"),
                            5)
                    .withFullWidth()).withFullWidth().withMargin(true);

    setContent(layout);

}

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();// ww w .j  a  va  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.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);/*from   w  ww.j  a v  a  2 s.  c  o  m*/

    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:org.vaadin.tori.util.ComponentUtil.java

License:Apache License

public static MenuBar getDropdownMenu() {
    final MenuBar result = new MenuBar();
    MenuItem rootItem = result.addItem("", null);
    result.setMoreMenuItem(rootItem);/*from www .j  a  va  2 s  .c om*/
    result.addStyleName("dropdown");
    return result;
}

From source file:pt.ist.vaadinframework.ui.ApplicationWindow.java

License:Open Source License

public ApplicationWindow(String theme, Property applicationTitle, Property applicationSubtitle,
        Property copyright) {/*from   w  ww .j  a  va2  s  .co  m*/
    setTheme(theme);
    this.applicationTitle = applicationTitle;
    this.applicationSubtitle = applicationSubtitle;
    this.copyright = copyright;
    VerticalLayout main = new VerticalLayout();
    main.setWidth(90, UNITS_PERCENTAGE);
    main.setHeight(98, UNITS_PERCENTAGE);
    main.addStyleName("application-container");

    VerticalLayout header = new VerticalLayout();
    header.setMargin(true, true, false, true);
    header.setSpacing(true);
    main.addComponent(header);
    HorizontalLayout iconAndTitle = new HorizontalLayout();
    iconAndTitle.setSizeFull();
    iconAndTitle.setSpacing(true);
    header.addComponent(iconAndTitle);
    Embedded logo = new Embedded(null, new ThemeResource("../runo/icons/64/globe.png"));
    iconAndTitle.addComponent(logo);
    iconAndTitle.setComponentAlignment(logo, Alignment.MIDDLE_LEFT);

    VerticalLayout titles = new VerticalLayout();
    titles.setSpacing(true);
    iconAndTitle.addComponent(titles);
    iconAndTitle.setExpandRatio(titles, 0.8f);
    Label title = new Label(applicationTitle);
    title.addStyleName("application-title");
    titles.addComponent(title);
    Label subtitle = new Label(applicationSubtitle);
    subtitle.addStyleName("application-subtitle");
    titles.addComponent(subtitle);

    HorizontalLayout controls = new HorizontalLayout();
    controls.setSpacing(true);
    iconAndTitle.addComponent(controls);
    iconAndTitle.setComponentAlignment(controls, Alignment.TOP_RIGHT);
    Label user = new Label("ist148357");
    controls.addComponent(user);
    Link logout = new Link("logout", new ExternalResource("#"));
    controls.addComponent(logout);

    MenuBar menu = new MenuBar();
    menu.addStyleName("application-menu");
    header.addComponent(menu);
    MenuItem hello = menu.addItem("hello", null);
    hello.addItem("sdgjk", new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            getWindow().showNotification("skjhfgksjdfhglksdjh");
        }
    });
    MenuItem hello1 = menu.addItem("hello", null);
    hello1.addItem("sdgjk", new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            getWindow().showNotification("skjhfgksjdfhglksdjh");
        }
    });
    MenuItem hello2 = menu.addItem("hello", null);
    hello2.addItem("sdgjk", new Command() {
        @Override
        public void menuSelected(MenuItem selectedItem) {
            getWindow().showNotification("skjhfgksjdfhglksdjh");
        }
    });

    body = new VerticalLayout();
    body.setSizeFull();
    body.setMargin(true);
    body.addStyleName("application-body");
    main.addComponent(body);
    main.setExpandRatio(body, 1f);
    body.addComponent(createDefaultPageBody());

    VerticalLayout footer = new VerticalLayout();
    main.addComponent(footer);
    main.setComponentAlignment(footer, Alignment.MIDDLE_CENTER);
    Label copyrightLabel = new Label(copyright);
    copyrightLabel.setSizeUndefined();
    copyrightLabel.addStyleName("application-footer");
    footer.addComponent(copyrightLabel);
    footer.setComponentAlignment(copyrightLabel, Alignment.MIDDLE_CENTER);

    VerticalLayout outer = (VerticalLayout) getContent();
    outer.setSizeFull();
    outer.addComponent(main);
    outer.setComponentAlignment(main, Alignment.MIDDLE_CENTER);
}