View Javadoc

1   package org.appfuse.webapp.client.application.utils.menu;
2   
3   import java.util.ArrayList;
4   import java.util.Arrays;
5   import java.util.Iterator;
6   import java.util.List;
7   
8   import org.appfuse.webapp.client.proxies.RoleProxy;
9   
10  import com.google.gwt.dom.client.Element;
11  import com.google.gwt.place.shared.Place;
12  
13  public class MenuItem implements Iterable<MenuItem> {
14  
15      private final String title;
16      private final Place place;
17      private final List<String> roles = new ArrayList<String>();
18      private MenuItem parent;
19      private final List<MenuItem> children = new ArrayList<MenuItem>();
20      private Element element;
21  
22      /**
23       * @param title
24       * @param children
25       */
26      public MenuItem(final String title, final String... roles) {
27          this(title, null, roles);
28      }
29  
30      public MenuItem(final String title, final Place place, final String... roles) {
31          super();
32          this.title = title;
33          this.place = place;
34          this.roles.addAll(Arrays.asList(roles));
35          if (this.roles.isEmpty()) {
36              this.roles.add(RoleProxy.ANONYMOUS);
37          }
38      }
39  
40      public String getTitle() {
41          return title;
42      }
43  
44      public Place getPlace() {
45          return place;
46      }
47  
48      public List<String> getRoles() {
49          return roles;
50      }
51  
52      public MenuItem getParent() {
53          return parent;
54      }
55  
56      public List<MenuItem> getChildren() {
57          return children;
58      }
59  
60      public Element getElement() {
61          return element;
62      }
63  
64      public void setElement(final Element widget) {
65          this.element = widget;
66      }
67  
68      public void add(final MenuItem item) {
69          item.parent = this;
70          children.add(item);
71      }
72  
73      @Override
74      public Iterator<MenuItem> iterator() {
75          return children.iterator();
76      }
77  
78      public boolean isLeafMenuItem() {
79          return children.isEmpty();
80      }
81  }