001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/velocity/tags/sakai_2-4-1/tool/src/java/org/sakaiproject/cheftool/menu/MenuEntry.java $
003: * $Id: MenuEntry.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.api.MenuItem;
026:
027: /**
028: * <p>
029: * MenuEntry is a clickable entry in a menu.
030: * </p>
031: */
032: public class MenuEntry implements MenuItem {
033: /** The display title for the entry. */
034: protected String m_title = null;
035:
036: /** The icon name for the entry. */
037: protected String m_icon = null;
038:
039: /** The enabled flag for the entry. */
040: protected boolean m_enabled = true;
041:
042: /** The action string for the entry. */
043: protected String m_action = null;
044:
045: /** The full URL string for the entry. */
046: protected String m_url = null;
047:
048: /** The form name string for the entry. */
049: protected String m_form = null;
050:
051: /** The checked status (@see MenuItem for values). */
052: protected int m_checked = CHECKED_NA;
053:
054: /**
055: * Construct a menu.
056: */
057: public MenuEntry(String title, String icon, boolean enabled,
058: int checked, String action, String form) {
059: m_title = title;
060: m_icon = icon;
061: m_enabled = enabled;
062: m_checked = checked;
063: m_action = action;
064: m_form = form;
065:
066: } // MenuEntry
067:
068: /**
069: * Construct a menu.
070: */
071: public MenuEntry(String title, String icon, boolean enabled,
072: int checked, String action) {
073: m_title = title;
074: m_icon = icon;
075: m_enabled = enabled;
076: m_checked = checked;
077: m_action = action;
078:
079: } // MenuEntry
080:
081: /**
082: * Construct a menu.
083: */
084: public MenuEntry(String title, boolean enabled, String action) {
085: m_title = title;
086: m_enabled = enabled;
087: m_action = action;
088:
089: } // MenuEntry
090:
091: /**
092: * Construct a menu.
093: */
094: public MenuEntry(String title, String action) {
095: m_title = title;
096: m_action = action;
097:
098: } // MenuEntry
099:
100: /**
101: * Set the full URL of the entry. To create an entry with a URL, create one first with a "" action, then call this.
102: *
103: * @param url
104: * The full URL for the entry.
105: * @return This, for convenience.
106: */
107: public MenuEntry setUrl(String url) {
108: m_url = url;
109: return this ;
110:
111: } // setUrl
112:
113: /**
114: * Does this item act as a container for other items?
115: *
116: * @return true if this MenuItem is a container for other items, false if not.
117: */
118: public boolean getIsContainer() {
119: return false;
120:
121: } // getIsContainer
122:
123: /**
124: * Is this item a divider ?
125: *
126: * @return true if this MenuItem is a divider, false if not.
127: */
128: public boolean getIsDivider() {
129: return false;
130:
131: } // getIsDivider
132:
133: /**
134: * Access the display title for the item.
135: *
136: * @return The display title for the item.
137: */
138: public String getTitle() {
139: return ((m_title == null) ? "" : m_title);
140:
141: } // getTitle
142:
143: /**
144: * Access the icon name for the item (or null if no icon).
145: *
146: * @return The icon name for the item (or null if no icon).
147: */
148: public String getIcon() {
149: return m_icon;
150:
151: } // getIcon
152:
153: /**
154: * Access the enabled flag for the item.
155: *
156: * @return True if the item is enabled, false if not.
157: */
158: public boolean getIsEnabled() {
159: return m_enabled;
160:
161: } // getIsEnabled
162:
163: /**
164: * 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 ""). Note: if the entry is not enabled, this will return "".
165: *
166: * @return The action string for this item.
167: */
168: public String getAction() {
169: return (((m_action == null) || (!m_enabled)) ? "" : m_action);
170:
171: } // getAction
172:
173: /**
174: * 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 "").
175: *
176: * @return The full URL string for this item.
177: */
178: public String getUrl() {
179: return (((m_url == null) || (!m_enabled)) ? "" : m_url);
180:
181: } // getUrl
182:
183: /**
184: * Access the form name whose values will be used when this item is selected.
185: *
186: * @return The form name whose values will be used when this item is selected.
187: */
188: public String getForm() {
189: return m_form;
190:
191: } // getForm
192:
193: /**
194: * Access the sub-items of the item. Note: if !isContainer(), there will be no sub-items (will return EmptyIterator).
195: *
196: * @return The sub-items of the item.
197: */
198: public List getItems() {
199: return new Vector();
200:
201: } // getItems
202:
203: /**
204: * Access one sub-items of the item. Note: if !isContainer(), there will be no sub-items (will return null).
205: *
206: * @param index
207: * The index position (0 based) for the sub-item to get.
208: * @return The sub-item of the item.
209: */
210: public MenuItem getItem(int index) {
211: return null;
212:
213: } // getItem
214:
215: /**
216: * Access the checked status of this item. Possible values:
217: *
218: * @see MenuItem
219: * @return The checked status of this item.
220: */
221: public int getChecked() {
222: return m_checked;
223:
224: } // getChecked
225:
226: /**
227: * Access the checked status of this item.
228: *
229: * @return True if item is checked, false otherwise.
230: */
231: public boolean getIschecked() {
232: return m_checked == CHECKED_TRUE;
233:
234: } // getIsChecked
235:
236: /**
237: * Count the sub-items of the item. Note: if !isContainer(), the count is 0.
238: *
239: * @return The count of sub-items of the item.
240: */
241: public int size() {
242: return 0;
243:
244: } // size
245:
246: /**
247: * Check if there are any sub-items. Note: if !isContainer(), this is empty.
248: *
249: * @return true of there are no sub-items, false if there are.
250: */
251: public boolean isEmpty() {
252: return true;
253:
254: } // isEmpty
255:
256: /**
257: * Access the is-field (not a button) flag.
258: *
259: * @return True if the item is a field, false if not.
260: */
261: public boolean getIsField() {
262: return false;
263:
264: } // getIsField
265:
266: } // MenuEntry
|