View Javadoc

1   package org.rcfaces.core.component;
2   
3   import org.rcfaces.core.internal.converter.LiteralDateConverter;
4   import org.rcfaces.core.internal.component.Properties;
5   import org.rcfaces.core.internal.converter.CalendarLayoutConverter;
6   import org.rcfaces.core.component.familly.IContentAccessors;
7   import java.lang.String;
8   import org.apache.commons.logging.LogFactory;
9   import org.rcfaces.core.component.capability.ICalendarLayoutCapability;
10  import java.util.Date;
11  import org.rcfaces.core.component.capability.IForCapability;
12  import javax.faces.context.FacesContext;
13  import org.rcfaces.core.internal.tools.ImageAccessorTools;
14  import org.rcfaces.core.component.capability.IHorizontalTextPositionCapability;
15  import javax.faces.convert.Converter;
16  import org.rcfaces.core.component.AbstractCalendarComponent;
17  import javax.el.ValueExpression;
18  import java.util.HashSet;
19  import org.apache.commons.logging.Log;
20  import java.util.Set;
21  import java.util.Arrays;
22  import org.rcfaces.core.component.capability.IValueChangeEventCapability;
23  import org.rcfaces.core.component.familly.IImageButtonFamilly;
24  import org.rcfaces.core.internal.converter.TextPositionConverter;
25  
26  /**
27   * <p>The dateChooser Component is a button that shows a calendar and help the user to choose a date. It can be associated to a entry field, the choosen date is then automatically entered in the field. It works like an <a href="/comps/imageButtonComponent.html">Image Button Component</a>. The dateChooser Component does <b>not</b> provide an Entry field.</p>
28   * <p>The dateChooser Component has the following capabilities :
29   * <ul>
30   * <li>IImageButtonFamilly,
31   * <li>IValueChangeEventCapability,
32   * <li>IForCapability,
33   * <li>ICalendarLayoutCapability</li>
34   * </ul>
35   * </p>
36   * 
37   * <p>The default <a href="/apidocs/index.html?org/rcfaces/core/component/DateChooserComponent.html">dateChooser</a> renderer is link to the <a href="/jsdocs/index.html?f_dateChooser.html" target="_blank">f_dateChooser</a> javascript class. f_dateChooser extends f_imageButton, fa_calendarPopup</p>
38   * 
39   * <p> Table of component style classes: </p>
40   * <table border="1" cellpadding="3" cellspacing="0" width="100%">
41   * <tbody>
42   * 
43   * <tr style="text-align:left">
44   * <th  width="33%">Style Name</th>
45   * <th width="50%">Description</th>
46   * </tr>
47   * 
48   * <tr  style="text-align:left">
49   * <td width="33%">f_dateChooser</td>
50   * <td id="ermvsh" width="50%">Defines styles for the wrapper DIV element.</td>
51   * </tr>
52   * <tr  style="text-align:left">
53   * <td width="33%">f_dateChooser_image</td>
54   * <td id="ermvsh" width="50%">Defines styles for the wrapper IMG element for the calendar icone  .</td>
55   * </tr>
56   * <tr  style="text-align:left">
57   * <td width="33%">f_dateChooser_popup</td>
58   * <td id="ermvsh" width="50%">Defines styles for the wrapper DIV element for the calendar pop-up.</td>
59   * </tr>
60   * </tbody>
61   * </table>
62   */
63  public class DateChooserComponent extends AbstractCalendarComponent implements 
64  	IImageButtonFamilly,
65  	IValueChangeEventCapability,
66  	IForCapability,
67  	ICalendarLayoutCapability {
68  
69  	private static final Log LOG = LogFactory.getLog(DateChooserComponent.class);
70  
71  	public static final String COMPONENT_TYPE="org.rcfaces.core.dateChooser";
72  
73  	protected static final Set CAMELIA_ATTRIBUTES=new HashSet(AbstractCalendarComponent.CAMELIA_ATTRIBUTES);
74  	static {
75  		CAMELIA_ATTRIBUTES.addAll(Arrays.asList(new String[] {"disabledImageURL","imageHeight","text","for","borderType","textPosition","hoverImageURL","tabIndex","popupStyleClass","defaultSelectedDate","calendarLayout","selectedImageURL","selectionListener","valueChangeListener","homeDate","readOnly","forValueFormat","border","homeDateLabel","imageURL","disabled","imageWidth"}));
76  	}
77  
78  	public DateChooserComponent() {
79  		setRendererType(COMPONENT_TYPE);
80  	}
81  
82  	public DateChooserComponent(String componentId) {
83  		this();
84  		setId(componentId);
85  	}
86  
87  	public void setHomeDate(String date) {
88  
89  
90  			engine.setProperty(Properties.HOME_DATE, date);
91  		
92  	}
93  
94  	public Date getHomeDate(FacesContext facesContext) {
95  
96  
97  			Object value=engine.getProperty(Properties.HOME_DATE, facesContext);
98  			if (value instanceof String) {
99  				value=LiteralDateConverter.SINGLETON.getAsObject(facesContext, this, (String)value);
100 			}
101 			
102 			return (Date)value;
103 		
104 	}
105 
106 	public void setDefaultSelectedDate(String date) {
107 
108 
109 			engine.setProperty(Properties.DEFAULT_SELECTED_DATE, date);
110 		
111 	}
112 
113 	public Date getDefaultSelectedDate(FacesContext facesContext) {
114 
115 
116 			Object value=engine.getProperty(Properties.DEFAULT_SELECTED_DATE, facesContext);
117 			if (value instanceof String) {
118 				value=LiteralDateConverter.SINGLETON.getAsObject(facesContext, this, (String)value);
119 			}
120 			
121 			return (Date)value;
122 		
123 	}
124 
125 	protected Converter getTextPositionConverter() {
126 
127 
128 				return TextPositionConverter.SINGLETON;
129 			
130 	}
131 
132 	public void setTextPosition(String textPosition) {
133 
134 
135 			setTextPosition(((Integer)getTextPositionConverter().getAsObject(null, this, textPosition)).intValue());
136 		
137 	}
138 
139 	public void setCalendarLayout(String layout) {
140 
141 
142 			setCalendarLayout(((Integer)CalendarLayoutConverter.SINGLETON.getAsObject(null, this, layout)).intValue());
143 		
144 	}
145 
146 	public java.lang.String getImageURL() {
147 		return getImageURL(null);
148 	}
149 
150 	/**
151 	 * See {@link #getImageURL() getImageURL()} for more details
152 	 */
153 	public java.lang.String getImageURL(javax.faces.context.FacesContext facesContext) {
154 		return engine.getStringProperty(Properties.IMAGE_URL, facesContext);
155 	}
156 
157 	/**
158 	 * Returns <code>true</code> if the attribute "imageURL" is set.
159 	 * @return <code>true</code> if the attribute is set.
160 	 */
161 	public final boolean isImageURLSetted() {
162 		return engine.isPropertySetted(Properties.IMAGE_URL);
163 	}
164 
165 	public void setImageURL(java.lang.String imageURL) {
166 		engine.setProperty(Properties.IMAGE_URL, imageURL);
167 	}
168 
169 	public java.lang.String getDisabledImageURL() {
170 		return getDisabledImageURL(null);
171 	}
172 
173 	/**
174 	 * See {@link #getDisabledImageURL() getDisabledImageURL()} for more details
175 	 */
176 	public java.lang.String getDisabledImageURL(javax.faces.context.FacesContext facesContext) {
177 		return engine.getStringProperty(Properties.DISABLED_IMAGE_URL, facesContext);
178 	}
179 
180 	/**
181 	 * Returns <code>true</code> if the attribute "disabledImageURL" is set.
182 	 * @return <code>true</code> if the attribute is set.
183 	 */
184 	public final boolean isDisabledImageURLSetted() {
185 		return engine.isPropertySetted(Properties.DISABLED_IMAGE_URL);
186 	}
187 
188 	public void setDisabledImageURL(java.lang.String disabledImageURL) {
189 		engine.setProperty(Properties.DISABLED_IMAGE_URL, disabledImageURL);
190 	}
191 
192 	public java.lang.String getHoverImageURL() {
193 		return getHoverImageURL(null);
194 	}
195 
196 	/**
197 	 * See {@link #getHoverImageURL() getHoverImageURL()} for more details
198 	 */
199 	public java.lang.String getHoverImageURL(javax.faces.context.FacesContext facesContext) {
200 		return engine.getStringProperty(Properties.HOVER_IMAGE_URL, facesContext);
201 	}
202 
203 	/**
204 	 * Returns <code>true</code> if the attribute "hoverImageURL" is set.
205 	 * @return <code>true</code> if the attribute is set.
206 	 */
207 	public final boolean isHoverImageURLSetted() {
208 		return engine.isPropertySetted(Properties.HOVER_IMAGE_URL);
209 	}
210 
211 	public void setHoverImageURL(java.lang.String hoverImageURL) {
212 		engine.setProperty(Properties.HOVER_IMAGE_URL, hoverImageURL);
213 	}
214 
215 	public java.lang.String getSelectedImageURL() {
216 		return getSelectedImageURL(null);
217 	}
218 
219 	/**
220 	 * See {@link #getSelectedImageURL() getSelectedImageURL()} for more details
221 	 */
222 	public java.lang.String getSelectedImageURL(javax.faces.context.FacesContext facesContext) {
223 		return engine.getStringProperty(Properties.SELECTED_IMAGE_URL, facesContext);
224 	}
225 
226 	/**
227 	 * Returns <code>true</code> if the attribute "selectedImageURL" is set.
228 	 * @return <code>true</code> if the attribute is set.
229 	 */
230 	public final boolean isSelectedImageURLSetted() {
231 		return engine.isPropertySetted(Properties.SELECTED_IMAGE_URL);
232 	}
233 
234 	public void setSelectedImageURL(java.lang.String selectedImageURL) {
235 		engine.setProperty(Properties.SELECTED_IMAGE_URL, selectedImageURL);
236 	}
237 
238 	public boolean isBorder() {
239 		return isBorder(null);
240 	}
241 
242 	/**
243 	 * See {@link #isBorder() isBorder()} for more details
244 	 */
245 	public boolean isBorder(javax.faces.context.FacesContext facesContext) {
246 		return engine.getBoolProperty(Properties.BORDER, true, facesContext);
247 	}
248 
249 	/**
250 	 * Returns <code>true</code> if the attribute "border" is set.
251 	 * @return <code>true</code> if the attribute is set.
252 	 */
253 	public final boolean isBorderSetted() {
254 		return engine.isPropertySetted(Properties.BORDER);
255 	}
256 
257 	public void setBorder(boolean border) {
258 		engine.setProperty(Properties.BORDER, border);
259 	}
260 
261 	public java.lang.String getBorderType() {
262 		return getBorderType(null);
263 	}
264 
265 	/**
266 	 * See {@link #getBorderType() getBorderType()} for more details
267 	 */
268 	public java.lang.String getBorderType(javax.faces.context.FacesContext facesContext) {
269 		return engine.getStringProperty(Properties.BORDER_TYPE, facesContext);
270 	}
271 
272 	/**
273 	 * Returns <code>true</code> if the attribute "borderType" is set.
274 	 * @return <code>true</code> if the attribute is set.
275 	 */
276 	public final boolean isBorderTypeSetted() {
277 		return engine.isPropertySetted(Properties.BORDER_TYPE);
278 	}
279 
280 	public void setBorderType(java.lang.String borderType) {
281 		engine.setProperty(Properties.BORDER_TYPE, borderType);
282 	}
283 
284 	public java.lang.String getText() {
285 		return getText(null);
286 	}
287 
288 	/**
289 	 * See {@link #getText() getText()} for more details
290 	 */
291 	public java.lang.String getText(javax.faces.context.FacesContext facesContext) {
292 		return engine.getStringProperty(Properties.TEXT, facesContext);
293 	}
294 
295 	/**
296 	 * Returns <code>true</code> if the attribute "text" is set.
297 	 * @return <code>true</code> if the attribute is set.
298 	 */
299 	public final boolean isTextSetted() {
300 		return engine.isPropertySetted(Properties.TEXT);
301 	}
302 
303 	public void setText(java.lang.String text) {
304 		engine.setProperty(Properties.TEXT, text);
305 	}
306 
307 	public int getTextPosition() {
308 		return getTextPosition(null);
309 	}
310 
311 	/**
312 	 * See {@link #getTextPosition() getTextPosition()} for more details
313 	 */
314 	public int getTextPosition(javax.faces.context.FacesContext facesContext) {
315 		return engine.getIntProperty(Properties.TEXT_POSITION,IHorizontalTextPositionCapability.DEFAULT_POSITION, facesContext);
316 	}
317 
318 	/**
319 	 * Returns <code>true</code> if the attribute "textPosition" is set.
320 	 * @return <code>true</code> if the attribute is set.
321 	 */
322 	public final boolean isTextPositionSetted() {
323 		return engine.isPropertySetted(Properties.TEXT_POSITION);
324 	}
325 
326 	public void setTextPosition(int textPosition) {
327 		engine.setProperty(Properties.TEXT_POSITION, textPosition);
328 	}
329 
330 	public int getImageHeight() {
331 		return getImageHeight(null);
332 	}
333 
334 	/**
335 	 * See {@link #getImageHeight() getImageHeight()} for more details
336 	 */
337 	public int getImageHeight(javax.faces.context.FacesContext facesContext) {
338 		return engine.getIntProperty(Properties.IMAGE_HEIGHT,0, facesContext);
339 	}
340 
341 	/**
342 	 * Returns <code>true</code> if the attribute "imageHeight" is set.
343 	 * @return <code>true</code> if the attribute is set.
344 	 */
345 	public final boolean isImageHeightSetted() {
346 		return engine.isPropertySetted(Properties.IMAGE_HEIGHT);
347 	}
348 
349 	public void setImageHeight(int imageHeight) {
350 		engine.setProperty(Properties.IMAGE_HEIGHT, imageHeight);
351 	}
352 
353 	public int getImageWidth() {
354 		return getImageWidth(null);
355 	}
356 
357 	/**
358 	 * See {@link #getImageWidth() getImageWidth()} for more details
359 	 */
360 	public int getImageWidth(javax.faces.context.FacesContext facesContext) {
361 		return engine.getIntProperty(Properties.IMAGE_WIDTH,0, facesContext);
362 	}
363 
364 	/**
365 	 * Returns <code>true</code> if the attribute "imageWidth" is set.
366 	 * @return <code>true</code> if the attribute is set.
367 	 */
368 	public final boolean isImageWidthSetted() {
369 		return engine.isPropertySetted(Properties.IMAGE_WIDTH);
370 	}
371 
372 	public void setImageWidth(int imageWidth) {
373 		engine.setProperty(Properties.IMAGE_WIDTH, imageWidth);
374 	}
375 
376 	public IContentAccessors getImageAccessors(FacesContext facesContext) {
377 
378 
379 			return ImageAccessorTools.createImageAccessors(facesContext, this, engine);
380 		
381 	}
382 
383 	public IContentAccessors getImageAccessors() {
384 
385 
386 			return getImageAccessors(null);
387 		
388 	}
389 
390 	public final void addValueChangeListener(javax.faces.event.ValueChangeListener listener) {
391 		addFacesListener(listener);
392 	}
393 
394 	public final void removeValueChangeListener(javax.faces.event.ValueChangeListener listener) {
395 		removeFacesListener(listener);
396 	}
397 
398 	public final javax.faces.event.FacesListener [] listValueChangeListeners() {
399 		return getFacesListeners(javax.faces.event.ValueChangeListener.class);
400 	}
401 
402 	public java.lang.String getFor() {
403 		return getFor(null);
404 	}
405 
406 	/**
407 	 * See {@link #getFor() getFor()} for more details
408 	 */
409 	public java.lang.String getFor(javax.faces.context.FacesContext facesContext) {
410 		return engine.getStringProperty(Properties.FOR, facesContext);
411 	}
412 
413 	/**
414 	 * Returns <code>true</code> if the attribute "for" is set.
415 	 * @return <code>true</code> if the attribute is set.
416 	 */
417 	public final boolean isForSetted() {
418 		return engine.isPropertySetted(Properties.FOR);
419 	}
420 
421 	public void setFor(java.lang.String forValue) {
422 		engine.setProperty(Properties.FOR, forValue);
423 	}
424 
425 	public int getCalendarLayout() {
426 		return getCalendarLayout(null);
427 	}
428 
429 	/**
430 	 * See {@link #getCalendarLayout() getCalendarLayout()} for more details
431 	 */
432 	public int getCalendarLayout(javax.faces.context.FacesContext facesContext) {
433 		return engine.getIntProperty(Properties.CALENDAR_LAYOUT,ICalendarLayoutCapability.DEFAULT_LAYOUT, facesContext);
434 	}
435 
436 	/**
437 	 * Returns <code>true</code> if the attribute "calendarLayout" is set.
438 	 * @return <code>true</code> if the attribute is set.
439 	 */
440 	public final boolean isCalendarLayoutSetted() {
441 		return engine.isPropertySetted(Properties.CALENDAR_LAYOUT);
442 	}
443 
444 	public void setCalendarLayout(int calendarLayout) {
445 		engine.setProperty(Properties.CALENDAR_LAYOUT, calendarLayout);
446 	}
447 
448 	/**
449 	 * Returns a string specifying the format to use for the value that will be send to the component specified in the <b>for</b> property.
450 	 * @return value format
451 	 */
452 	public String getForValueFormat() {
453 		return getForValueFormat(null);
454 	}
455 
456 	/**
457 	 * Returns a string specifying the format to use for the value that will be send to the component specified in the <b>for</b> property.
458 	 * @return value format
459 	 */
460 	public String getForValueFormat(javax.faces.context.FacesContext facesContext) {
461 		return engine.getStringProperty(Properties.FOR_VALUE_FORMAT, facesContext);
462 	}
463 
464 	/**
465 	 * Sets a string specifying the format to use for the value that will be send to the component specified in the <b>for</b> property.
466 	 * @param forValueFormat value format
467 	 */
468 	public void setForValueFormat(String forValueFormat) {
469 		engine.setProperty(Properties.FOR_VALUE_FORMAT, forValueFormat);
470 	}
471 
472 	/**
473 	 * Sets a string specifying the format to use for the value that will be send to the component specified in the <b>for</b> property.
474 	 * @param forValueFormat value format
475 	 */
476 	/**
477 	 * Returns <code>true</code> if the attribute "forValueFormat" is set.
478 	 * @return <code>true</code> if the attribute is set.
479 	 */
480 	public boolean isForValueFormatSetted() {
481 		return engine.isPropertySetted(Properties.FOR_VALUE_FORMAT);
482 	}
483 
484 	public java.util.Date getHomeDate() {
485 		return getHomeDate(null);
486 	}
487 
488 	public void setHomeDate(java.util.Date homeDate) {
489 		engine.setProperty(Properties.HOME_DATE, homeDate);
490 	}
491 
492 	/**
493 	 * Returns <code>true</code> if the attribute "homeDate" is set.
494 	 * @return <code>true</code> if the attribute is set.
495 	 */
496 	public boolean isHomeDateSetted() {
497 		return engine.isPropertySetted(Properties.HOME_DATE);
498 	}
499 
500 	public java.util.Date getDefaultSelectedDate() {
501 		return getDefaultSelectedDate(null);
502 	}
503 
504 	public void setDefaultSelectedDate(java.util.Date defaultSelectedDate) {
505 		engine.setProperty(Properties.DEFAULT_SELECTED_DATE, defaultSelectedDate);
506 	}
507 
508 	/**
509 	 * Returns <code>true</code> if the attribute "defaultSelectedDate" is set.
510 	 * @return <code>true</code> if the attribute is set.
511 	 */
512 	public boolean isDefaultSelectedDateSetted() {
513 		return engine.isPropertySetted(Properties.DEFAULT_SELECTED_DATE);
514 	}
515 
516 	/**
517 	 * Returns a string specifying the label associated with the home button.
518 	 * @return the label used
519 	 */
520 	public String getHomeDateLabel() {
521 		return getHomeDateLabel(null);
522 	}
523 
524 	/**
525 	 * Returns a string specifying the label associated with the home button.
526 	 * @return the label used
527 	 */
528 	public String getHomeDateLabel(javax.faces.context.FacesContext facesContext) {
529 		return engine.getStringProperty(Properties.HOME_DATE_LABEL, facesContext);
530 	}
531 
532 	/**
533 	 * Sets a string specifying the label associated with the home button.
534 	 * @param homeDateLabel the label to use
535 	 */
536 	public void setHomeDateLabel(String homeDateLabel) {
537 		engine.setProperty(Properties.HOME_DATE_LABEL, homeDateLabel);
538 	}
539 
540 	/**
541 	 * Sets a string specifying the label associated with the home button.
542 	 * @param homeDateLabel the label to use
543 	 */
544 	/**
545 	 * Returns <code>true</code> if the attribute "homeDateLabel" is set.
546 	 * @return <code>true</code> if the attribute is set.
547 	 */
548 	public boolean isHomeDateLabelSetted() {
549 		return engine.isPropertySetted(Properties.HOME_DATE_LABEL);
550 	}
551 
552 	public String getPopupStyleClass() {
553 		return getPopupStyleClass(null);
554 	}
555 
556 	public String getPopupStyleClass(javax.faces.context.FacesContext facesContext) {
557 		return engine.getStringProperty(Properties.POPUP_STYLE_CLASS, facesContext);
558 	}
559 
560 	public void setPopupStyleClass(String popupStyleClass) {
561 		engine.setProperty(Properties.POPUP_STYLE_CLASS, popupStyleClass);
562 	}
563 
564 	/**
565 	 * Returns <code>true</code> if the attribute "popupStyleClass" is set.
566 	 * @return <code>true</code> if the attribute is set.
567 	 */
568 	public boolean isPopupStyleClassSetted() {
569 		return engine.isPropertySetted(Properties.POPUP_STYLE_CLASS);
570 	}
571 
572 	protected Set getCameliaFields() {
573 		return CAMELIA_ATTRIBUTES;
574 	}
575 }