List of usage examples for com.vaadin.ui MenuBar.Command MenuBar.Command
MenuBar.Command
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();//from w w w. j av a 2s .c o 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"); } }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.MenuNavigationViewlet.java
License:Apache License
private void processRootPage(final NavigationVersion navigationVersion, final MenuBar menuBar, final String pageName) { final ViewVersion pageVersion = getSite().getCurrentViewVersion(pageName); if (pageVersion == null) { throw new SiteException("Unknown page: " + pageName); }/*w w w . java2s. c om*/ if (pageVersion.getViewerRoles().length > 0) { boolean roleMatch = false; for (final String role : pageVersion.getViewerRoles()) { if (getSite().getSecurityProvider().getRoles().contains(role)) { roleMatch = true; break; } } if (!roleMatch) { return; } } final String localizedPageName = pageVersion.isDynamic() ? pageName : getSite().localize("page-link-" + pageName); final Resource iconResource = pageVersion.isDynamic() ? navigationVersion.hasChildPages(pageName) ? getSite().getIcon("page-icon-folder") : getSite().getIcon("page-icon-page") : getSite().getIcon("page-icon-" + pageName); final MenuBar.MenuItem menuItem = menuBar.addItem(localizedPageName, iconResource, navigationVersion.hasChildPages(pageName) ? null : new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { UI.getCurrent().getNavigator().navigateTo(pageName); } }); menuItem.setStyleName("navigation-" + pageName); if (navigationVersion.hasChildPages(pageName)) { for (final String childPage : navigationVersion.getChildPages(pageName)) { processChildPage(navigationVersion, menuItem, childPage); } } }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.MenuNavigationViewlet.java
License:Apache License
private void processChildPage(final NavigationVersion navigationVersion, final MenuBar.MenuItem parentItem, final String pageName) { final ViewVersion pageVersion = getSite().getCurrentViewVersion(pageName); if (pageVersion == null) { throw new SiteException("Unknown page: " + pageName); }/*w w w . jav a 2 s . c o m*/ if (pageVersion.getViewerRoles().length > 0) { boolean roleMatch = false; for (final String role : pageVersion.getViewerRoles()) { if (getSite().getSecurityProvider().getRoles().contains(role)) { roleMatch = true; break; } } if (!roleMatch) { return; } } final String localizedPageName = pageVersion.isDynamic() ? pageName : getSite().localize("page-link-" + pageName); final Resource iconResource = pageVersion.isDynamic() ? navigationVersion.hasChildPages(pageName) ? getSite().getIcon("page-icon-folder") : getSite().getIcon("page-icon-page") : getSite().getIcon("page-icon-" + pageName); final MenuBar.MenuItem menuItem = parentItem.addItem(localizedPageName, iconResource, navigationVersion.hasChildPages(pageName) ? null : new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { UI.getCurrent().getNavigator().navigateTo(pageName); } }); menuItem.setStyleName("navigation-" + pageName); menuItem.setEnabled(true); if (navigationVersion.hasChildPages(pageName)) { for (final String childPage : navigationVersion.getChildPages(pageName)) { processChildPage(navigationVersion, menuItem, childPage); } } }