001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/velocity/tags/sakai_2-4-1/tool/src/java/org/sakaiproject/cheftool/menu/MenuImpl.java $
003: * $Id: MenuImpl.java 7247 2006-03-29 21:09:51Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.cheftool.menu;
021:
022: import java.util.List;
023: import java.util.Vector;
024:
025: import org.sakaiproject.cheftool.RunData;
026: import org.sakaiproject.cheftool.VelocityPortlet;
027: import org.sakaiproject.cheftool.api.Menu;
028: import org.sakaiproject.cheftool.api.MenuItem;
029:
030: /**
031: * <p>
032: * Menu is an ordered list of MenuItems.
033: * </p>
034: */
035: public class MenuImpl implements Menu {
036: /** The menu's title. */
037: protected String m_title = null;
038:
039: /** The menu's icon. */
040: protected String m_icon = null;
041:
042: /** The menu's enabled flag. */
043: protected boolean m_enabled = true;
044:
045: /** The MenuItems, in order. */
046: protected List m_items = new Vector();
047:
048: /** The form name string for the entry. */
049: protected String m_form = null;
050:
051: /** The base url for any action taken after clicking on the menu. */
052: protected String m_linkBaseUrl = null;
053:
054: /** The base url for any resources (images, etc.) required by the menu. */
055: protected String m_resourceBaseUrl = null;
056:
057: /** The menu's flag for whether to display disabled entries */
058: protected boolean m_showDisabled = false;
059:
060: // CHEF 1.x support
061: public final static String CONTEXT_ACTION = "action";
062:
063: public final static String CONTEXT_MENU = "menu";
064:
065: public final static String STATE_MENU = "menu";
066:
067: public MenuImpl(VelocityPortlet p, RunData r, String action) {
068: super ();
069: }
070:
071: // CHEF 1.x support
072:
073: /**
074: * Construct a menu (good for sub-menus).
075: */
076: public MenuImpl(String title, String icon, boolean enabled) {
077: m_title = title;
078: m_icon = icon;
079: m_enabled = enabled;
080:
081: } // Menu
082:
083: /**
084: * Construct a menu (good for sub-menus).
085: */
086: public MenuImpl(String title, String icon, boolean enabled,
087: String form) {
088: m_title = title;
089: m_icon = icon;
090: m_enabled = enabled;
091: m_form = form;
092:
093: } // Menu
094:
095: /**
096: * Construct a menu (good for a menu bar).
097: */
098: public MenuImpl() {
099: } // Menu
100:
101: /**
102: * Add a menu item to the bar.
103: *
104: * @param entry
105: * The menu item to add.
106: * @return the item.
107: */
108: public MenuItem add(MenuItem item) {
109: m_items.add(item);
110:
111: return item;
112:
113: } // add
114:
115: /**
116: * Clear the menu of all items.
117: */
118: public void clear() {
119: m_items.clear();
120:
121: } // clear
122:
123: /**
124: * Does this item act as a container for other items?
125: *
126: * @return true if this MenuItem is a container for other items, false if not.
127: */
128: public boolean getIsContainer() {
129: return true;
130:
131: } // getIsContainer
132:
133: /**
134: * Is this item a divider ?
135: *
136: * @return true if this MenuItem is a divider, false if not.
137: */
138: public boolean getIsDivider() {
139: return false;
140:
141: } // getIsDivider
142:
143: /**
144: * Access the display title for the item.
145: *
146: * @return The display title for the item.
147: */
148: public String getTitle() {
149: return ((m_title == null) ? "" : m_title);
150:
151: } // getTitle
152:
153: /**
154: * Access the icon name for the item (or null if no icon).
155: *
156: * @return The icon name for the item (or null if no icon).
157: */
158: public String getIcon() {
159: return m_icon;
160:
161: } // getIcon
162:
163: /**
164: * Access the enabled flag for the item.
165: *
166: * @return True if the item is enabled, false if not.
167: */
168: public boolean getIsEnabled() {
169: return m_enabled;
170:
171: } // getIsEnabled
172:
173: /**
174: * Access the action string for this item; what to do when the user clicks. Note: if getIsMenu(), there will not be an action string (will return "").
175: *
176: * @return The action string for this item.
177: */
178: public String getAction() {
179: return "";
180:
181: } // getAction
182:
183: /**
184: * Access the full URL string for this item; what to do when the user clicks. Note: this if defined overrides getAction() which should be "". Note: if getIsMenu(), there will not be a URL string (will return "").
185: *
186: * @return The full URL string for this item.
187: */
188: public String getUrl() {
189: return "";
190:
191: } // getUrl
192:
193: /**
194: * Access the form name whose values will be used when this item is selected.
195: *
196: * @return The form name whose values will be used when this item is selected.
197: */
198: public String getForm() {
199: return m_form;
200:
201: } // getForm
202:
203: /**
204: * Access the sub-items of the item. Note: if !isContainer(), there will be no sub-items (will return EmptyIterator).
205: *
206: * @return The sub-items of the item.
207: */
208: public List getItems() {
209: return m_items;
210:
211: } // getItems
212:
213: /**
214: * Count the sub-items of the item. Note: if !isContainer(), the count is 0.
215: *
216: * @return The count of sub-items of the item.
217: */
218: public int size() {
219: return m_items.size();
220:
221: } // size
222:
223: /**
224: * Check if there are any sub-items. Note: if !isContainer(), this is empty.
225: *
226: * @return true of there are no sub-items, false if there are.
227: */
228: public boolean isEmpty() {
229: return m_items.isEmpty();
230:
231: } // isEmpty
232:
233: /**
234: * Access one sub-items of the item. Note: if !isContainer(), there will be no sub-items (will return null).
235: *
236: * @param index
237: * The index position (0 based) for the sub-item to get.
238: * @return The sub-item of the item.
239: */
240: public MenuItem getItem(int index) {
241: try {
242: return (MenuItem) m_items.get(index);
243: } catch (Exception e) {
244: return null;
245: }
246:
247: } // getItems
248:
249: /**
250: * Access the checked status of this item. Possible values:
251: *
252: * @see MenuItem
253: * @return The the checked status of this item.
254: */
255: public int getChecked() {
256: return CHECKED_NA;
257:
258: } // getChecked
259:
260: /**
261: * Access the is-field (not a button) flag.
262: *
263: * @return True if the item is a field, false if not.
264: */
265: public boolean getIsField() {
266: return false;
267:
268: } // getIsField
269:
270: /**
271: * Adjust by removing any dividers at the start or end.
272: */
273: public void adjustDividers() {
274: // trim leading dividers
275: while ((m_items.size() > 0)
276: && (m_items.get(0) instanceof MenuDivider)) {
277: m_items.remove(0);
278: }
279:
280: // trim trailing dividers
281: while ((m_items.size() > 0)
282: && (m_items.get(m_items.size() - 1) instanceof MenuDivider)) {
283: m_items.remove(m_items.size() - 1);
284: }
285:
286: } // adjustDividers
287:
288: /**
289: * Set whether disabled items in this menu should be shown.
290: *
291: * @param value
292: * True to show disabled items, False otherwise.
293: * @return This, for convenience.
294: */
295: public Menu setShowdisabled(boolean value) {
296: m_showDisabled = value;
297: return this ;
298:
299: } // setShowdisabled
300:
301: /**
302: * Access whether disabled items in this menu should be shown.
303: *
304: * @return Current setting for show-disabled status (true to show disabled items, false to NOT show disabled items).
305: */
306: public boolean getShowdisabled() {
307: return m_showDisabled;
308:
309: } // getShowdisabled
310:
311: } // class Menu
|