List of usage examples for com.vaadin.ui MenuBar.MenuItem addItem
public MenuBar.MenuItem addItem(String caption, MenuBar.Command command)
From source file:nz.co.senanque.perspectiveslibrary.MenuCloner.java
License:Apache License
private static void merge(MenuBar.MenuItem target, MenuBar.MenuItem source, List<MenuBar.MenuItem> added) { if (source.hasChildren()) { List<MenuBar.MenuItem> targetItems = target.getChildren(); for (MenuBar.MenuItem sourceItem : source.getChildren()) { if (sourceItem.isSeparator()) { target.addSeparator();//from w w w . ja va 2 s.c om } else { MenuBar.MenuItem targetItem = findItem(sourceItem.getText(), targetItems); if (targetItem == null) { try { int sizeOfTarget = target.getChildren().size(); if (sizeOfTarget > 0) { targetItem = target.addItemBefore(sourceItem.getText(), null, sourceItem.getCommand(), target.getChildren().get(sizeOfTarget - 1)); } } 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);//from w w w. java 2 s .co m 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.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 w w.j av a2 s . co 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.balisunrise.vaadin.components.header.ModuleButton.java
private void init() { setStyleName("b-module-button"); setHeight("100%"); button = new MenuBar(); setCompositionRoot(button);//ww w .j a v a2 s . c o m MenuBar.MenuItem modules = button.addItem("", null); //modules.setIcon(new ThemeResource("img/modules.png")); modules.setDescription("Clique e selecione um mdulo"); modules.addItem("Pessoas", c -> { Notification.show("Modulo: " + c.getText(), Notification.Type.TRAY_NOTIFICATION); }); modules.addItem("Vendas", c -> { Notification.show("Modulo: " + c.getText(), Notification.Type.TRAY_NOTIFICATION); }); modules.addItem("Financeiro", c -> { Notification.show("Modulo: " + c.getText(), Notification.Type.TRAY_NOTIFICATION); }); modules.addItem("Estoque", c -> { Notification.show("Modulo: " + c.getText(), Notification.Type.TRAY_NOTIFICATION); }); modules.addItem("Compras", c -> { Notification.show("Modulo: " + c.getText(), Notification.Type.TRAY_NOTIFICATION); }); }
From source file:org.balisunrise.vaadin.components.header.ModuleMenu.java
private void init() { setHeight("100%"); setWidthUndefined();/*from w w w . j a va2 s.com*/ menuBar = new MenuBar(); menuBar.setStyleName("b-module-menu"); setCompositionRoot(menuBar); MenuBar.MenuItem item; item = menuBar.addItem("Menu 1", new ItemCommand()); item.setStyleName("b-module-menu-item"); item.setDescription("1 Item do menu"); MenuBar.MenuItem subMenu; subMenu = menuBar.addItem("Sub Menus 1", null); subMenu.setStyleName("b-module-menu-item"); item = subMenu.addItem("Menu 2", new ItemCommand()); item.setStyleName("b-module-menu-item"); item.setDescription("2 Item do menu"); item = subMenu.addItem("Menu 3", new ItemCommand()); item.setStyleName("b-module-menu-item"); item.setDescription("3 Item do menu"); subMenu = menuBar.addItem("Sub Menus 2", null); subMenu.setStyleName("b-module-menu-item"); MenuBar.MenuItem subMenu2; subMenu2 = subMenu.addItem("Sub Sub Menu 1", null); subMenu2.setStyleName("b-module-menu-item"); item = subMenu2.addItem("Menu 4", new ItemCommand()); item.setStyleName("b-module-menu-item"); item.setDescription("4 Item do menu"); item = subMenu2.addItem("Menu 5", new ItemCommand()); item.setStyleName("b-module-menu-item"); item.setDescription("5 Item do menu"); subMenu2 = subMenu.addItem("Sub Sub Menu 2", null); subMenu2.setStyleName("b-module-menu-item"); item = subMenu2.addItem("Menu 6", new ItemCommand()); item.setStyleName("b-module-menu-item"); item.setDescription("6 Item do menu"); item = subMenu2.addItem("Menu 7", new ItemCommand()); item.setStyleName("b-module-menu-item"); item.setDescription("7 Item do menu"); }
From source file:org.bubblecloud.ilves.site.view.valo.DefaultValoView.java
License:Apache License
private CssLayout buildMenu() { final HorizontalLayout topLayout = new HorizontalLayout(); topLayout.setWidth("100%"); topLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT); topLayout.addStyleName("valo-menu-title"); menu.addComponent(topLayout);/*ww w . j a v a2 s . c om*/ final Button showMenu = new Button("Menu", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (menu.getStyleName().contains("valo-menu-visible")) { menu.removeStyleName("valo-menu-visible"); } else { menu.addStyleName("valo-menu-visible"); } } }); showMenu.addStyleName(ValoTheme.BUTTON_PRIMARY); showMenu.addStyleName(ValoTheme.BUTTON_SMALL); showMenu.addStyleName("valo-menu-toggle"); showMenu.setIcon(FontAwesome.LIST); menu.addComponent(showMenu); final Label title = new Label("<h3>" + Site.getCurrent().localize(getViewVersion().getTitle()) + "</h3>", ContentMode.HTML); title.setSizeUndefined(); topLayout.addComponent(title); topLayout.setExpandRatio(title, 1); final MenuBar settings = new MenuBar(); settings.addStyleName("user-menu"); final String user = Site.getCurrent().getSecurityProvider().getUser(); final String userMenuCaption; final Resource userMenuIcon; if (user == null) { userMenuCaption = Site.getCurrent().localize("page-link-login"); userMenuIcon = new ThemeResource("ilves_logo.png"); } else { final URL gravatarUrl = GravatarUtil.getGravatarUrl(user, 64); userMenuIcon = new ExternalResource(gravatarUrl); userMenuCaption = ((SecurityProviderSessionImpl) Site.getCurrent().getSecurityProvider()) .getUserFromSession().getFirstName(); } final MenuBar.MenuItem settingsItem = settings.addItem(userMenuCaption, userMenuIcon, null); if (user != null) { settingsItem.addItem(Site.getCurrent().localize("page-link-account"), new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { UI.getCurrent().getNavigator().navigateTo("account"); } }); settingsItem.addSeparator(); settingsItem.addItem(Site.getCurrent().localize("button-logout"), new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { LoginService.logout(Site.getCurrent().getSiteContext()); final Company company = Site.getCurrent().getSiteContext().getObject(Company.class); getUI().getPage().setLocation(company.getUrl()); getSession().getSession().invalidate(); getSession().close(); } }); } else { settingsItem.addItem(Site.getCurrent().localize("page-link-login"), new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { UI.getCurrent().getNavigator().navigateTo("login"); } }); } menu.addComponent(settings); menuItemsLayout.setPrimaryStyleName("valo-menuitems"); menu.addComponent(menuItemsLayout); final Site site = Site.getCurrent(); final NavigationVersion navigationVersion = site.getCurrentNavigationVersion(); for (final String pageName : navigationVersion.getRootPages()) { final ViewVersion pageVersion = site.getCurrentViewVersion(pageName); if (pageVersion == null) { throw new SiteException("Unknown page: " + pageName); } if (pageVersion.getViewerRoles().length > 0) { boolean roleMatch = false; for (final String role : pageVersion.getViewerRoles()) { if (site.getSecurityProvider().getRoles().contains(role)) { roleMatch = true; break; } } if (!roleMatch) { continue; } } if (navigationVersion.hasChildPages(pageName)) { final String localizedPageName = pageVersion.isDynamic() ? pageName : site.localize("page-link-" + pageName); final Label label = new Label(localizedPageName, ContentMode.HTML); label.setPrimaryStyleName("valo-menu-subtitle"); label.addStyleName("h4"); label.setSizeUndefined(); menuItemsLayout.addComponent(label); final List<String> childPages = navigationVersion.getChildPages(pageName); for (final String childPage : childPages) { addMenuLink(navigationVersion, childPage); } label.setValue( label.getValue() + " <span class=\"valo-menu-badge\">" + childPages.size() + "</span>"); } else { addMenuLink(navigationVersion, pageName); } } return menu; }
From source file:org.jpos.qi.Header.java
License:Open Source License
private void addMenuItem(MenuBar.MenuItem mb, Element e) { if ("menu".equals(e.getName())) { String perm = e.getAttributeValue("perm"); boolean allowed = perm == null || QI.getQI().getUser().hasPermission(perm); if (allowed) { MenuBar.MenuItem mi = mb.addItem(e.getAttributeValue("name"), selectedItem -> menuItemSelected(selectedItem, e)); decorate(mi, e);//from ww w . j av a 2 s . c o m for (Element child : e.getChildren()) { addMenuItem(mi, child); } } } else if ("separator".equals(e.getName())) { mb.addSeparator(); } }
From source file:org.kani.Application.java
License:Apache License
private MenuBar getMenu() { MenuBar menubar = new MenuBar(); menubar.setWidth("100%"); actionMenu = menubar.addItem("Action", null); actionMenu.addItem("Built-in Action...", new Command() { public void menuSelected(MenuItem selectedItem) { main.showNotification("Built-in Action executed!"); }//from w ww .ja v a2s . c om }); final MenuBar.MenuItem viewMenu = menubar.addItem("Help", null); viewMenu.addItem("About...", new Command() { public void menuSelected(MenuItem selectedItem) { main.addWindow(getAboutDialog()); } }); return menubar; }
From source file:org.opennms.features.topology.app.internal.menu.MenuBuilder.java
License:Open Source License
private void addItems(MenuBar.MenuItem currentMenuItem, MenuItem currentParent, List<VertexRef> targets, OperationContext operationContext, List<Runnable> hooks) { if (currentMenuItem != null) { // Now add children List<MenuItem> childItems = new ArrayList<>(currentParent.getChildren()); Collections.sort(childItems); String prevGroup = null;// w ww . j a va 2s. co m MenuBar.MenuItem prevMenuItem = null; for (MenuItem eachChild : childItems) { // add Separators between groups if the previous group changed and we added an element // (otherwise we may end up having multiple separators) String currentGroup = getGroupForLabel(eachChild.getLabel(), getSubmenuOrderList(currentParent)); if (prevGroup != null && prevMenuItem != null && !prevGroup.equals(currentGroup)) { currentMenuItem.addSeparator(); } prevGroup = currentGroup; prevMenuItem = addItem( () -> currentMenuItem.addItem(removeLabelProperties(eachChild.getLabel()), null), eachChild, targets, operationContext, hooks); // add children addItems(prevMenuItem, eachChild, targets, operationContext, hooks); } } }
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 -> {// w w w . ja va2 s . c o m 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); }