Java tutorial
package net.meddeb.md.core.presentation; /*-------------------------------------------------------------------- mdCore module. The boot module for Merged directory system. Copyright (C) 2015, Abdelhamid MEDDEB (abdelhamid@meddeb.net) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. ---------------------------------------------------------------------*/ import java.util.HashMap; import java.util.Map; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Cookies; import com.google.gwt.user.client.ui.MenuBar; import com.google.gwt.user.client.ui.MenuItem; import com.google.gwt.user.client.ui.RootPanel; public class MenuManager { private MainMsg mainMsg = GWT.create(MainMsg.class); private MenuLauncher menuLauncher = null; private final MenuBar menu = new MenuBar(); private final MenuBar controlMenu = new MenuBar(true); private final MenuBar helpMenu = new MenuBar(true); private final Map<MDCoreMenu, MenuItem> menuList = new HashMap<MDCoreMenu, MenuItem>(); private boolean isMenuaActive(MDCoreMenu menuKey) { return menuKey == MDCoreMenu.MESSAGING; } private void initMenuStatus() { for (Map.Entry<MDCoreMenu, MenuItem> entry : menuList.entrySet()) { MDCoreMenu menuKey = entry.getKey(); if ((menuKey != MDCoreMenu.ROOTCONNECT) && (menuKey != MDCoreMenu.HELPABOUT) && (menuKey != MDCoreMenu.HELPLINK)) entry.getValue().addStyleName("disabled"); } } public void setLoggedoutStatus() { for (Map.Entry<MDCoreMenu, MenuItem> entry : menuList.entrySet()) { MDCoreMenu menuKey = entry.getKey(); if ((menuKey != MDCoreMenu.HELPABOUT) && (menuKey != MDCoreMenu.HELPLINK)) if (isMenuaActive(menuKey)) entry.getValue().addStyleName("disabled"); if (menuKey == MDCoreMenu.ROOTCONNECT) entry.getValue().removeStyleName("disabled"); } } public void setRootLoggedinStatus() { for (Map.Entry<MDCoreMenu, MenuItem> entry : menuList.entrySet()) { MDCoreMenu menuKey = entry.getKey(); if (isMenuaActive(menuKey)) entry.getValue().removeStyleName("disabled"); if (menuKey == MDCoreMenu.ROOTCONNECT) entry.getValue().addStyleName("disabled"); } } private MDCoreMenu getCurrentmenu() { String strMenu = Cookies.getCookie(MenuLauncher.MENUTAG); MDCoreMenu rslt = MDCoreMenu.fromName(strMenu); return rslt; } private void initMenu() { menu.setAutoOpen(true); menu.setAnimationEnabled(true); menu.setStyleName("gwt-MenuBar-local"); // Create the control menu controlMenu.setAnimationEnabled(true); final MenuItem mnuFMessaging = new MenuItem(mainMsg.messaging(), new Command() { @Override public void execute() { menuLauncher.launch(MDCoreMenu.MESSAGING); } }); final MenuItem mnuFRootConnect = new MenuItem(mainMsg.rootConnect(), new Command() { @Override public void execute() { menuLauncher.launch(MDCoreMenu.ROOTCONNECT); } }); controlMenu.addItem(mnuFMessaging); controlMenu.addSeparator(); controlMenu.addItem(mnuFRootConnect); menuList.put(MDCoreMenu.MESSAGING, mnuFMessaging); menuList.put(MDCoreMenu.ROOTCONNECT, mnuFRootConnect); // Create the help menu helpMenu.setAnimationEnabled(true); final MenuItem mnuHLink = new MenuItem(mainMsg.helpLink(), new Command() { @Override public void execute() { menuLauncher.launch(MDCoreMenu.HELPLINK); } }); final MenuItem mnuHAbout = new MenuItem(mainMsg.helpAbout(), new Command() { @Override public void execute() { menuLauncher.launch(MDCoreMenu.HELPABOUT); } }); helpMenu.addItem(mnuHLink); helpMenu.addItem(mnuHAbout); menuList.put(MDCoreMenu.HELPLINK, mnuHLink); menuList.put(MDCoreMenu.HELPABOUT, mnuHAbout); setLoggedoutStatus(); menu.addItem(mainMsg.control(), controlMenu); menu.addSeparator(); menu.addItem(mainMsg.help(), helpMenu); RootPanel.get("menu").clear(); RootPanel.get("menu").add(menu); } public MenuManager() { initMenu(); initMenuStatus(); menuLauncher = new MenuLauncher(this); } public void launchCurrent() { menuLauncher.initConnectStatus(); MDCoreMenu menu = getCurrentmenu(); menuLauncher.launch(menu, true); } }