List of usage examples for com.vaadin.ui MenuBar addItem
public MenuBar.MenuItem addItem(String caption, MenuBar.Command command)
From source file:org.opennms.features.topology.app.internal.menu.MenuBuilder.java
License:Open Source License
public void apply(MenuBar rootMenu, List<VertexRef> targets, OperationContext operationContext, Runnable... hooks) {//from w ww .j av a 2 s .c o m final List<Runnable> hookList = hooks == null ? Collections.emptyList() : Arrays.asList(hooks); // Determine the order of the items in the menu determineAndApplyOrder(); // Start building menubar List<MenuItem> rootItems = new ArrayList<>(m_menuBar); Collections.sort(rootItems); for (MenuItem eachRootElement : rootItems) { MenuBar.MenuItem menuItem = addItem( () -> rootMenu.addItem(removeLabelProperties(eachRootElement.getLabel()), null), eachRootElement, targets, operationContext, hookList); // Add children addItems(menuItem, eachRootElement, targets, operationContext, hookList); } }
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 . jav a 2 s .co m 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 {//from w w w . j a v a 2 s . c o m menuBar.addItem(entry.getKey(), (Command) entry.getValue()); } } return menuBar; }
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 ww. j ava 2 s . 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 www .j a va 2 s . 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.tori.util.ComponentUtil.java
License:Apache License
public static MenuBar getDropdownMenu() { final MenuBar result = new MenuBar(); MenuItem rootItem = result.addItem("", null); result.setMoreMenuItem(rootItem);// w ww . j av a 2 s. c o m 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 ww w .j av a 2 s. c o 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); }
From source file:rs.pupin.jpo.esta_ld.DSDRepoComponent.java
public DSDRepoComponent(Repository repository, String dataGraph, String repoGraph) { this.repository = repository; this.dataGraph = dataGraph; this.repoGraph = repoGraph; initializeRepoGraph();/*from w w w . ja v a2 s. com*/ dcRepo = new SparqlDCRepository(repository); graph = new SparqlDCGraph(repository, dataGraph); VerticalLayout rootLayout = new VerticalLayout(); rootLayout.setWidth("100%"); rootLayout.setSpacing(true); mainLayout = new VerticalLayout(); mainLayout.setWidth("100%"); mainLayout.setSpacing(true); HorizontalLayout menuLayout = new HorizontalLayout(); menuLayout.setSpacing(true); menuLayout.setWidth("100%"); rootLayout.addComponent(menuLayout); final MenuBar menu = new MenuBar(); menu.addStyleName("dsd"); cmdFindDSD = new MenuBar.Command() { public void menuSelected(MenuBar.MenuItem selectedItem) { for (MenuBar.MenuItem item : menu.getItems()) { if (item == selectedItem) { if (!item.getStyleName().contains("selected")) { if (ds != null) item.setStyleName("selected"); findDSDs(); } } else item.setStyleName("bleja"); } } }; menu.addItem("Find Suitable DSDs", cmdFindDSD).setStyleName("bleja"); cmdCreateDSD = new MenuBar.Command() { public void menuSelected(MenuBar.MenuItem selectedItem) { for (MenuBar.MenuItem item : menu.getItems()) { if (item == selectedItem) { if (!item.getStyleName().contains("selected")) { if (ds != null) item.setStyleName("selected"); createDSD(); } } else item.setStyleName("bleja"); } } }; menu.addItem("Create DSD", cmdCreateDSD).setStyleName("bleja"); cmdStoreDSD = new MenuBar.Command() { public void menuSelected(MenuBar.MenuItem selectedItem) { for (MenuBar.MenuItem item : menu.getItems()) { if (item == selectedItem) { if (!item.getStyleName().contains("selected")) { if (ds != null) item.setStyleName("selected"); storeDSD(); } } else item.setStyleName("bleja"); } } }; menu.addItem("Store DSD", cmdStoreDSD).setStyleName("bleja"); menuLayout.addComponent(menu); Label spaceLbl = new Label(""); menuLayout.addComponent(spaceLbl); menuLayout.setExpandRatio(spaceLbl, 2.0f); Label lbl = new Label("Choose dataset: "); lbl.setSizeUndefined(); menuLayout.addComponent(lbl); selectDataSet = new ComboBox(null, graph.getDataSets()); selectDataSet.setImmediate(true); selectDataSet.setNewItemsAllowed(false); selectDataSet.setNullSelectionAllowed(false); selectDataSet.setWidth("300px"); selectDataSet.addListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent event) { ds = (DataSet) event.getProperty().getValue(); } }); menuLayout.addComponent(selectDataSet); rootLayout.addComponent(new Label("<hr/>", Label.CONTENT_XHTML)); rootLayout.addComponent(mainLayout); setCompositionRoot(rootLayout); }
From source file:ru.codeinside.gses.webui.manager.ManagerWorkplace.java
License:Mozilla Public License
public ManagerWorkplace() { setSizeFull();//from ww w . j a v a 2 s . com servicePanel = createServicePanel(); procedurePanel = createProcedurePanel1(); directoryPanel = DirectoryPanel.createDirectoryPanel(); final MenuBar menu = new MenuBar(); menu.setWidth("100%"); menu.addStyleName("submenu"); MenuBar.MenuItem servicesItem = menu.addItem("?", new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { chooseTab(selectedItem, menu, servicePanel, procedurePanel, directoryPanel); } }); MenuBar.MenuItem administrativeProceduresItem = menu .addItem("?? ", new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { chooseTab(selectedItem, menu, procedurePanel, servicePanel, directoryPanel); activateApInterface(); } }); menu.addItem("? ", new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { chooseTab(selectedItem, menu, procedurePanel, servicePanel, directoryPanel); activateMpInterface(); } }); menu.addItem(" ?", new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { chooseTab(selectedItem, menu, directoryPanel, servicePanel, procedurePanel); activateMpInterface(); } }); addComponent(menu); setExpandRatio(menu, 0.01f); administrativeProceduresItem.getCommand().menuSelected(administrativeProceduresItem); }