View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.custom.navmenu;
20  
21  import javax.faces.model.SelectItem;
22  import java.util.List;
23  import java.util.Arrays;
24  import java.util.ArrayList;
25  
26  /**
27   * A node in a tree of menu items.<br>
28   *
29   * @author Thomas Spiegl (latest modification by $Author: grantsmith $)
30   * @version $Revision: 472638 $ $Date: 2006-11-08 15:54:13 -0500 (Wed, 08 Nov 2006) $
31   */
32  public class NavigationMenuItem extends SelectItem {
33      private static final long serialVersionUID = 2801735314476639024L;
34      private String _icon;
35      private String _action;
36      private String _actionListener;
37      private boolean _open;
38      private boolean _active;
39      boolean _split;
40      private boolean rendered = true;
41      private List _navigationMenuItems = null;
42      private String _target;
43      private String _disabledStyle;
44      private String _disabledStyleClass;
45      private String _externalLink;
46      private String _activeOnViewIds;
47  
48      // CONSTRUCTORS
49      public NavigationMenuItem()
50      {
51          super();
52      }
53  
54      public NavigationMenuItem(String label, String action) {
55          super(label, label);
56          _action = action;
57          _icon = null;
58          _split = false;
59      }
60  
61      public NavigationMenuItem(String label, String action, String icon, boolean split) {
62          super(label, label);
63          _action = action;
64          _icon = icon;
65          _split = split;
66      }
67  
68      public NavigationMenuItem(Object value,
69                                String label,
70                                String description,
71                                boolean disabled,
72                                String action,
73                                String icon,
74                                boolean split) {
75          super(value, label, description, disabled);
76          _action = action;
77          _icon = icon;
78          _split = split;
79      }
80  
81      public NavigationMenuItem(Object value,
82                                String label,
83                                String description,
84                                boolean disabled,
85                                boolean rendered,
86                                String action,
87                                String icon,
88                                boolean split) {
89          this(value, label, description, disabled, action, icon, split);
90          this.rendered = rendered;
91      }
92  
93      public NavigationMenuItem(Object value,
94                                String label,
95                                String description,
96                                boolean disabled,
97                                boolean rendered,
98                                String action,
99                                String icon,
100                               boolean split,
101                               String target) {
102         this(value, label, description, disabled, rendered, action, icon, split);
103         this.setTarget(target);
104     }
105 
106     public boolean isRendered() {
107         return rendered;
108     }
109 
110     public String getActiveOnViewIds() {
111         return _activeOnViewIds;
112     }
113 
114     public void setActiveOnViewIds(String activeOnViewIds) {
115         _activeOnViewIds = activeOnViewIds;
116     }
117 
118 
119     public String getAction() {
120         return _action;
121     }
122 
123     public void setAction(String action) {
124         _action = action;
125     }
126 
127     public boolean isSplit() {
128         return _split;
129     }
130 
131     public void setSplit(boolean split) {
132         _split = split;
133     }
134 
135     public String getIcon() {
136         return _icon;
137     }
138 
139     public void setIcon(String icon) {
140         _icon = icon;
141     }
142 
143     /**
144      * Relevant only for types of menus which can leave a menu in an "expanded"
145      * state across requests. Returns true if the menu is currently open
146      * (displaying its child items).
147      */
148     public boolean isOpen() {
149         return _open;
150     }
151 
152     public void setOpen(boolean open) {
153         _open = open;
154     }
155 
156     public boolean isActive() {
157         return _active;
158     }
159 
160     public void setActive(boolean active) {
161         _active = active;
162     }
163 
164     public String getActionListener() {
165         return _actionListener;
166     }
167 
168     public void setActionListener(String actionListener) {
169         _actionListener = actionListener;
170     }
171 
172     public String getTarget() {
173         return _target;
174     }
175 
176     public void setTarget(String target) {
177         _target = target;
178     }
179 
180     public String getDisabledStyle() {
181         return _disabledStyle;
182     }
183 
184     public void setDisabledStyle(String disabledStyle) {
185         _disabledStyle = disabledStyle;
186     }
187 
188     public String getDisabledStyleClass() {
189         return _disabledStyleClass;
190     }
191 
192     public void setDisabledStyleClass(String disabledStyleClass) {
193         _disabledStyleClass = disabledStyleClass;
194     }
195 
196     public String getExternalLink() {
197         return _externalLink;
198     }
199 
200     public void setExternalLink(String externalLink) {
201         _externalLink = externalLink;
202     }
203 
204     /**
205      * Get the array of child nodes of this menu item. If this node has
206      * no children then an empty array is returned. The array is a copy
207      * of the internal data of this object, so changes to the array will
208      * not affect the state of this object. The members of the array
209      * are the actual children of this object, however (the copy is not
210      * a "deep clone").
211      */
212     public NavigationMenuItem[] getNavigationMenuItems() {
213         if (_navigationMenuItems == null) {
214             return new NavigationMenuItem[0];
215         }
216         return (NavigationMenuItem[]) _navigationMenuItems.toArray(
217             new NavigationMenuItem[_navigationMenuItems.size()]);
218     }
219 
220     /**
221      * Set the child nodes of this menu item.
222      */
223     public void setNavigationMenuItems(NavigationMenuItem[] navigationMenuItems) {
224         _navigationMenuItems = Arrays.asList(navigationMenuItems);
225     }
226 
227     /**
228      * Set the child nodes of this menu item.
229      */
230     public void setNavigationMenuItems(List list) {
231         _navigationMenuItems = list;
232     }
233 
234     /**
235      * Add another node to the end of the list of child nodes of
236      * this menu item.
237      * <p/>
238      * Note that if setNavigationMenuItems(array) was called previously,
239      * then this method will throw an exception as the child list will
240      * be of fixed length.
241      */
242     public void add(NavigationMenuItem navigationMenuItem) {
243         if (_navigationMenuItems == null)
244             _navigationMenuItems = new ArrayList();
245         _navigationMenuItems.add(navigationMenuItem);
246     }
247 }