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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
134
135 public int getPreloadedLevelDepth(javax.faces.context.FacesContext facesContext) {
136 return engine.getIntProperty(Properties.PRELOADED_LEVEL_DEPTH,-1, facesContext);
137 }
138
139
140
141
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
193
194 public java.lang.Object getCheckedValues(javax.faces.context.FacesContext facesContext) {
195 return engine.getProperty(Properties.CHECKED_VALUES, facesContext);
196 }
197
198
199
200
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
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
247
248
249 public String getMenuId() {
250 return getMenuId(null);
251 }
252
253
254
255
256
257 public String getMenuId(javax.faces.context.FacesContext facesContext) {
258 return engine.getStringProperty(Properties.MENU_ID, facesContext);
259 }
260
261
262
263
264
265 public void setMenuId(String menuId) {
266 engine.setProperty(Properties.MENU_ID, menuId);
267 }
268
269
270
271
272
273
274
275
276
277 public boolean isMenuIdSetted() {
278 return engine.isPropertySetted(Properties.MENU_ID);
279 }
280
281
282
283
284
285 public boolean isRemoveAllWhenShown() {
286 return isRemoveAllWhenShown(null);
287 }
288
289
290
291
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
299
300
301 public void setRemoveAllWhenShown(boolean removeAllWhenShown) {
302 engine.setProperty(Properties.REMOVE_ALL_WHEN_SHOWN, removeAllWhenShown);
303 }
304
305
306
307
308
309
310
311
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 }