private void addAuthorizedModulesToMenu(Layout menuHolder, String moduleKey) { Collection<Module> allowedModules = modules.values(); for (Iterator<Module> iterator = allowedModules.iterator(); iterator.hasNext(); ) { Module testModule = iterator.next(); if (!SecurityManager.getInstance().isUserAuthorizedToViewModule(testModule.getModuleKey())) { iterator.remove(); if (moduleKey != null && moduleKey.equals(testModule.getModuleKey())) { moduleKey = null; } } } // The module being requested is not visible to the current user. Set the default to // the first module (if one is available). if (moduleKey == null && allowedModules.size() > 0) { moduleKey = allowedModules.iterator().next().getModuleKey(); } for (Module module : allowedModules) { boolean selected = module.getModuleKey().equals(moduleKey); Label primaryMenuLabel = buildPrimaryMenuOption(module, selected); menuHolder.addMember(primaryMenuLabel); menuHolder.addMember(buildMenuSpacer()); moduleLabelMap.put(module.getModuleKey(), primaryMenuLabel); } }
public void onValueChange(ValueChangeEvent<String> event) { String token = event.getValue(); if (token != null) { String page = BLCLaunch.getSelectedPage(token); String moduleName = BLCLaunch.getSelectedModule(token); LinkedHashMap<String, String[]> pages = modules.get(moduleName).getPages(); if (SecurityManager.getInstance().isUserAuthorizedToViewModule(moduleName) && SecurityManager.getInstance().isUserAuthorizedToViewSection(pages.get(page)[0])) { if (moduleName != null && !moduleName.equals(BLCMain.currentModuleKey)) { BLCMain.setCurrentModuleKey(moduleName); selectPrimaryMenu(moduleName); buildSecondaryMenu(page, moduleName); AppController.getInstance().clearCurrentView(); } else { AppController.getInstance().clearCurrentView(); buildSecondaryMenu(page, moduleName); } } } }
private Layout buildSecondaryMenu(String selectedPage, String moduleKey) { secondaryMenu.removeMembers(secondaryMenu.getMembers()); LayoutSpacer sp2 = new LayoutSpacer(); sp2.setWidth(10); secondaryMenu.addMember(sp2); secondaryMenu.setHeight(40); // secondaryMenu.setBackgroundColor("#78a22F"); secondaryMenu.setBackgroundImage(GWT.getModuleBaseURL() + "admin/images/nav_sec_bg.png"); secondaryMenu.addMember(sp2); LinkedHashMap<String, String[]> pages = modules.get(moduleKey).getPages(); Collection<String> allowedPages = pages.keySet(); for (Iterator<String> iterator = allowedPages.iterator(); iterator.hasNext(); ) { String testPage = (String) iterator.next(); if (!SecurityManager.getInstance().isUserAuthorizedToViewSection(pages.get(testPage)[0])) { iterator.remove(); if (selectedPage != null && selectedPage.equals(testPage)) { selectedPage = null; } } } if (selectedPage == null && allowedPages.size() > 0) { selectedPage = (String) allowedPages.iterator().next(); } for (String page : allowedPages) { boolean selected = (page.equals(selectedPage)); secondaryMenu.addMember(buildSecondaryMenuOption(page, selected)); if (selectedPage == null) { selectedPage = page; } selected = false; } return secondaryMenu; }