1
2
3
4 package org.rcfaces.core.item;
5
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import javax.faces.component.UISelectItem;
10 import javax.faces.model.SelectItem;
11
12 import org.rcfaces.core.component.capability.IAcceleratorKeyCapability;
13 import org.rcfaces.core.component.capability.IAccessKeyCapability;
14 import org.rcfaces.core.component.capability.IClientDataCapability;
15 import org.rcfaces.core.component.capability.IDragAndDropEffects;
16 import org.rcfaces.core.component.capability.IDraggableCapability;
17 import org.rcfaces.core.component.capability.IInputTypeCapability;
18 import org.rcfaces.core.component.capability.IRadioGroupCapability;
19 import org.rcfaces.core.component.capability.IServerDataCapability;
20 import org.rcfaces.core.component.capability.IStyleClassCapability;
21 import org.rcfaces.core.component.capability.IToolTipCapability;
22 import org.rcfaces.core.component.capability.IVisibilityCapability;
23
24
25
26
27
28
29 public class BasicSelectItem extends SelectItem implements ISelectItem,
30 IAccessKeyItem, IAcceleratorKeyItem, IGroupSelectItem, IInputTypeItem,
31 IVisibleItem, IServerDataItem, IClientDataItem, IStyleClassItem {
32 private static final String REVISION = "$Revision: 1.5 $";
33
34 private static final long serialVersionUID = 6953469102413843158L;
35
36 private static final String[] STRING_EMPTY_ARRAY = new String[0];
37
38 private Map serverDatas;
39
40 private Map clientDatas;
41
42 private String accessKey;
43
44 private String acceleratorKey;
45
46 private String groupName;
47
48 private boolean visible = true;
49
50 private int inputType;
51
52 private String styleClass;
53
54 private int dragEffects = IDragAndDropEffects.UNKNOWN_DND_EFFECT;
55
56 private String[] dragTypes;
57
58 public BasicSelectItem() {
59 }
60
61 public BasicSelectItem(Object value) {
62 super(value);
63 }
64
65 public BasicSelectItem(Object value, String label) {
66 super(value, label);
67 }
68
69 public BasicSelectItem(Object value, String label, String description) {
70 super(value, label, description);
71 }
72
73 public BasicSelectItem(Object value, String label, String description,
74 boolean disabled) {
75 super(value, label, description, disabled);
76 }
77
78 public BasicSelectItem(ISelectItem selectItem) {
79 super(selectItem.getValue(), selectItem.getLabel(), selectItem
80 .getDescription(), selectItem.isDisabled());
81 }
82
83 public BasicSelectItem(UISelectItem component) {
84 super(getValue(component), component.getItemLabel(), component
85 .getItemDescription(), component.isItemDisabled());
86
87 int s = 0;
88
89
90 if (component instanceof IAccessKeyCapability) {
91 accessKey = ((IAccessKeyCapability) component).getAccessKey();
92
93 } else {
94 accessKey = null;
95 }
96
97 if (component instanceof IAcceleratorKeyCapability) {
98 acceleratorKey = ((IAcceleratorKeyCapability) component)
99 .getAcceleratorKey();
100
101 } else {
102 acceleratorKey = null;
103 }
104
105 if (component instanceof IRadioGroupCapability) {
106 groupName = ((IRadioGroupCapability) component).getGroupName();
107 s = IInputTypeCapability.AS_RADIO_BUTTON;
108
109 } else {
110 groupName = null;
111 }
112
113 if (component instanceof IVisibilityCapability) {
114 Boolean b = ((IVisibilityCapability) component).getVisibleState();
115
116 visible = (Boolean.FALSE.equals(b) == false);
117
118 } else {
119 visible = true;
120 }
121
122 if (component instanceof IServerDataCapability) {
123 IServerDataCapability serverDataCapability = (IServerDataCapability) component;
124
125 if (serverDataCapability.getServerDataCount() > 0) {
126 Map map = serverDataCapability.getServerDataMap();
127
128 getServerDataMap().putAll(map);
129 }
130 }
131
132 if (component instanceof IClientDataCapability) {
133 IClientDataCapability clientDataCapability = (IClientDataCapability) component;
134
135 if (clientDataCapability.getClientDataCount() > 0) {
136 Map map = clientDataCapability.getClientDataMap();
137
138 getClientDataMap().putAll(map);
139 }
140 }
141
142 if (getDescription() == null
143 && (component instanceof IToolTipCapability)) {
144 setDescription(((IToolTipCapability) component).getToolTipText());
145 }
146
147 this.inputType = s;
148
149 if (component instanceof IStyleClassCapability) {
150 IStyleClassCapability styleClassCapability = (IStyleClassCapability) component;
151
152 styleClass = styleClassCapability.getStyleClass();
153 }
154
155 if (component instanceof IDraggableCapability) {
156 IDraggableCapability draggableItemCapability = (IDraggableCapability) component;
157
158 dragTypes = draggableItemCapability.getDragTypes();
159 dragEffects = draggableItemCapability.getDragEffects();
160 }
161 }
162
163
164
165
166
167
168 public String getAccessKey() {
169 return accessKey;
170 }
171
172 public String getGroupName() {
173 return groupName;
174 }
175
176 public static Object getValue(UISelectItem component) {
177 Object value = component.getItemValue();
178 if (value != null) {
179 return value;
180 }
181
182
183
184 return component.getId();
185 }
186
187 public int getInputType() {
188 return inputType;
189 }
190
191 public boolean isVisible() {
192 return visible;
193 }
194
195 public void setAccessKey(String accessKey) {
196 this.accessKey = accessKey;
197 }
198
199 public final void setAcceleratorKey(String acceleratorKey) {
200 this.acceleratorKey = acceleratorKey;
201 }
202
203 public final void setStyleClass(String styleClass) {
204 this.styleClass = styleClass;
205 }
206
207 public void setGroupName(String groupName) {
208 this.groupName = groupName;
209 }
210
211 public void setInputType(int style) {
212 this.inputType = style;
213 }
214
215 public void setVisible(boolean visible) {
216 this.visible = visible;
217 }
218
219 public boolean isServerDataEmpty() {
220 if (serverDatas == null) {
221 return true;
222 }
223
224 return serverDatas.isEmpty();
225 }
226
227 public Map getServerDataMap() {
228 if (serverDatas == null) {
229 serverDatas = new HashMap();
230 }
231
232 return serverDatas;
233 }
234
235 public boolean isClientDataEmpty() {
236 if (clientDatas == null) {
237 return true;
238 }
239
240 return clientDatas.isEmpty();
241 }
242
243 public Map getClientDataMap() {
244 if (clientDatas == null) {
245 clientDatas = new HashMap();
246 }
247
248 return clientDatas;
249 }
250
251 public String getStyleClass() {
252 return styleClass;
253 }
254
255 public String getAcceleratorKey() {
256 return acceleratorKey;
257 }
258
259 public int getDragEffects(SelectItem dragItem) {
260 if (dragItem == null || equals(getValue(), dragItem.getValue())) {
261 return dragEffects;
262 }
263
264 return IDragAndDropEffects.UNKNOWN_DND_EFFECT;
265 }
266
267 public void setDragEffects(int dragEffects) {
268 this.dragEffects = dragEffects;
269 }
270
271 public String[] getDragTypes(SelectItem dragItem) {
272 if (dragItem == null || equals(getValue(), dragItem.getValue())) {
273 return dragTypes;
274 }
275
276 return null;
277 }
278
279 public void setDragTypes(String[] dragTypes) {
280 this.dragTypes = dragTypes;
281 }
282
283 private boolean equals(Object value1, Object value2) {
284 if (value1 == value2) {
285 return true;
286 }
287
288 return value1 != null && value1.equals(value2);
289 }
290 }