View Javadoc

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.internal.converter.WeekDaysConverter;
7   import org.rcfaces.core.lang.IAdaptable;
8   import org.rcfaces.core.component.capability.IComponentLocaleCapability;
9   import org.rcfaces.core.component.capability.ILiteralLocaleCapability;
10  import org.apache.commons.logging.LogFactory;
11  import org.rcfaces.core.component.capability.IComponentTimeZoneCapability;
12  import javax.faces.context.FacesContext;
13  import org.rcfaces.core.internal.converter.TimeZoneConverter;
14  import org.rcfaces.core.component.capability.IReadOnlyCapability;
15  import javax.faces.FacesException;
16  import org.apache.commons.logging.Log;
17  import org.rcfaces.core.internal.converter.LocaleConverter;
18  import java.util.Locale;
19  import java.util.Set;
20  import org.rcfaces.core.component.capability.ISelectionEventCapability;
21  import org.rcfaces.core.component.capability.IClientDatesStrategyCapability;
22  import org.rcfaces.core.internal.converter.LiteralTwoDigitYearConverter;
23  import org.rcfaces.core.internal.converter.ClientDatesStrategyConverter;
24  import java.util.Date;
25  import javax.el.ValueExpression;
26  import org.rcfaces.core.component.capability.ILiteralTimeZoneCapability;
27  import java.util.HashSet;
28  import java.util.Arrays;
29  import org.rcfaces.core.component.AbstractInputComponent;
30  
31  /**
32   * Technical component, used as a basis for building new RCFaces components.
33   */
34  public abstract class AbstractCalendarComponent extends AbstractInputComponent implements 
35  	ISelectionEventCapability,
36  	IReadOnlyCapability,
37  	ILiteralLocaleCapability,
38  	ILiteralTimeZoneCapability,
39  	IComponentLocaleCapability,
40  	IComponentTimeZoneCapability,
41  	IClientDatesStrategyCapability {
42  
43  	private static final Log LOG = LogFactory.getLog(AbstractCalendarComponent.class);
44  
45  	protected static final Set CAMELIA_ATTRIBUTES=new HashSet(AbstractInputComponent.CAMELIA_ATTRIBUTES);
46  	static {
47  		CAMELIA_ATTRIBUTES.addAll(Arrays.asList(new String[] {"selectionListener","literalLocale","cursorDate","readOnly","maxDate","componentTimeZone","componentLocale","literalTimeZone","disabledWeekDays","minDate","clientDatesStrategy","twoDigitYearStart"}));
48  	}
49  
50  
51  	public Date getDate() {
52  
53  
54  				Object submittedValue=getSubmittedExternalValue();
55  				if (submittedValue!=null) {
56  					return (Date)submittedValue;
57  				}
58  			
59  				Object value=getValue();
60  
61  				if (value==null) {
62  					return null;
63  				}			
64  
65  				if (value instanceof Date) {
66  					return (Date)value;
67  				}
68  								
69  				if (value instanceof String) {
70  					return (Date)LiteralDateConverter.SINGLETON.getAsObject(null, this, (String)value);
71  				}				
72  
73  				if (value instanceof IAdaptable) {
74  					Date adapted=(Date)((IAdaptable)value).getAdapter(Date.class, this);
75  					if (adapted!=null) {
76  						return adapted;
77  					}
78  				}
79  
80  
81  				throw new FacesException("Value of AbstractCalendar is not a date ! ("+value+")");
82  			
83  	}
84  
85  	public void setDate(Date date) {
86  
87  
88  				setValue(date);
89  			
90  	}
91  
92  	public void setTwoDigitYearStart(String date) {
93  
94  
95  			engine.setProperty(Properties.TWO_DIGIT_YEAR_START, date);
96  		
97  	}
98  
99  	public Date getTwoDigitYearStart(FacesContext facesContext) {
100 
101 
102 			Object value=engine.getProperty(Properties.TWO_DIGIT_YEAR_START, facesContext);
103 			if (value instanceof String) {
104 				value=LiteralTwoDigitYearConverter.SINGLETON.getAsObject(facesContext, this, (String)value);
105 			}
106 			
107 			return (Date)value;
108 		
109 	}
110 
111 	public void setClientDatesStrategy(String strategy) {
112 
113 
114 			setClientDatesStrategy(((Integer)ClientDatesStrategyConverter.SINGLETON.getAsObject(null, this, strategy)).intValue());
115 		
116 	}
117 
118 	public void setMinDate(String date) {
119 
120 
121 			engine.setProperty(Properties.MIN_DATE, date);
122 		
123 	}
124 
125 	public Date getMinDate(FacesContext facesContext) {
126 
127 
128 			Object value=engine.getProperty(Properties.MIN_DATE, facesContext);
129 			if (value instanceof String) {
130 				value=LiteralDateConverter.SINGLETON.getAsObject(facesContext, this, (String)value);
131 			}
132 			
133 			return (Date)value;
134 		
135 	}
136 
137 	public void setMaxDate(String date) {
138 
139 
140 			engine.setProperty(Properties.MAX_DATE, date);
141 		
142 	}
143 
144 	public Date getMaxDate(FacesContext facesContext) {
145 
146 
147 			Object value=engine.getProperty(Properties.MAX_DATE, facesContext);
148 			if (value instanceof String) {
149 				value=LiteralDateConverter.SINGLETON.getAsObject(facesContext, this, (String)value);
150 			}
151 			
152 			return (Date)value;
153 		
154 	}
155 
156 	public void setLiteralLocale(String locale) {
157 
158 
159 		setLiteralLocale((Locale)LocaleConverter.SINGLETON.getAsObject(null, this, locale));
160 		
161 	}
162 
163 	public void setComponentLocale(String locale) {
164 
165 
166 		setComponentLocale((Locale)LocaleConverter.SINGLETON.getAsObject(null, this, locale));
167 		
168 	}
169 
170 	public void setLiteralTimeZone(String timeZone) {
171 
172 
173 		setLiteralTimeZone((TimeZone)TimeZoneConverter.SINGLETON.getAsObject(null, this, timeZone));
174 		
175 	}
176 
177 	public void setComponentTimeZone(String timeZone) {
178 
179 
180 		setComponentTimeZone((TimeZone)TimeZoneConverter.SINGLETON.getAsObject(null, this, timeZone));
181 		
182 	}
183 
184 	public void setCursorDate(String date) {
185 
186 
187 			engine.setProperty(Properties.CURSOR_DATE, date);
188 		
189 	}
190 
191 	public Date getCursorDate(FacesContext facesContext) {
192 
193 
194 			Object value=engine.getProperty(Properties.CURSOR_DATE, facesContext);
195 			if (value instanceof String) {
196 				value=LiteralDateConverter.SINGLETON.getAsObject(facesContext, this, (String)value);
197 			}
198 			
199 			return (Date)value;
200 		
201 	}
202 
203 	public void setDisabledWeekDays(String disabledWeekDays) {
204 
205 
206 		setDisabledWeekDays(((Integer)WeekDaysConverter.SINGLETON.getAsObject(null, this, disabledWeekDays)).intValue());
207 		
208 	}
209 
210 	public final void addSelectionListener(org.rcfaces.core.event.ISelectionListener listener) {
211 		addFacesListener(listener);
212 	}
213 
214 	public final void removeSelectionListener(org.rcfaces.core.event.ISelectionListener listener) {
215 		removeFacesListener(listener);
216 	}
217 
218 	public final javax.faces.event.FacesListener [] listSelectionListeners() {
219 		return getFacesListeners(org.rcfaces.core.event.ISelectionListener.class);
220 	}
221 
222 	public boolean isReadOnly() {
223 		return isReadOnly(null);
224 	}
225 
226 	/**
227 	 * See {@link #isReadOnly() isReadOnly()} for more details
228 	 */
229 	public boolean isReadOnly(javax.faces.context.FacesContext facesContext) {
230 		return engine.getBoolProperty(Properties.READ_ONLY, false, facesContext);
231 	}
232 
233 	/**
234 	 * Returns <code>true</code> if the attribute "readOnly" is set.
235 	 * @return <code>true</code> if the attribute is set.
236 	 */
237 	public final boolean isReadOnlySetted() {
238 		return engine.isPropertySetted(Properties.READ_ONLY);
239 	}
240 
241 	public void setReadOnly(boolean readOnly) {
242 		engine.setProperty(Properties.READ_ONLY, readOnly);
243 	}
244 
245 	public java.util.Locale getLiteralLocale() {
246 		return getLiteralLocale(null);
247 	}
248 
249 	/**
250 	 * See {@link #getLiteralLocale() getLiteralLocale()} for more details
251 	 */
252 	public java.util.Locale getLiteralLocale(javax.faces.context.FacesContext facesContext) {
253 		return (java.util.Locale)engine.getProperty(Properties.LITERAL_LOCALE, facesContext);
254 	}
255 
256 	/**
257 	 * Returns <code>true</code> if the attribute "literalLocale" is set.
258 	 * @return <code>true</code> if the attribute is set.
259 	 */
260 	public final boolean isLiteralLocaleSetted() {
261 		return engine.isPropertySetted(Properties.LITERAL_LOCALE);
262 	}
263 
264 	public void setLiteralLocale(java.util.Locale literalLocale) {
265 		engine.setProperty(Properties.LITERAL_LOCALE, literalLocale);
266 	}
267 
268 	public java.util.TimeZone getLiteralTimeZone() {
269 		return getLiteralTimeZone(null);
270 	}
271 
272 	/**
273 	 * See {@link #getLiteralTimeZone() getLiteralTimeZone()} for more details
274 	 */
275 	public java.util.TimeZone getLiteralTimeZone(javax.faces.context.FacesContext facesContext) {
276 		return (java.util.TimeZone)engine.getProperty(Properties.LITERAL_TIME_ZONE, facesContext);
277 	}
278 
279 	/**
280 	 * Returns <code>true</code> if the attribute "literalTimeZone" is set.
281 	 * @return <code>true</code> if the attribute is set.
282 	 */
283 	public final boolean isLiteralTimeZoneSetted() {
284 		return engine.isPropertySetted(Properties.LITERAL_TIME_ZONE);
285 	}
286 
287 	public void setLiteralTimeZone(java.util.TimeZone literalTimeZone) {
288 		engine.setProperty(Properties.LITERAL_TIME_ZONE, literalTimeZone);
289 	}
290 
291 	public java.util.Locale getComponentLocale() {
292 		return getComponentLocale(null);
293 	}
294 
295 	/**
296 	 * See {@link #getComponentLocale() getComponentLocale()} for more details
297 	 */
298 	public java.util.Locale getComponentLocale(javax.faces.context.FacesContext facesContext) {
299 		return (java.util.Locale)engine.getProperty(Properties.COMPONENT_LOCALE, facesContext);
300 	}
301 
302 	/**
303 	 * Returns <code>true</code> if the attribute "componentLocale" is set.
304 	 * @return <code>true</code> if the attribute is set.
305 	 */
306 	public final boolean isComponentLocaleSetted() {
307 		return engine.isPropertySetted(Properties.COMPONENT_LOCALE);
308 	}
309 
310 	public void setComponentLocale(java.util.Locale componentLocale) {
311 		engine.setProperty(Properties.COMPONENT_LOCALE, componentLocale);
312 	}
313 
314 	public java.util.TimeZone getComponentTimeZone() {
315 		return getComponentTimeZone(null);
316 	}
317 
318 	/**
319 	 * See {@link #getComponentTimeZone() getComponentTimeZone()} for more details
320 	 */
321 	public java.util.TimeZone getComponentTimeZone(javax.faces.context.FacesContext facesContext) {
322 		return (java.util.TimeZone)engine.getProperty(Properties.COMPONENT_TIME_ZONE, facesContext);
323 	}
324 
325 	/**
326 	 * Returns <code>true</code> if the attribute "componentTimeZone" is set.
327 	 * @return <code>true</code> if the attribute is set.
328 	 */
329 	public final boolean isComponentTimeZoneSetted() {
330 		return engine.isPropertySetted(Properties.COMPONENT_TIME_ZONE);
331 	}
332 
333 	public void setComponentTimeZone(java.util.TimeZone componentTimeZone) {
334 		engine.setProperty(Properties.COMPONENT_TIME_ZONE, componentTimeZone);
335 	}
336 
337 	public int getClientDatesStrategy() {
338 		return getClientDatesStrategy(null);
339 	}
340 
341 	/**
342 	 * See {@link #getClientDatesStrategy() getClientDatesStrategy()} for more details
343 	 */
344 	public int getClientDatesStrategy(javax.faces.context.FacesContext facesContext) {
345 		return engine.getIntProperty(Properties.CLIENT_DATES_STRATEGY,0, facesContext);
346 	}
347 
348 	/**
349 	 * Returns <code>true</code> if the attribute "clientDatesStrategy" is set.
350 	 * @return <code>true</code> if the attribute is set.
351 	 */
352 	public final boolean isClientDatesStrategySetted() {
353 		return engine.isPropertySetted(Properties.CLIENT_DATES_STRATEGY);
354 	}
355 
356 	public void setClientDatesStrategy(int clientDatesStrategy) {
357 		engine.setProperty(Properties.CLIENT_DATES_STRATEGY, clientDatesStrategy);
358 	}
359 
360 	/**
361 	 * Returns a string value specifying the year considered as base for selecting a date when the associated dateEntry's value's year has only two digits.
362 	 * @return pivot year
363 	 */
364 	public java.util.Date getTwoDigitYearStart() {
365 		return getTwoDigitYearStart(null);
366 	}
367 
368 	/**
369 	 * Sets a string value specifying the year considered as base for selecting a date when the associated dateEntry's value's year has only two digits.
370 	 * @param twoDigitYearStart pivot year
371 	 */
372 	public void setTwoDigitYearStart(java.util.Date twoDigitYearStart) {
373 		engine.setProperty(Properties.TWO_DIGIT_YEAR_START, twoDigitYearStart);
374 	}
375 
376 	/**
377 	 * Sets a string value specifying the year considered as base for selecting a date when the associated dateEntry's value's year has only two digits.
378 	 * @param twoDigitYearStart pivot year
379 	 */
380 	/**
381 	 * Returns <code>true</code> if the attribute "twoDigitYearStart" is set.
382 	 * @return <code>true</code> if the attribute is set.
383 	 */
384 	public boolean isTwoDigitYearStartSetted() {
385 		return engine.isPropertySetted(Properties.TWO_DIGIT_YEAR_START);
386 	}
387 
388 	/**
389 	 * Returns a date value indicating the minimum acceptable date for the component. the first accepted value is minDate plus one day.
390 	 * @return min date
391 	 */
392 	public java.util.Date getMinDate() {
393 		return getMinDate(null);
394 	}
395 
396 	/**
397 	 * Sets a date value indicating the minimum acceptable date for the component. the first accepted value is minDate plus one day.
398 	 * @param minDate min date
399 	 */
400 	public void setMinDate(java.util.Date minDate) {
401 		engine.setProperty(Properties.MIN_DATE, minDate);
402 	}
403 
404 	/**
405 	 * Sets a date value indicating the minimum acceptable date for the component. the first accepted value is minDate plus one day.
406 	 * @param minDate min date
407 	 */
408 	/**
409 	 * Returns <code>true</code> if the attribute "minDate" is set.
410 	 * @return <code>true</code> if the attribute is set.
411 	 */
412 	public boolean isMinDateSetted() {
413 		return engine.isPropertySetted(Properties.MIN_DATE);
414 	}
415 
416 	/**
417 	 * Returns a date value indicating the maximum acceptable date for the component. The last accepted value is maxDate minus one day.
418 	 * @return max date
419 	 */
420 	public java.util.Date getMaxDate() {
421 		return getMaxDate(null);
422 	}
423 
424 	/**
425 	 * Sets a date value indicating the maximum acceptable date for the component. The last accepted value is maxDate minus one day.
426 	 * @param maxDate max date
427 	 */
428 	public void setMaxDate(java.util.Date maxDate) {
429 		engine.setProperty(Properties.MAX_DATE, maxDate);
430 	}
431 
432 	/**
433 	 * Sets a date value indicating the maximum acceptable date for the component. The last accepted value is maxDate minus one day.
434 	 * @param maxDate max date
435 	 */
436 	/**
437 	 * Returns <code>true</code> if the attribute "maxDate" is set.
438 	 * @return <code>true</code> if the attribute is set.
439 	 */
440 	public boolean isMaxDateSetted() {
441 		return engine.isPropertySetted(Properties.MAX_DATE);
442 	}
443 
444 	public java.util.Date getCursorDate() {
445 		return getCursorDate(null);
446 	}
447 
448 	public void setCursorDate(java.util.Date cursorDate) {
449 		engine.setProperty(Properties.CURSOR_DATE, cursorDate);
450 	}
451 
452 	/**
453 	 * Returns <code>true</code> if the attribute "cursorDate" is set.
454 	 * @return <code>true</code> if the attribute is set.
455 	 */
456 	public boolean isCursorDateSetted() {
457 		return engine.isPropertySetted(Properties.CURSOR_DATE);
458 	}
459 
460 	/**
461 	 * Returns a list of disabled week days (depending on the locale specified for the component).
462 	 * @return list of days
463 	 */
464 	public int getDisabledWeekDays() {
465 		return getDisabledWeekDays(null);
466 	}
467 
468 	/**
469 	 * Returns a list of disabled week days (depending on the locale specified for the component).
470 	 * @return list of days
471 	 */
472 	public int getDisabledWeekDays(javax.faces.context.FacesContext facesContext) {
473 		return engine.getIntProperty(Properties.DISABLED_WEEK_DAYS, 0, facesContext);
474 	}
475 
476 	/**
477 	 * Sets a list of disabled week days (depending on the locale specified for the component).
478 	 * @param disabledWeekDays list of days
479 	 */
480 	public void setDisabledWeekDays(int disabledWeekDays) {
481 		engine.setProperty(Properties.DISABLED_WEEK_DAYS, disabledWeekDays);
482 	}
483 
484 	/**
485 	 * Sets a list of disabled week days (depending on the locale specified for the component).
486 	 * @param disabledWeekDays list of days
487 	 */
488 	/**
489 	 * Returns <code>true</code> if the attribute "disabledWeekDays" is set.
490 	 * @return <code>true</code> if the attribute is set.
491 	 */
492 	public boolean isDisabledWeekDaysSetted() {
493 		return engine.isPropertySetted(Properties.DISABLED_WEEK_DAYS);
494 	}
495 
496 	protected Set getCameliaFields() {
497 		return CAMELIA_ATTRIBUTES;
498 	}
499 }