KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > dialoglayout > www > CalendarTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: CalendarTag.java,v 1.9 2007/01/07 06:14:28 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.patterns.dialoglayout.www;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25
26 import org.opensubsystems.core.www.BlockElementTag;
27 import org.opensubsystems.core.www.TagUtils;
28 import org.opensubsystems.patterns.tabbeddialog.www.TabbedDialogTag;
29
30 /**
31  * Custom tag to generate all HTML code necessary to display calendar
32  * control displayed in the dialog row (calendar consists from edit box
33  * and button that will open calendar dialog).
34  *
35  * TODO: For Julo: This tag is not used anywhere and we don't even have test
36  * page for it. Once you create a test page add an example tag to the tld
37  * demonstrating how should this tag be used.
38  *
39  * @version $Id: CalendarTag.java,v 1.9 2007/01/07 06:14:28 bastafidli Exp $
40  * @author Julian Legeny
41  * @code.reviewer Miro Halas
42  * @code.reviewed 1.6 2006/02/17 06:54:14 bastafidli
43  */

44 public class CalendarTag extends BlockElementTag
45 {
46    // Attributes ///////////////////////////////////////////////////////////////
47

48    /**
49     * Generated serial version id for this class.
50     */

51    private static final long serialVersionUID = 8205210883621738873L;
52
53    /**
54     * Name of the input tag used to identify submitted data.
55     */

56    protected String JavaDoc m_strName;
57    
58    /**
59     * Size of the input tag used to limit viewable area.
60     */

61    protected String JavaDoc m_strSize;
62
63    /**
64     * Class for the input control representing this single line edit.
65     */

66    protected String JavaDoc m_strInputcssclass;
67
68    /**
69     * Class for the button control representing this calendar control.
70     */

71    protected String JavaDoc m_strButtoncssclass;
72
73    /**
74     * Does this control have focus when it is displayed on the page or not.
75     * Only one control on a page or tab can be marked as focus at a time.
76     * If multiple controls are marked this way, then the first one on the page
77     * or tab will get the focus.
78     */

79    protected String JavaDoc m_strFocus;
80
81    /**
82     * Flag which will tells us if the input is disabled.
83     */

84    protected String JavaDoc m_strDisabled;
85
86    /**
87     * Initial value to display in the edit field of the calendar control.
88     */

89    protected String JavaDoc m_strValue;
90    
91    /**
92     * Format of the date, time or datetime that should be used for value entered
93     * using the calendar dialog.
94     * TODO: For Julo: The calendarinit tag also allows to specify the format but
95     * it is not used anywhere in this class. How do these formats relate to each
96     * other. Once you figure it out, do not forget to update the tld description.
97     */

98    protected String JavaDoc m_strDatetimeformat;
99
100    // Constructors /////////////////////////////////////////////////////////////
101

102    /**
103     * Constructor for custom tag.
104     */

105    public CalendarTag()
106    {
107       super("clsStrechControl", BlockElementTag.DIV_BLOCK_ELEMENT);
108       
109       m_strName = null;
110       m_strSize = null;
111       m_strInputcssclass = "clsStretchCalendarEdit";
112       m_strButtoncssclass = "clsCalendarButton";
113       m_strDisabled = Boolean.FALSE.toString();
114       m_strValue = null;
115       // TODO: Improve: This should be eventually determined based on localization
116
// and eventually on the type of calendar (date, time, datetime)
117
// Then we will have to resolve that on GUI different users may use
118
// different format but on the backend we will need to always store it
119
// consistently.
120
m_strDatetimeformat = null;
121    }
122    
123    // Business logic ///////////////////////////////////////////////////////////
124

125    /**
126     * {@inheritDoc}
127     */

128    public int doStartTag(
129    ) throws JspException JavaDoc
130    {
131       StringBuffer JavaDoc sbHtml = null;
132       
133       sbHtml = new StringBuffer JavaDoc();
134
135       /*
136       <div id="calendarcontrol" class="clsStrechControl">
137          <input id="calendarinputfield" class="clsStretchCalendarEdit"
138                 type="text" name="CALENDAR_TIME" size="25" maxlength="30"
139                 onKeyPress="checkIt(event, false)">
140       </div>
141       <button class="clsCalendarButton" type="button"
142               onclick="return showCalendar('calendarinputfield', 'MM/dd/yyyy HH:mm');"></button>
143       */

144       
145       // Generate the start of the tabbed dialog
146
sbHtml.append("<");
147       sbHtml.append(m_strType);
148       sbHtml.append(" id=\"");
149       sbHtml.append(getCurrentId());
150       sbHtml.append(m_strId);
151       sbHtml.append("control\"");
152       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
153       {
154          sbHtml.append(" class=\"");
155          sbHtml.append(m_strCssclass);
156          sbHtml.append("\"");
157       }
158       sbHtml.append(">\n");
159       sbHtml.append("<input id=\"");
160       sbHtml.append(getCurrentId());
161       sbHtml.append(m_strId);
162       sbHtml.append("inputfield\"");
163       if ((m_strInputcssclass != null) && (m_strInputcssclass.length() > 0))
164       {
165          sbHtml.append(" class=\"");
166          sbHtml.append(m_strInputcssclass);
167          sbHtml.append("\"");
168       }
169       sbHtml.append(" type=\"text\"");
170       if ((m_strName != null) && (m_strName.length() > 0))
171       {
172          sbHtml.append(" name=\"");
173          sbHtml.append(m_strName);
174          sbHtml.append("\"");
175       }
176       if ((m_strSize != null) && (m_strSize.length() > 0))
177       {
178          sbHtml.append(" size=\"");
179          sbHtml.append(m_strSize);
180          sbHtml.append("\"");
181       }
182       
183       // TODO: For Julo: Where are you setting this? By default this is null, so
184
// user has to set this for this to do not generate NPE. User shouldn't have
185
// to set this if it is automatically generated by CalendarInit and if it
186
// not set explicitely by user then the values generated by CalendarInit
187
// should be user.
188
// Also are you sure that maxlength = m_strDatetimeformat.length()? Is it
189
// always 1 for 1 replacement or can 1 character in format means more than
190
// 1 character in value?
191

192       // set max length from datetime format
193
sbHtml.append(" maxlength=\"");
194       sbHtml.append(m_strDatetimeformat.length());
195       sbHtml.append("\"");
196
197       if (isDisabledControl())
198       {
199          sbHtml.append(" disabled=\"disabled\"");
200       }
201       if ((m_strValue != null) && (m_strValue.length() > 0))
202       {
203          sbHtml.append(" value=\"");
204          sbHtml.append(m_strValue);
205          sbHtml.append("\"");
206       }
207       sbHtml.append(">");
208       // add button conrol
209
sbHtml.append("<button");
210       if ((m_strButtoncssclass != null) && (m_strButtoncssclass.length() > 0))
211       {
212          sbHtml.append(" class=\"");
213          sbHtml.append(m_strButtoncssclass);
214          sbHtml.append("\"");
215       }
216       sbHtml.append(" type=\"button\" onclick=\"return showCalendar('");
217       sbHtml.append(getCurrentId());
218       sbHtml.append(m_strId);
219       sbHtml.append("inputfield', '");
220       sbHtml.append(m_strDatetimeformat);
221       sbHtml.append("');\"></button>");
222
223       TagUtils.write(pageContext, sbHtml.toString());
224       
225       if (isFocusedControl())
226       {
227          // Cache the content since it should be inserted at a row
228
// boundary and not at a field boundary
229
sbHtml.delete(0, sbHtml.length());
230          sbHtml.append(getCurrentId());
231          sbHtml.append(m_strId);
232    
233          cache(TabbedDialogTag.FOCUSED_CONTROL_ID, sbHtml.toString());
234       }
235       
236       return (EVAL_BODY_INCLUDE);
237    }
238
239    /**
240     * {@inheritDoc}
241     */

242    public int doEndTag(
243    ) throws JspException JavaDoc
244    {
245       // Finish the label
246
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
247
248       sbHtml.append("</");
249       sbHtml.append(m_strType);
250       sbHtml.append(">");
251       
252       TagUtils.write(pageContext, sbHtml.toString());
253       
254       return (EVAL_PAGE);
255    }
256    
257    /**
258     * @return String - Class for the input control representing this single line edit
259     */

260    public String JavaDoc getInputcssclass()
261    {
262       return m_strInputcssclass;
263    }
264    
265    /**
266     * @return String - Class for the button control representing this calendar control
267     */

268    public String JavaDoc getButtoncssclass()
269    {
270       return m_strButtoncssclass;
271    }
272
273    /**
274     * @return String - Name of the input tag used to identify submitted data
275     */

276    public String JavaDoc getName()
277    {
278       return m_strName;
279    }
280    
281    /**
282     * @return String - Size of the input tag used to limit viewable area.
283     */

284    public String JavaDoc getSize()
285    {
286       return m_strSize;
287    }
288    
289    /**
290     * @return String - Does this control have focus when it si displayed on the
291     * page or not.
292     */

293    public String JavaDoc getFocus()
294    {
295       return m_strFocus;
296    }
297    
298    /**
299     * @param strInputcssclass - Class for the input control representing this
300     * single line edit
301     */

302    public void setInputcssclass(
303       String JavaDoc strInputcssclass
304    )
305    {
306       m_strInputcssclass = strInputcssclass;
307    }
308    
309    /**
310     * @param strButtoncssclass - Class for the button control representing this
311     * calendar control
312     *
313     */

314    public void setButtoncssclass(
315       String JavaDoc strButtoncssclass
316    )
317    {
318       m_strButtoncssclass = strButtoncssclass;
319    }
320
321    /**
322     * @param strName - Name of the input tag used to identify submitted data
323     */

324    public void setName(
325       String JavaDoc strName
326    )
327    {
328       m_strName = strName;
329    }
330    
331    /**
332     * @param strFocus - If this control have focus when it si displayed on the
333     * page say true or 1.
334     */

335    public void setFocus(
336       String JavaDoc strFocus
337    )
338    {
339       m_strFocus = strFocus;
340    }
341    
342    /**
343     * @param bFocus - Does this control have focus when it si displayed on the
344     * page or tab.
345     */

346    public void setFocus(
347       boolean bFocus
348    )
349    {
350       m_strFocus = Boolean.toString(bFocus);
351    }
352
353    /**
354     * @param strSize - Size of the input tag used to limit viewable area.
355     */

356    public void setSize(
357       String JavaDoc strSize
358    )
359    {
360       m_strSize = strSize;
361    }
362
363    /**
364     * @return boolean - true if this control has focus when it is displayed
365     * on a page or tab
366     */

367    public boolean isFocusedControl(
368    )
369    {
370       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus))
371              || ("1".equals(m_strFocus)));
372    }
373
374    /**
375     * @return String - If this control should be disabled then this attribute
376     * should say true or 1.
377     */

