View Javadoc

1   /**
2    * 
3    */
4   package org.appfuse.webapp.client.application;
5   
6   import java.util.ArrayList;
7   import java.util.List;
8   
9   import org.appfuse.webapp.client.application.base.place.EntitySearchPlace;
10  import org.appfuse.webapp.client.application.utils.menu.MenuItem;
11  import org.appfuse.webapp.client.proxies.RoleProxy;
12  import org.appfuse.webapp.client.proxies.UserProxy;
13  import org.appfuse.webapp.client.ui.home.HomePlace;
14  import org.appfuse.webapp.client.ui.login.LoginPlace;
15  import org.appfuse.webapp.client.ui.logout.LogoutPlace;
16  import org.appfuse.webapp.client.ui.reloadOptions.ReloadOptionsPlace;
17  import org.appfuse.webapp.client.ui.upload.FileUploadPlace;
18  import org.appfuse.webapp.client.ui.users.active.ActiveUsersPlace;
19  import org.appfuse.webapp.client.ui.users.editProfile.EditProfilePlace;
20  
21  import com.google.gwt.core.client.GWT;
22  
23  /**
24   * @author ivangsa
25   *
26   */
27  public class ApplicationMenu {
28  
29      private static final ApplicationResources i18n = GWT.create(ApplicationResources.class);
30  
31      private final MenuItem rootMenu = new MenuItem(null);
32      private final MenuItem adminMenu = new MenuItem(i18n.menu_admin(), RoleProxy.ROLE_ADMIN);
33  
34      private List<MenuItem> allMenuItems;
35  
36      {
37          rootMenu.add(new MenuItem(i18n.home_title(), new HomePlace(), RoleProxy.ROLE_USER, RoleProxy.ROLE_ADMIN));
38          rootMenu.add(new MenuItem(i18n.menu_user(), new EditProfilePlace(), RoleProxy.ROLE_USER, RoleProxy.ROLE_ADMIN));
39  
40          rootMenu.add(adminMenu);
41          adminMenu.add(new MenuItem(i18n.menu_admin_users(), new EntitySearchPlace(UserProxy.class), RoleProxy.ROLE_ADMIN));
42          adminMenu.add(new MenuItem(i18n.home_activeUsers(), new ActiveUsersPlace(), RoleProxy.ROLE_ADMIN));
43          adminMenu.add(new MenuItem(i18n.menu_admin_reload(), new ReloadOptionsPlace(), RoleProxy.ROLE_ADMIN));
44          adminMenu.add(new MenuItem(i18n.menu_selectFile(), new FileUploadPlace(), RoleProxy.ROLE_ADMIN));
45  
46          rootMenu.add(new MenuItem(i18n.login_title(), new LoginPlace(), RoleProxy.ANONYMOUS));
47          rootMenu.add(new MenuItem(i18n.user_logout(), new LogoutPlace(), RoleProxy.AUTHENTICATED));
48      }
49  
50      public MenuItem getRootMenu() {
51          return rootMenu;
52      }
53  
54      public List<MenuItem> asList() {
55          if (allMenuItems == null) {
56              allMenuItems = new ArrayList<MenuItem>();
57              appendChildrenToList(allMenuItems, rootMenu);
58          }
59          return allMenuItems;
60      }
61  
62      protected void appendChildrenToList(final List<MenuItem> menuItems, final MenuItem menuItem) {
63          for (final MenuItem childItem : menuItem) {
64              menuItems.add(childItem);
65              appendChildrenToList(menuItems, childItem);
66          }
67      }
68  }