View Javadoc

1   package org.rcfaces.core.component;
2   
3   import org.rcfaces.core.internal.tools.CollectionTools.IComponentValueType;
4   import org.rcfaces.core.component.capability.ISelectionEventCapability;
5   import org.rcfaces.core.internal.component.Properties;
6   import org.rcfaces.core.component.capability.ICheckedValuesCapability;
7   import org.apache.commons.logging.LogFactory;
8   import org.rcfaces.core.internal.tools.MenuTools;
9   import org.rcfaces.core.internal.tools.CollectionTools.IComponentValueTypeCapability;
10  import org.rcfaces.core.component.iterator.IMenuItemIterator;
11  import org.rcfaces.core.component.capability.ICheckEventCapability;
12  import org.rcfaces.core.component.IMenuComponent;
13  import org.rcfaces.core.component.capability.IPreloadedLevelDepthCapability;
14  import javax.el.ValueExpression;
15  import java.util.HashSet;
16  import org.apache.commons.logging.Log;
17  import org.rcfaces.core.internal.capability.ICheckComponent;
18  import java.util.Set;
19  import java.util.Arrays;
20  import org.rcfaces.core.internal.component.CameliaSelectManyComponent;
21  import org.rcfaces.core.component.capability.IMenuEventCapability;
22  import org.rcfaces.core.internal.tools.CheckTools;
23  
24  /**
25   * <p>The menu Component provides a way of creating desktop style menus on web pages. It allows sub-menus, check and radio menu items and image menus. It also provides pop-up menus.</p>
26   * <p>The menu Component has the following capabilities :
27   * <ul>
28   * <li>IPreloadedLevelDepthCapability</li>
29   * <li>IMenuEventCapability</li>
30   * <li>ISelectionEventCapability</li>
31   * <li>ICheckEventCapability</li>
32   * <li>ICheckedValuesCapability</li>
33   * <li>ICheckComponent</li>
34   * <li>IMenuComponent</li>
35   * <li>IComponentValueTypeCapability</li>
36   * </ul>
37   * </p>
38   * 
39   * <p>The default <a href="/apidocs/index.html?org/rcfaces/core/component/MenuComponent.html">menu</a> renderer is linked to the <a href="/jsdocs/index.html?f_menu.html" target="_blank">f_menu</a> javascript class. f_menu extends f_menuBase</p>
40   * 
41   * <p> Table of component style classes: </p>
42   * <table border="1" cellpadding="3" cellspacing="0" width="100%">
43   * <tbody>
44   * 
45   * <tr style="text-align:left">
46   * <th  width="33%">Style Name</th>
47   * <th width="50%">Description</th>
48   * </tr>
49   * 
50   * <tr  style="text-align:left">
51   * <td width="33%">f_menu</td>
52   * <td width="50%">Defines styles for the wrapper UL element. Coantains f_grid_popup and f_menu_item styles</td>
53   * </tr>
54   * 
55   * </tbody>
56   * </table>
57   */
58  public class MenuComponent extends CameliaSelectManyComponent implements 
59  	IPreloadedLevelDepthCapability,
60  	IMenuEventCapability,
61  	ISelectionEventCapability,
62  	ICheckEventCapability,
63  	ICheckedValuesCapability,
64  	ICheckComponent,
65  	IMenuComponent,
66  	IComponentValueTypeCapability {
67  
68  	private static final Log LOG = LogFactory.getLog(MenuComponent.class);
69  
70  	public static final String COMPONENT_TYPE="org.rcfaces.core.menu";
71  
72  	protected static final Set CAMELIA_ATTRIBUTES=new HashSet(CameliaSelectManyComponent.CAMELIA_ATTRIBUTES);
73  	static {
74  		CAMELIA_ATTRIBUTES.addAll(Arrays.asList(new String[] {"checkedValues","checkListener","selectionListener","preloadedLevelDepth","converter","removeAllWhenShown","menuListener","menuId"}));
75  	}
76  
77  	public MenuComponent() {
78  		setRendererType(null);
79  	}
80  
81  	public MenuComponent(String componentId) {
82  		this();
83  		setId(componentId);
84  	}
85  
86  	public IMenuItemIterator listMenuItems() {
87  
88  
89  		return MenuTools.listMenuItems(this);
90  		
91  	}
92  
93  	public IComponentValueType getComponentValueType() {
94  
95  
96  				return MenuTools.MENU_VALUE_TYPE;
97  			
98  	}
99  
100 	public void check(Object value) {
101 
102 
103 				CheckTools.check(null, this, value);
104 			
105 	}
106 
107 	public void checkAll() {
108 
109 
110 				CheckTools.checkAll(null, this);
111 			
112 	}
113 
114 	public void uncheck(Object value) {
115 
116 
117 				CheckTools.uncheck(null, this, value);
118 			
119 	}
120 
121 	public void uncheckAll() {
122 
123 
124 				CheckTools.uncheckAll(null, this);
125 			
126 	}
127 
128 	public int getPreloadedLevelDepth() {
129 		return getPreloadedLevelDepth(null);
130 	}
131 
132 	/**
133 	 * See {@link #getPreloadedLevelDepth() getPreloadedLevelDepth()} for more details
134 	 */
135 	public int getPreloadedLevelDepth(javax.faces.context.FacesContext facesContext) {
136 		return engine.getIntProperty(Properties.PRELOADED_LEVEL_DEPTH,-1, facesContext);
137 	}
138 
139 	/**
140 	 * Returns <code>true</code> if the attribute "preloadedLevelDepth" is set.
141 	 * @return <code>true</code> if the attribute is set.
142 	 */
143 	public final boolean isPreloadedLevelDepthSetted() {
144 		return engine.isPropertySetted(Properties.PRELOADED_LEVEL_DEPTH);
145 	}
146 
147 	public void setPreloadedLevelDepth(int preloadedLevelDepth) {
148 		engine.setProperty(Properties.PRELOADED_LEVEL_DEPTH, preloadedLevelDepth);
149 	}
150 
151 	public final void addMenuListener(org.rcfaces.core.event.IMenuListener listener) {
152 		addFacesListener(listener);
153 	}
154 
155 	public final void removeMenuListener(org.rcfaces.core.event.IMenuListener listener) {
156 		removeFacesListener(listener);
157 	}
158 
159 	public final javax.faces.event.FacesListener [] listMenuListeners() {
160 		return getFacesListeners(org.rcfaces.core.event.IMenuListener.class);
161 	}
162 
163 	public final void addSelectionListener(org.rcfaces.core.event.ISelectionListener listener) {
164 		addFacesListener(listener);
165 	}
166 
167 	public final void removeSelectionListener(org.rcfaces.core.event.ISelectionListener listener) {
168 		removeFacesListener(listener);
169 	}
170 
171 	public final javax.faces.event.FacesListener [] listSelectionListeners() {
172 		return getFacesListeners(org.rcfaces.core.event.ISelectionListener.class);
173 	}
174 
175 	public final void addCheckListener(org.rcfaces.core.event.ICheckListener listener) {
176 		addFacesListener(listener);
177 	}
178 
179 	public final void removeCheckListener(org.rcfaces.core.event.ICheckListener listener) {
180 		removeFacesListener(listener);
181 	}
182 
183 	public final javax.faces.event.FacesListener [] listCheckListeners() {
184 		return getFacesListeners(org.rcfaces.core.event.ICheckListener.class);
185 	}
186 
187 	public java.lang.Object getCheckedValues() {
188 		return getCheckedValues(null);
189 	}
190 
191 	/**
192 	 * See {@link #getCheckedValues() getCheckedValues()} for more details
193 	 */
194 	public java.lang.Object getCheckedValues(javax.faces.context.FacesContext facesContext) {
195 		return engine.getProperty(Properties.CHECKED_VALUES, facesContext);
196 	}
197 
198 	/**
199 	 * Returns <code>true</code> if the attribute "checkedValues" is set.
200 	 * @return <code>true</code> if the attribute is set.
201 	 */
202 	public final boolean isCheckedValuesSetted() {
203 		return engine.isPropertySetted(Properties.CHECKED_VALUES);
204 	}
205 
206 	public void setCheckedValues(java.lang.Object checkedValues) {
207 		engine.setProperty(Properties.CHECKED_VALUES, checkedValues);
208 	}
209 
210 	/**
211 	 * Return the type of the property represented by the {@link ValueExpression}, relative to the specified {@link javax.faces.context.FacesContext}.
212 	 */
213 	public Class getCheckedValuesType(javax.faces.context.FacesContext facesContext) {
214 		ValueExpression valueExpression=engine.getValueExpressionProperty(Properties.CHECKED_VALUES);
215 		if (valueExpression==null) {
216 			return null;
217 		}
218 		if (facesContext==null) {
219 			facesContext=javax.faces.context.FacesContext.getCurrentInstance();
220 		}
221 		return valueExpression.getType(facesContext.getELContext());
222 	}
223 
224 	public Object getFirstCheckedValue() {
225 
226 
227 			return CheckTools.getFirst(getCheckedValues(), getValue());
228 		
229 	}
230 
231 	public int getCheckedValuesCount() {
232 
233 
234 			return CheckTools.getCount(getCheckedValues());
235 		
236 	}
237 
238 	public Object[] listCheckedValues() {
239 
240 
241 			return CheckTools.listValues(getCheckedValues(), getValue());
242 		
243 	}
244 
245 	/**
246 	 * Returns an id used to retreive a specific menu. For example, "#node" is used to call a menu on a tree node while "#body" is used for the menu boody.
247 	 * @return menu Id
248 	 */
249 	public String getMenuId() {
250 		return getMenuId(null);
251 	}
252 
253 	/**
254 	 * Returns an id used to retreive a specific menu. For example, "#node" is used to call a menu on a tree node while "#body" is used for the menu boody.
255 	 * @return menu Id
256 	 */
257 	public String getMenuId(javax.faces.context.FacesContext facesContext) {
258 		return engine.getStringProperty(Properties.MENU_ID, facesContext);
259 	}
260 
261 	/**
262 	 * Sets an id used to retreive a specific menu. For example, "#node" is used to call a menu on a tree node while "#body" is used for the menu boody.
263 	 * @param menuId menu Id
264 	 */
265 	public void setMenuId(String menuId) {
266 		engine.setProperty(Properties.MENU_ID, menuId);
267 	}
268 
269 	/**
270 	 * Sets an id used to retreive a specific menu. For example, "#node" is used to call a menu on a tree node while "#body" is used for the menu boody.
271 	 * @param menuId menu Id
272 	 */
273 	/**
274 	 * Returns <code>true</code> if the attribute "menuId" is set.
275 	 * @return <code>true</code> if the attribute is set.
276 	 */
277 	public boolean isMenuIdSetted() {
278 		return engine.isPropertySetted(Properties.MENU_ID);
279 	}
280 
281 	/**
282 	 * Returns a boolean value specifying wether the content of the component must be remove before the listener is called and the component displayed.
283 	 * @return true if content is removed when shown
284 	 */
285 	public boolean isRemoveAllWhenShown() {
286 		return isRemoveAllWhenShown(null);
287 	}
288 
289 	/**
290 	 * Returns a boolean value specifying wether the content of the component must be remove before the listener is called and the component displayed.
291 	 * @return true if content is removed when shown
292 	 */
293 	public boolean isRemoveAllWhenShown(javax.faces.context.FacesContext facesContext) {
294 		return engine.getBoolProperty(Properties.REMOVE_ALL_WHEN_SHOWN, false, facesContext);
295 	}
296 
297 	/**
298 	 * Sets a boolean value specifying wether the content of the component must be remove before the listener is called and the component displayed.
299 	 * @param removeAllWhenShown true if content is to be removed when shown
300 	 */
301 	public void setRemoveAllWhenShown(boolean removeAllWhenShown) {
302 		engine.setProperty(Properties.REMOVE_ALL_WHEN_SHOWN, removeAllWhenShown);
303 	}
304 
305 	/**
306 	 * Sets a boolean value specifying wether the content of the component must be remove before the listener is called and the component displayed.
307 	 * @param removeAllWhenShown true if content is to be removed when shown
308 	 */
309 	/**
310 	 * Returns <code>true</code> if the attribute "removeAllWhenShown" is set.
311 	 * @return <code>true</code> if the attribute is set.
312 	 */
313 	public boolean isRemoveAllWhenShownSetted() {
314 		return engine.isPropertySetted(Properties.REMOVE_ALL_WHEN_SHOWN);
315 	}
316 
317 	protected Set getCameliaFields() {
318 		return CAMELIA_ATTRIBUTES;
319 	}
320 }