378    public String JavaDoc getDisabled(
379    )
380    {
381       return m_strDisabled;
382    }
383
384    /**
385     * @param strDisabled - If this control should be disabled then this attribute
386     * should say true or 1.
387     */

388    public void setDisabled(
389       String JavaDoc strDisabled
390    )
391    {
392       m_strDisabled = strDisabled;
393    }
394    
395    /**
396     * @param bDisabled - If this control should be disabled then this attribute
397     * should say true or 1.
398     */

399    public void setDisabled(
400       boolean bDisabled
401    )
402    {
403       m_strDisabled = Boolean.toString(bDisabled);
404    }
405
406    /**
407     * @return boolean - true if this control should be disabled
408     */

409    public boolean isDisabledControl(
410    )
411    {
412       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
413              || ("1".equals(m_strDisabled)));
414    }
415
416    /**
417     * @return String - Value of the input tag used to display in the edit box
418     */

419    public String JavaDoc getValue()
420    {
421       return m_strValue;
422    }
423    
424    /**
425     * @param strValue - Value of the input tag used to display in the edit box
426     */

427    public void setValue(
428       String JavaDoc strValue
429    )
430    {
431       m_strValue = strValue;
432    }
433
434    /**
435     * @return String - Value of the datetime format that display in the edit box
436     */

437    public String JavaDoc getDatetimeformat()
438    {
439       return m_strDatetimeformat;
440    }
441    
442    /**
443     * @param strDatetimeformat - Value of the datetime format that display in the edit box
444     */

445    public void setDatetimeformat(
446       String JavaDoc strDatetimeformat
447    )
448    {
449       m_strDatetimeformat = strDatetimeformat;
450    }
451 }
452
Popular Tags