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.UIComponent;
10 import javax.faces.component.UISelectItem;
11 import javax.faces.context.FacesContext;
12 import javax.faces.model.SelectItem;
13 import javax.faces.model.SelectItemGroup;
14
15 import org.rcfaces.core.component.capability.IAcceleratorKeyCapability;
16 import org.rcfaces.core.component.capability.IAccessKeyCapability;
17 import org.rcfaces.core.component.capability.IAlternateTextCapability;
18 import org.rcfaces.core.component.capability.IClientDataCapability;
19 import org.rcfaces.core.component.capability.IDragAndDropEffects;
20 import org.rcfaces.core.component.capability.IDraggableCapability;
21 import org.rcfaces.core.component.capability.IDroppableCapability;
22 import org.rcfaces.core.component.capability.IHorizontalTextPositionCapability;
23 import org.rcfaces.core.component.capability.IImageCapability;
24 import org.rcfaces.core.component.capability.IImageSizeCapability;
25 import org.rcfaces.core.component.capability.IImmediateCapability;
26 import org.rcfaces.core.component.capability.IInputTypeCapability;
27 import org.rcfaces.core.component.capability.ILookAndFeelCapability;
28 import org.rcfaces.core.component.capability.IMenuPopupIdCapability;
29 import org.rcfaces.core.component.capability.IRadioGroupCapability;
30 import org.rcfaces.core.component.capability.IServerDataCapability;
31 import org.rcfaces.core.component.capability.IStyleClassCapability;
32 import org.rcfaces.core.component.capability.IVisibilityCapability;
33 import org.rcfaces.core.component.capability.IWidthCapability;
34 import org.rcfaces.core.component.familly.IContentAccessors;
35 import org.rcfaces.core.internal.component.IExpandImageAccessors;
36 import org.rcfaces.core.internal.component.IImageAccessors;
37 import org.rcfaces.core.internal.component.IStatesImageAccessors;
38 import org.rcfaces.core.internal.contentAccessor.IContentAccessor;
39
40
41
42
43
44
45 class DefaultItem extends SelectItemGroup {
46
47 private static final String REVISION = "$Revision: 1.5 $";
48
49 private static final long serialVersionUID = -3799667579566545958L;
50
51 protected static final SelectItem SELECT_ITEMS_EMPTY_ARRAY[] = new SelectItem[0];
52
53 private Map serverDatas;
54
55 private Map clientDatas;
56
57 private String imageURL;
58
59 private String disabledImageURL;
60
61 private String hoverImageURL;
62
63 private String selectedImageURL;
64
65 private String expandedImageURL;
66
67 private int inputType;
68
69 private String styleClass;
70
71 private String groupName;
72
73 private int imageWidth;
74
75 private int imageHeight;
76
77 private boolean visible = true;
78
79 private boolean immediate = true;
80
81 private String borderType;
82
83 private int textPosition = IHorizontalTextPositionCapability.UNKNOWN_POSITION;
84
85 private String accessKey;
86
87 private String lookId;
88
89 private String acceleratorKey;
90
91 private String menuPopupId;
92
93 private String width;
94
95 private String alternateText;
96
97 private int dragEffects = IDragAndDropEffects.UNKNOWN_DND_EFFECT;
98
99 private String dragTypes[];
100
101 private int dropEffects = IDragAndDropEffects.UNKNOWN_DND_EFFECT;
102
103 private String dropTypes[];
104
105 public DefaultItem() {
106 }
107
108 public DefaultItem(String label) {
109 super(label);
110 }
111
112 public DefaultItem(String label, String description, boolean disabled,
113 SelectItem items[]) {
114 super(label, description, disabled, items);
115 }
116
117 public DefaultItem(ISelectItemGroup selectItem) {
118 super(selectItem.getLabel());
119
120 String description = selectItem.getDescription();
121 if (description != null) {
122 setDescription(description);
123 }
124
125 if (selectItem.isDisabled()) {
126 setDisabled(true);
127 }
128
129 SelectItem children[] = selectItem.getSelectItems();
130 if (children != null) {
131 setSelectItems(children);
132 }
133
134 Object itemValue = selectItem.getValue();
135 if (itemValue != null) {
136 setValue(itemValue);
137 }
138
139 if (selectItem instanceof IInputTypeItem) {
140 setInputType(((IInputTypeItem) selectItem).getInputType());
141
142 if (selectItem instanceof IGroupSelectItem) {
143 String groupName = ((IGroupSelectItem) selectItem)
144 .getGroupName();
145 if (groupName != null) {
146 setGroupName(groupName);
147 }
148 }
149 }
150
151 if (selectItem instanceof IImagesItem) {
152 IImagesItem imagesItem = (IImagesItem) selectItem;
153 setImageURL(imagesItem.getImageURL());
154 setDisabledImageURL(imagesItem.getDisabledImageURL());
155 setHoverImageURL(imagesItem.getHoverImageURL());
156 setSelectedImageURL(imagesItem.getSelectedImageURL());
157 setExpandedImageURL(imagesItem.getExpandedImageURL());
158 }
159
160 if (selectItem instanceof IStyleClassItem) {
161 setStyleClass(((IStyleClassItem) selectItem).getStyleClass());
162 }
163
164 if (selectItem instanceof ILookAndFeelItem) {
165 setLookId(((ILookAndFeelItem) selectItem).getLookId());
166 }
167
168 if (selectItem instanceof IClientDataItem) {
169 Map map = ((IClientDataItem) selectItem).getClientDataMap();
170 if (map.isEmpty() == false) {
171 getClientDataMap().putAll(map);
172 }
173 }
174
175 if (selectItem instanceof IServerDataItem) {
176 Map map = ((IServerDataItem) selectItem).getServerDataMap();
177 if (map.isEmpty() == false) {
178 getServerDataMap().putAll(map);
179 }
180 }
181
182 if (selectItem instanceof IVisibleItem) {
183 if (((IVisibleItem) selectItem).isVisible() == false) {
184 setVisible(false);
185 }
186 }
187
188 if (selectItem instanceof IImmediateItem) {
189 if (((IImmediateItem) selectItem).isImmediate() == false) {
190 setImmediate(false);
191 }
192 }
193
194 if (selectItem instanceof IAccessKeyItem) {
195 setAccessKey(((IAccessKeyItem) selectItem).getAccessKey());
196 }
197
198 if (selectItem instanceof IAcceleratorKeyItem) {
199 setAcceleratorKey(((IAcceleratorKeyItem) selectItem)
200 .getAcceleratorKey());
201 }
202
203 if (selectItem instanceof IMenuPopupIdItem) {
204 setMenuPopupId(((IMenuPopupIdItem) selectItem).getMenuPopupId());
205 }
206
207 if (selectItem instanceof IWidthItem) {
208 setWidth(((IWidthItem) selectItem).getWidth());
209 }
210
211 if (selectItem instanceof IAlternateTextItem) {
212 setAlternateText(((IAlternateTextItem) selectItem)
213 .getAlternateText());
214 }
215
216 if (selectItem instanceof SelectItem) {
217 if (selectItem instanceof IDraggableItem) {
218 IDraggableItem draggableItem = (IDraggableItem) selectItem;
219
220 setDragEffects(draggableItem
221 .getDragEffects((SelectItem) selectItem));
222
223 setDragTypes(draggableItem
224 .getDragTypes((SelectItem) selectItem));
225 }
226
227 if (selectItem instanceof IDroppableItem) {
228 IDroppableItem droppableItem = (IDroppableItem) selectItem;
229
230 setDropEffects(droppableItem
231 .getDropEffects((SelectItem) selectItem));
232
233 setDropTypes(droppableItem
234 .getDropTypes((SelectItem) selectItem));
235 }
236 }
237 }
238
239 public DefaultItem(UISelectItem selectItemComponent) {
240 super(selectItemComponent.getItemLabel(), selectItemComponent
241 .getItemDescription(), selectItemComponent.isItemDisabled(),
242 SELECT_ITEMS_EMPTY_ARRAY);
243
244 FacesContext facesContext = FacesContext.getCurrentInstance();
245
246 Object itemValue = selectItemComponent.getItemValue();
247 if (itemValue != null) {
248 setValue(itemValue);
249 }
250 setInputType(selectItemComponent);
251
252 if (selectItemComponent instanceof IStyleClassCapability) {
253 setStyleClass(((IStyleClassCapability) selectItemComponent)
254 .getStyleClass());
255 }
256
257 if (selectItemComponent instanceof ILookAndFeelCapability) {
258 setLookId(((ILookAndFeelCapability) selectItemComponent)
259 .getLookId());
260 }
261
262 if (selectItemComponent instanceof IImageCapability) {
263 IContentAccessors contentAccessors = ((IImageCapability) selectItemComponent)
264 .getImageAccessors();
265
266 if (contentAccessors instanceof IImageAccessors) {
267 IImageAccessors imageAccessors = (IImageAccessors) contentAccessors;
268
269 IContentAccessor contentAccessor = imageAccessors
270 .getImageAccessor();
271 if (contentAccessor != null) {
272 setImageURL(contentAccessor.resolveURL(facesContext, null,
273 null));
274 }
275
276 if (imageAccessors instanceof IStatesImageAccessors) {
277 IStatesImageAccessors statesImageAccessors = (IStatesImageAccessors) imageAccessors;
278
279 contentAccessor = statesImageAccessors
280 .getDisabledImageAccessor();
281 if (contentAccessor != null) {
282 setDisabledImageURL(contentAccessor.resolveURL(
283 facesContext, null, null));
284 }
285
286 contentAccessor = statesImageAccessors
287 .getHoverImageAccessor();
288 if (contentAccessor != null) {
289 setHoverImageURL(contentAccessor.resolveURL(
290 facesContext, null, null));
291 }
292
293 contentAccessor = statesImageAccessors
294 .getSelectedImageAccessor();
295 if (contentAccessor != null) {
296 setSelectedImageURL(contentAccessor.resolveURL(
297 facesContext, null, null));
298 }
299
300 if (imageAccessors instanceof IExpandImageAccessors) {
301 IExpandImageAccessors expandImageAccessors = (IExpandImageAccessors) imageAccessors;
302
303 contentAccessor = expandImageAccessors
304 .getExpandedImageAccessor();
305 if (contentAccessor != null) {
306 setExpandedImageURL(contentAccessor.resolveURL(
307 facesContext, null, null));
308 }
309 }
310
311 }
312 }
313 }
314
315 if (selectItemComponent instanceof IImageSizeCapability) {
316 IImageSizeCapability imageSizeCapability = (IImageSizeCapability) selectItemComponent;
317
318 setImageWidth(imageSizeCapability.getImageWidth());
319 setImageHeight(imageSizeCapability.getImageHeight());
320 }
321
322 if (selectItemComponent instanceof IServerDataCapability) {
323 IServerDataCapability serverDataCapability = (IServerDataCapability) selectItemComponent;
324
325 if (serverDataCapability.getServerDataCount() > 0) {
326 Map map = serverDataCapability.getServerDataMap();
327
328 getServerDataMap().putAll(map);
329 }
330 }
331
332 if (selectItemComponent instanceof IClientDataCapability) {
333 IClientDataCapability clientDataCapability = (IClientDataCapability) selectItemComponent;
334
335 if (clientDataCapability.getClientDataCount() > 0) {
336 Map map = clientDataCapability.getClientDataMap();
337
338 getClientDataMap().putAll(map);
339 }
340 }
341
342 if (selectItemComponent.isRendered() == false) {
343 setVisible(false);
344
345 } else if (selectItemComponent instanceof IVisibilityCapability) {
346 if (((IVisibilityCapability) selectItemComponent).isVisible() == false) {
347 setVisible(false);
348 }
349 }
350
351 if (selectItemComponent instanceof IAccessKeyCapability) {
352 setAccessKey(((IAccessKeyCapability) selectItemComponent)
353 .getAccessKey());
354 }
355
356 if (selectItemComponent instanceof IAcceleratorKeyCapability) {
357 setAcceleratorKey(((IAcceleratorKeyCapability) selectItemComponent)
358 .getAcceleratorKey());
359 }
360
361 if (selectItemComponent instanceof IMenuPopupIdCapability) {
362 setMenuPopupId(((IMenuPopupIdCapability) selectItemComponent)
363 .getMenuPopupId());
364 }
365
366 if (selectItemComponent instanceof IWidthCapability) {
367 setWidth(((IWidthCapability) selectItemComponent).getWidth());
368 }
369
370 if (selectItemComponent instanceof IAlternateTextCapability) {
371 setAlternateText(((IAlternateTextCapability) selectItemComponent)
372 .getAlternateText());
373 }
374
375 if (selectItemComponent instanceof IImmediateCapability) {
376 setImmediate(((IImmediateCapability) selectItemComponent)
377 .isImmediate());
378 }
379
380 if (selectItemComponent instanceof IDraggableCapability) {
381 IDraggableCapability draggableCapability = (IDraggableCapability) selectItemComponent;
382
383 setDragEffects(draggableCapability.getDragEffects());
384 setDragTypes(draggableCapability.getDragTypes());
385 }
386
387 if (selectItemComponent instanceof IDroppableCapability) {
388 IDroppableCapability droppableCapability = (IDroppableCapability) selectItemComponent;
389
390 setDropEffects(droppableCapability.getDropEffects());
391 setDropTypes(droppableCapability.getDropTypes());
392 }
393
394 }
395
396 public String getImageURL() {
397 return imageURL;
398 }
399
400
401
402
403
404
405 public String getHoverImageURL() {
406 return hoverImageURL;
407 }
408
409
410
411
412
413
414 public String getSelectedImageURL() {
415 return selectedImageURL;
416 }
417
418
419
420
421
422
423 public String getExpandedImageURL() {
424 return expandedImageURL;
425 }
426
427
428
429
430
431
432 public String getDisabledImageURL() {
433 return disabledImageURL;
434 }
435
436 public void setDisabledImageURL(String disabledImageURL) {
437 this.disabledImageURL = disabledImageURL;
438 }
439
440 public void setExpandedImageURL(String expandedImageURL) {
441 this.expandedImageURL = expandedImageURL;
442 }
443
444 public void setHoverImageURL(String hoverImageURL) {
445 this.hoverImageURL = hoverImageURL;
446 }
447
448 public void setImageURL(String imageURL) {
449 this.imageURL = imageURL;
450 }
451
452 public void setSelectedImageURL(String selectedImageURL) {
453 this.selectedImageURL = selectedImageURL;
454 }
455
456 public int getInputType() {
457 return inputType;
458 }
459
460 public void setInputType(int inputType) {
461 this.inputType = inputType;
462 }
463
464 public final String getStyleClass() {
465 return styleClass;
466 }
467
468 public final void setStyleClass(String styleClass) {
469 this.styleClass = styleClass;
470 }
471
472 public boolean isServerDataEmpty() {
473 if (serverDatas == null) {
474 return true;
475 }
476
477 return serverDatas.isEmpty();
478 }
479
480 public Map getServerDataMap() {
481 if (serverDatas == null) {
482 serverDatas = new HashMap();
483 }
484
485 return serverDatas;
486 }
487
488 public final String getGroupName() {
489 return groupName;
490 }
491
492 public final void setGroupName(String groupName) {
493 this.groupName = groupName;
494 }
495
496 public final int getImageHeight() {
497 return imageHeight;
498 }
499
500 public final void setImageHeight(int imageHeight) {
501 this.imageHeight = imageHeight;
502 }
503
504 public final int getImageWidth() {
505 return imageWidth;
506 }
507
508 public final void setImageWidth(int imageWidth) {
509 this.imageWidth = imageWidth;
510 }
511
512 public final String getLookId() {
513 return lookId;
514 }
515
516 public final void setLookId(String lookId) {
517 this.lookId = lookId;
518 }
519
520 public boolean isClientDataEmpty() {
521 if (clientDatas == null) {
522 return true;
523 }
524
525 return clientDatas.isEmpty();
526 }
527
528 public Map getClientDataMap() {
529 if (clientDatas == null) {
530 clientDatas = new HashMap();
531 }
532
533 return clientDatas;
534 }
535
536 public final boolean isVisible() {
537 return visible;
538 }
539
540 public final void setVisible(boolean visible) {
541 this.visible = visible;
542 }
543
544 public final boolean isImmediate() {
545 return immediate;
546 }
547
548 public final void setImmediate(boolean immediate) {
549 this.immediate = immediate;
550 }
551
552 public final String getBorderType() {
553 return borderType;
554 }
555
556 public final void setBorderType(String borderType) {
557 this.borderType = borderType;
558 }
559
560 public final int getTextPosition() {
561 return textPosition;
562 }
563
564 public final void setTextPosition(int textPosition) {
565 this.textPosition = textPosition;
566 }
567
568 public final String getAccessKey() {
569 return accessKey;
570 }
571
572 public final void setAccessKey(String accessKey) {
573 this.accessKey = accessKey;
574 }
575
576 public final String getAcceleratorKey() {
577 return acceleratorKey;
578 }
579
580 public final void setAcceleratorKey(String acceleratorKey) {
581 this.acceleratorKey = acceleratorKey;
582 }
583
584 public final String getMenuPopupId() {
585 return menuPopupId;
586 }
587
588 public final void setMenuPopupId(String menuPopupId) {
589 this.menuPopupId = menuPopupId;
590 }
591
592 protected void setInputType(UIComponent inputComponent) {
593 if (inputComponent instanceof IInputTypeCapability) {
594 setInputType(((IInputTypeCapability) inputComponent).getInputType());
595 }
596
597 if (inputComponent instanceof IRadioGroupCapability) {
598 String groupName = ((IRadioGroupCapability) inputComponent)
599 .getGroupName();
600 if (groupName != null) {
601 setGroupName(groupName);
602 }
603 }
604 }
605
606 public final String getWidth() {
607 return width;
608 }
609
610 public final void setWidth(String width) {
611 this.width = width;
612 }
613
614 public final String getAlternateText() {
615 return alternateText;
616 }
617
618 public final void setAlternateText(String alternateText) {
619 this.alternateText = alternateText;
620 }
621
622 public int getDragEffects() {
623 return dragEffects;
624 }
625
626 public void setDragEffects(int dragEffects) {
627 this.dragEffects = dragEffects;
628 }
629
630 public String[] getDragTypes() {
631 return dragTypes;
632 }
633
634 public void setDragTypes(String[] dragTypes) {
635 this.dragTypes = dragTypes;
636 }
637
638 public int getDragEffects(SelectItem dragItem) {
639 if (dragItem == null || equals(getValue(), dragItem.getValue())) {
640 return dragEffects;
641 }
642
643 return IDragAndDropEffects.UNKNOWN_DND_EFFECT;
644 }
645
646 public String[] getDragTypes(SelectItem dragItem) {
647 if (dragItem == null || equals(getValue(), dragItem.getValue())) {
648 return dragTypes;
649 }
650
651 return null;
652 }
653
654 public int getDropEffects() {
655 return dropEffects;
656 }
657
658 public void setDropEffects(int dropEffects) {
659 this.dropEffects = dropEffects;
660 }
661
662 public String[] getDropTypes() {
663 return dropTypes;
664 }
665
666 public void setDropTypes(String[] dropTypes) {
667 this.dropTypes = dropTypes;
668 }
669
670 public int getDropEffects(SelectItem dropItem) {
671 if (dropItem == null || equals(getValue(), dropItem.getValue())) {
672 return dropEffects;
673 }
674
675 return IDragAndDropEffects.UNKNOWN_DND_EFFECT;
676 }
677
678 public String[] getDropTypes(SelectItem dropItem) {
679 if (dropItem == null || equals(getValue(), dropItem.getValue())) {
680 return dropTypes;
681 }
682
683 return null;
684 }
685
686 private boolean equals(Object value1, Object value2) {
687 if (value1 == value2) {
688 return true;
689 }
690
691 return value1 != null && value1.equals(value2);
692 }
693
694 }