1 package org.rcfaces.core.component;
2
3 import org.rcfaces.core.internal.tools.CollectionTools.IComponentValueType;
4 import org.rcfaces.core.component.AbstractConverterCommandComponent;
5 import org.rcfaces.core.component.capability.ISelectionEventCapability;
6 import org.rcfaces.core.internal.component.Properties;
7 import org.rcfaces.core.component.capability.ICheckedValuesCapability;
8 import org.rcfaces.core.component.capability.IUnlockedClientAttributesCapability;
9 import org.apache.commons.logging.LogFactory;
10 import org.rcfaces.core.internal.tools.MenuTools;
11 import org.rcfaces.core.internal.tools.CollectionTools.IComponentValueTypeCapability;
12 import org.rcfaces.core.component.iterator.IMenuItemIterator;
13 import org.rcfaces.core.component.capability.ICheckEventCapability;
14 import org.rcfaces.core.component.IMenuComponent;
15 import org.rcfaces.core.component.capability.IReadOnlyCapability;
16 import javax.el.ValueExpression;
17 import java.util.HashSet;
18 import org.apache.commons.logging.Log;
19 import org.rcfaces.core.internal.capability.ICheckComponent;
20 import java.util.Set;
21 import java.util.Arrays;
22 import org.rcfaces.core.internal.tools.CheckTools;
23
24
25
26
27 public abstract class AbstractMenuComponent extends AbstractConverterCommandComponent implements
28 IUnlockedClientAttributesCapability,
29 ISelectionEventCapability,
30 ICheckEventCapability,
31 ICheckedValuesCapability,
32 IReadOnlyCapability,
33 ICheckComponent,
34 IMenuComponent,
35 IComponentValueTypeCapability {
36
37 private static final Log LOG = LogFactory.getLog(AbstractMenuComponent.class);
38
39 protected static final Set CAMELIA_ATTRIBUTES=new HashSet(AbstractConverterCommandComponent.CAMELIA_ATTRIBUTES);
40 static {
41 CAMELIA_ATTRIBUTES.addAll(Arrays.asList(new String[] {"checkedValues","checkListener","selectionListener","unlockedClientAttributeNames","readOnly","removeAllWhenShown"}));
42 }
43
44
45 public IComponentValueType getComponentValueType() {
46
47
48 return MenuTools.MENU_VALUE_TYPE;
49
50 }
51
52 public void check(Object value) {
53
54
55 CheckTools.check(null, this, value);
56
57 }
58
59 public void checkAll() {
60
61
62 CheckTools.checkAll(null, this);
63
64 }
65
66 public void uncheck(Object value) {
67
68
69 CheckTools.uncheck(null, this, value);
70
71 }
72
73 public void uncheckAll() {
74
75
76 CheckTools.uncheckAll(null, this);
77
78 }
79
80 public IMenuItemIterator listMenuItems() {
81
82
83 return MenuTools.listMenuItems(this);
84
85 }
86
87 public final void addSelectionListener(org.rcfaces.core.event.ISelectionListener listener) {
88 addFacesListener(listener);
89 }
90
91 public final void removeSelectionListener(org.rcfaces.core.event.ISelectionListener listener) {
92 removeFacesListener(listener);
93 }
94
95 public final javax.faces.event.FacesListener [] listSelectionListeners() {
96 return getFacesListeners(org.rcfaces.core.event.ISelectionListener.class);
97 }
98
99 public final void addCheckListener(org.rcfaces.core.event.ICheckListener listener) {
100 addFacesListener(listener);
101 }
102
103 public final void removeCheckListener(org.rcfaces.core.event.ICheckListener listener) {
104 removeFacesListener(listener);
105 }
106
107 public final javax.faces.event.FacesListener [] listCheckListeners() {
108 return getFacesListeners(org.rcfaces.core.event.ICheckListener.class);
109 }
110
111 public java.lang.Object getCheckedValues() {
112 return getCheckedValues(null);
113 }
114
115
116
117
118 public java.lang.Object getCheckedValues(javax.faces.context.FacesContext facesContext) {
119 return engine.getProperty(Properties.CHECKED_VALUES, facesContext);
120 }
121
122
123
124
125
126 public final boolean isCheckedValuesSetted() {
127 return engine.isPropertySetted(Properties.CHECKED_VALUES);
128 }
129
130 public void setCheckedValues(java.lang.Object checkedValues) {
131 engine.setProperty(Properties.CHECKED_VALUES, checkedValues);
132 }
133
134
135
136
137 public Class getCheckedValuesType(javax.faces.context.FacesContext facesContext) {
138 ValueExpression valueExpression=engine.getValueExpressionProperty(Properties.CHECKED_VALUES);
139 if (valueExpression==null) {
140 return null;
141 }
142 if (facesContext==null) {
143 facesContext=javax.faces.context.FacesContext.getCurrentInstance();
144 }
145 return valueExpression.getType(facesContext.getELContext());
146 }
147
148 public Object getFirstCheckedValue() {
149
150
151 return CheckTools.getFirst(getCheckedValues(), getValue());
152
153 }
154
155 public int getCheckedValuesCount() {
156
157
158 return CheckTools.getCount(getCheckedValues());
159
160 }
161
162 public Object[] listCheckedValues() {
163
164
165 return CheckTools.listValues(getCheckedValues(), getValue());
166
167 }
168
169 public boolean isReadOnly() {
170 return isReadOnly(null);
171 }
172
173
174
175
176 public boolean isReadOnly(javax.faces.context.FacesContext facesContext) {
177 return engine.getBoolProperty(Properties.READ_ONLY, false, facesContext);
178 }
179
180
181
182
183
184 public final boolean isReadOnlySetted() {
185 return engine.isPropertySetted(Properties.READ_ONLY);
186 }
187
188 public void setReadOnly(boolean readOnly) {
189 engine.setProperty(Properties.READ_ONLY, readOnly);
190 }
191
192
193
194
195
196 public boolean isRemoveAllWhenShown() {
197 return isRemoveAllWhenShown(null);
198 }
199
200
201
202
203
204 public boolean isRemoveAllWhenShown(javax.faces.context.FacesContext facesContext) {
205 return engine.getBoolProperty(Properties.REMOVE_ALL_WHEN_SHOWN, false, facesContext);
206 }
207
208
209
210
211
212 public void setRemoveAllWhenShown(boolean removeAllWhenShown) {
213 engine.setProperty(Properties.REMOVE_ALL_WHEN_SHOWN, removeAllWhenShown);
214 }
215
216
217
218
219
220
221
222
223
224 public boolean isRemoveAllWhenShownSetted() {
225 return engine.isPropertySetted(Properties.REMOVE_ALL_WHEN_SHOWN);
226 }
227
228 protected Set getCameliaFields() {
229 return CAMELIA_ATTRIBUTES;
230 }
231 }