1 package org.rcfaces.core.component;
2
3 import java.util.TimeZone;
4 import org.rcfaces.core.internal.converter.LiteralDateConverter;
5 import org.rcfaces.core.internal.component.Properties;
6 import org.rcfaces.core.lang.IAdaptable;
7 import org.rcfaces.core.component.capability.IMenuPopupIdCapability;
8 import java.lang.String;
9 import org.apache.commons.logging.LogFactory;
10 import org.rcfaces.core.component.capability.ILiteralLocaleCapability;
11 import java.util.Date;
12 import org.rcfaces.core.component.SelectItemComponent;
13 import org.rcfaces.core.internal.converter.TimeZoneConverter;
14 import javax.faces.FacesException;
15 import javax.el.ValueExpression;
16 import org.rcfaces.core.internal.converter.LocaleConverter;
17 import java.util.HashSet;
18 import org.apache.commons.logging.Log;
19 import org.rcfaces.core.component.capability.ILiteralTimeZoneCapability;
20 import java.util.Locale;
21 import org.rcfaces.core.component.capability.IStyleClassCapability;
22 import java.util.Set;
23 import java.util.Arrays;
24 import org.rcfaces.core.component.capability.ITextCapability;
25
26
27
28
29 public class DateItemComponent extends SelectItemComponent implements
30 ITextCapability,
31 IStyleClassCapability,
32 IMenuPopupIdCapability,
33 ILiteralLocaleCapability,
34 ILiteralTimeZoneCapability {
35
36 private static final Log LOG = LogFactory.getLog(DateItemComponent.class);
37
38 public static final String COMPONENT_TYPE="org.rcfaces.core.dateItem";
39
40 protected static final Set CAMELIA_ATTRIBUTES=new HashSet(SelectItemComponent.CAMELIA_ATTRIBUTES);
41 static {
42 CAMELIA_ATTRIBUTES.addAll(Arrays.asList(new String[] {"literalLocale","text","menuPopupId","literalTimeZone","styleClass","date"}));
43 }
44
45 public DateItemComponent() {
46 setRendererType(null);
47 }
48
49 public DateItemComponent(String componentId) {
50 this();
51 setId(componentId);
52 }
53
54 public Date getDate() {
55
56
57 Object value=getItemValue();
58
59 if (value==null) {
60 return null;
61 }
62
63 if (value instanceof Date) {
64 return (Date)value;
65 }
66
67 if (value instanceof String) {
68 return (Date)LiteralDateConverter.SINGLETON.getAsObject(null, this, (String)value);
69 }
70
71 if (value instanceof IAdaptable) {
72 Date adapted=(Date)((IAdaptable)value).getAdapter(Date.class, this);
73 if (adapted!=null) {
74 return adapted;
75 }
76 }
77
78 throw new FacesException("ItemValue of DateItem is not a date ! ("+value+")");
79
80 }
81
82 public void setDate(Date date) {
83
84
85 setItemValue(date);
86
87 }
88
89 public void setDate(String date) {
90
91
92 setItemValue(date);
93
94 }
95
96 public void setText(String text) {
97
98
99 setItemLabel(text);
100
101 }
102
103 public String getText() {
104
105
106 return getItemLabel();
107
108 }
109
110 public void setLiteralLocale(String locale) {
111
112
113 setLiteralLocale((Locale)LocaleConverter.SINGLETON.getAsObject(null, this, locale));
114
115 }
116
117 public void setLiteralTimeZone(String timeZone) {
118
119
120 setLiteralTimeZone((TimeZone)TimeZoneConverter.SINGLETON.getAsObject(null, this, timeZone));
121
122 }
123
124
125
126
127
128 public final boolean isTextSetted() {
129 return engine.isPropertySetted(Properties.TEXT);
130 }
131
132 public java.lang.String getStyleClass() {
133 return getStyleClass(null);
134 }
135
136
137
138
139 public java.lang.String getStyleClass(javax.faces.context.FacesContext facesContext) {
140 return engine.getStringProperty(Properties.STYLE_CLASS, facesContext);
141 }
142
143
144
145
146
147 public final boolean isStyleClassSetted() {
148 return engine.isPropertySetted(Properties.STYLE_CLASS);
149 }
150
151 public void setStyleClass(java.lang.String styleClass) {
152 engine.setProperty(Properties.STYLE_CLASS, styleClass);
153 }
154
155 public java.lang.String getMenuPopupId() {
156 return getMenuPopupId(null);
157 }
158
159
160
161
162 public java.lang.String getMenuPopupId(javax.faces.context.FacesContext facesContext) {
163 return engine.getStringProperty(Properties.MENU_POPUP_ID, facesContext);
164 }
165
166
167
168
169
170 public final boolean isMenuPopupIdSetted() {
171 return engine.isPropertySetted(Properties.MENU_POPUP_ID);
172 }
173
174 public void setMenuPopupId(java.lang.String menuPopupId) {
175 engine.setProperty(Properties.MENU_POPUP_ID, menuPopupId);
176 }
177
178 public java.util.Locale getLiteralLocale() {
179 return getLiteralLocale(null);
180 }
181
182
183
184
185 public java.util.Locale getLiteralLocale(javax.faces.context.FacesContext facesContext) {
186 return (java.util.Locale)engine.getProperty(Properties.LITERAL_LOCALE, facesContext);
187 }
188
189
190
191
192
193 public final boolean isLiteralLocaleSetted() {
194 return engine.isPropertySetted(Properties.LITERAL_LOCALE);
195 }
196
197 public void setLiteralLocale(java.util.Locale literalLocale) {
198 engine.setProperty(Properties.LITERAL_LOCALE, literalLocale);
199 }
200
201 public java.util.TimeZone getLiteralTimeZone() {
202 return getLiteralTimeZone(null);
203 }
204
205
206
207
208 public java.util.TimeZone getLiteralTimeZone(javax.faces.context.FacesContext facesContext) {
209 return (java.util.TimeZone)engine.getProperty(Properties.LITERAL_TIME_ZONE, facesContext);
210 }
211
212
213
214
215
216 public final boolean isLiteralTimeZoneSetted() {
217 return engine.isPropertySetted(Properties.LITERAL_TIME_ZONE);
218 }
219
220 public void setLiteralTimeZone(java.util.TimeZone literalTimeZone) {
221 engine.setProperty(Properties.LITERAL_TIME_ZONE, literalTimeZone);
222 }
223
224 protected Set getCameliaFields() {
225 return CAMELIA_ATTRIBUTES;
226 }
227
228 public void setValueExpression(String name, ValueExpression binding) {
229 if (Properties.TEXT.equals(name)) {
230 name=Properties.ITEM_LABEL;
231
232 } else if (Properties.DATE.equals(name)) {
233 name=Properties.ITEM_VALUE;
234 }
235 super.setValueExpression(name, binding);
236 }
237 }