View Javadoc

1   /*
2    * $Id: DateItem.java,v 1.3 2007/04/30 08:28:58 oeuillot Exp $
3    */
4   package org.rcfaces.core.item;
5   
6   import java.util.Date;
7   import java.util.HashMap;
8   import java.util.Map;
9   
10  import javax.faces.component.UISelectItem;
11  import javax.faces.model.SelectItem;
12  
13  import org.rcfaces.core.component.DateItemComponent;
14  import org.rcfaces.core.component.capability.IClientDataCapability;
15  import org.rcfaces.core.component.capability.IServerDataCapability;
16  import org.rcfaces.core.component.capability.IStyleClassCapability;
17  import org.rcfaces.core.internal.converter.LiteralDateConverter;
18  import org.rcfaces.core.internal.util.Convertor;
19  import org.rcfaces.core.lang.Period;
20  
21  /**
22   * 
23   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
24   * @version $Revision: 1.3 $ $Date: 2007/04/30 08:28:58 $
25   */
26  public class DateItem extends SelectItem implements IDateItem {
27  
28      private static final String REVISION = "$Revision: 1.3 $";
29  
30      private static final long serialVersionUID = -2332673361111286166L;
31  
32      private String styleClass;
33  
34      private Map clientDatas;
35  
36      private Map serverDatas;
37  
38      private String menuPopupId;
39  
40      public DateItem() {
41      }
42  
43      public DateItem(IDateItem dateItem) {
44          super(dateItem.getValue(), dateItem.getLabel(), dateItem
45                  .getDescription(), dateItem.isDisabled());
46  
47          setStyleClass(dateItem.getStyleClass());
48  
49          Map map = dateItem.getClientDataMap();
50          if (map.isEmpty() == false) {
51              getClientDataMap().putAll(map);
52          }
53  
54          map = dateItem.getServerDataMap();
55          if (map.isEmpty() == false) {
56              getServerDataMap().putAll(map);
57          }
58      }
59  
60      public DateItem(UISelectItem component) {
61          super(convertValue((DateItemComponent) component), component
62                  .getItemLabel(), component.getItemDescription(), component
63                  .isItemDisabled());
64  
65          if (component instanceof IStyleClassCapability) {
66              IStyleClassCapability dateItemComponent = (IStyleClassCapability) component;
67  
68              styleClass = dateItemComponent.getStyleClass();
69          }
70  
71          if (component instanceof IServerDataCapability) {
72              IServerDataCapability serverDataCapability = (IServerDataCapability) component;
73  
74              if (serverDataCapability.getServerDataCount() > 0) {
75                  Map map = serverDataCapability.getServerDataMap();
76  
77                  getServerDataMap().putAll(map);
78              }
79          }
80  
81          if (component instanceof IClientDataCapability) {
82              IClientDataCapability clientDataCapability = (IClientDataCapability) component;
83  
84              if (clientDataCapability.getClientDataCount() > 0) {
85                  Map map = clientDataCapability.getClientDataMap();
86  
87                  getClientDataMap().putAll(map);
88              }
89          }
90      }
91  
92      private static Object convertValue(DateItemComponent component) {
93          Object value = component.getItemValue();
94  
95          if (value == null || (value instanceof Date)
96                  || (value instanceof Period)) {
97              return value;
98          }
99  
100         if (value instanceof String) {
101             return LiteralDateConverter.SINGLETON.getAsObject(null, component,
102                     (String) value);
103         }
104 
105         return Convertor.convert(value, Date.class);
106     }
107 
108     public String getStyleClass() {
109         return styleClass;
110     }
111 
112     public void setStyleClass(String styleClass) {
113         this.styleClass = styleClass;
114     }
115 
116     public boolean isClientDataEmpty() {
117         if (clientDatas == null) {
118             return true;
119         }
120 
121         return clientDatas.isEmpty();
122     }
123 
124     public Map getClientDataMap() {
125         if (clientDatas == null) {
126             clientDatas = new HashMap();
127         }
128 
129         return clientDatas;
130     }
131 
132     public boolean isServerDataEmpty() {
133         if (serverDatas == null) {
134             return true;
135         }
136 
137         return serverDatas.isEmpty();
138     }
139 
140     public Map getServerDataMap() {
141         if (serverDatas == null) {
142             serverDatas = new HashMap();
143         }
144 
145         return serverDatas;
146     }
147 
148     public final String getMenuPopupId() {
149         return menuPopupId;
150     }
151 
152     public final void setMenuPopupId(String menuPopupId) {
153         this.menuPopupId = menuPopupId;
154     }
155 
156 }