KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: CheckboxControlTag.java,v 1.8 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 checkbox
32  * control displayed in the dialog row.
33  *
34  * @version $Id: CheckboxControlTag.java,v 1.8 2007/01/07 06:14:28 bastafidli Exp $
35  * @author Miro Halas
36  * @code.reviewer Miro Halas
37  * @code.reviewed 1.6 2006/06/05 18:21:23 bastafidli
38  */

39 public class CheckboxControlTag extends BlockElementTag
40 {
41    // Attributes ///////////////////////////////////////////////////////////////
42

43    /**
44     * Generated serial version id for this class.
45     */

46    private static final long serialVersionUID = 1538983390825246894L;
47
48    /**
49     * Name of the input tag used to identify submitted data
50     */

51    protected String JavaDoc m_strName;
52    
53    /**
54     * Class for the input control representing this single line edit.
55     */

56    protected String JavaDoc m_strCheckboxcssclass;
57
58    /**
59     * Does this control have focus when it is displayed on the page or not.
60     * Only one control on a page or tab can be marked as focus at a time.
61     * If multiple controls are marked this way, then the first one on the page
62     * or tab will get the focus.
63     */

64    protected String JavaDoc m_strFocus;
65
66    /**
67     * Flag specifying if the checkbox is checked.
68     */

69    protected String JavaDoc m_strChecked;
70
71    /**
72     * Flag specifying if the checkbox is disabled.
73     */

74    protected String JavaDoc m_strDisabled;
75
76    /**
77     * JavaScript code to execute when the check state changes.
78     */

79    protected String JavaDoc m_strOnchange;
80
81    // Constructors /////////////////////////////////////////////////////////////
82

83    /**
84     * Constructor for custom tag.
85     */

86    public CheckboxControlTag()
87    {
88       super("clsStrechControl", BlockElementTag.DIV_BLOCK_ELEMENT);
89
90       m_strName = null;
91       m_strCheckboxcssclass = "";
92       m_strStyle = "";
93       m_strDisabled = Boolean.FALSE.toString();
94       m_strDisabled = Boolean.FALSE.toString();
95       m_strOnchange = null;
96    }
97    
98    // Business logic ///////////////////////////////////////////////////////////
99

100    /**
101     * {@inheritDoc}
102     */

103    public int doStartTag(
104    ) throws JspException JavaDoc
105    {
106       StringBuffer JavaDoc sbHtml = null;
107       
108       sbHtml = new StringBuffer JavaDoc();
109
110       /*
111       <div id="roleenabledcontrol" class="clsStrechControl">
112          <input id="roleenabled" type="checkbox"
113                   name="ROLE_ENABLED"<%= (roledata.isEnabled() ? " checked" : "") %>
114                   <logic:notEqual name="roledata" property="userId"
115                         value="<%= DataObject.NEW_ID_STR%>">
116                      disabled="disabled"
117                   </logic:notEqual>
118                   >
119       </div>
120       */

121       
122       // Generate the start of the tabbed dialog
123
sbHtml.append("<");
124       sbHtml.append(m_strType);
125       sbHtml.append(" id=\"");
126       sbHtml.append(getCurrentId());
127       sbHtml.append(m_strId);
128       sbHtml.append("control\"");
129       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
130       {
131          sbHtml.append(" class=\"");
132          sbHtml.append(m_strCssclass);
133          sbHtml.append("\"");
134       }
135       if ((m_strStyle != null) && (m_strStyle.length() > 0))
136       {
137          sbHtml.append(" style=\"");
138          sbHtml.append(m_strStyle);
139          sbHtml.append("\"");
140       }
141       sbHtml.append(">\n");
142       sbHtml.append("<input id=\"");
143       sbHtml.append(getCurrentId());
144       sbHtml.append(m_strId);
145       sbHtml.append("\"");
146       if ((m_strCheckboxcssclass != null) && (m_strCheckboxcssclass.length() > 0))
147       {
148          sbHtml.append(" class=\"");
149          sbHtml.append(m_strCheckboxcssclass);
150          sbHtml.append("\"");
151       }
152       sbHtml.append(" type=\"checkbox\"");
153       if ((m_strName != null) && (m_strName.length() > 0))
154       {
155          sbHtml.append(" name=\"");
156          sbHtml.append(m_strName);
157          sbHtml.append("\"");
158       }
159       if ((m_strOnchange != null) && (m_strOnchange.length() > 0))
160       {
161          sbHtml.append(" onChange=\"");
162          sbHtml.append(m_strOnchange);
163          sbHtml.append("\"");
164       }
165       if (isDisabledControl())
166       {
167          sbHtml.append(" disabled=\"disabled\"");
168       }
169       if (isCheckedControl())
170       {
171          sbHtml.append(" checked");
172       }
173       sbHtml.append("/>");
174       
175       TagUtils.write(pageContext, sbHtml.toString());
176       
177       if (isFocusedControl())
178       {
179          // Cache the content since it should be inserted at a row
180
// boundary and not at a field boundary
181
sbHtml.delete(0, sbHtml.length());
182          sbHtml.append(getCurrentId());
183          sbHtml.append(m_strId);
184    
185          cache(TabbedDialogTag.FOCUSED_CONTROL_ID, sbHtml.toString());
186       }
187       
188       return (EVAL_BODY_INCLUDE);
189    }
190
191    /**
192     * {@inheritDoc}
193     */

194    public int doEndTag(
195    ) throws JspException JavaDoc
196    {
197       // Finish the label
198
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
199
200       sbHtml.append("</");
201       sbHtml.append(m_strType);
202       sbHtml.append(">");
203       
204       TagUtils.write(pageContext, sbHtml.toString());
205       
206       return (EVAL_PAGE);
207    }
208    
209    /**
210     * @return String - Class for the input control representing this single line edit
211     */

212    public String JavaDoc getCheckboxcssclass()
213    {
214       return m_strCheckboxcssclass;
215    }
216    
217    /**
218     * @return String - Name of the input tag used to identify submitted data
219     */

220    public String JavaDoc getName()
221    {
222       return m_strName;
223    }
224    
225    /**
226     * @return String - Does this control have focus when it si displayed on the
227     * page or not.
228     */

229    public String JavaDoc getFocus()
230    {
231       return m_strFocus;
232    }
233    
234    /**
235     * @param strInputcssclass - Class for the input control representing this
236     * single line edit
237     */

238    public void setCheckboxcssclass(
239       String JavaDoc strInputcssclass
240    )
241    {
242       m_strCheckboxcssclass = strInputcssclass;
243    }
244    
245    /**
246     * @param strName - Name of the input tag used to identify submitted data
247     */

248    public void setName(
249       String JavaDoc strName
250    )
251    {
252       m_strName = strName;
253    }
254    
255    /**
256     * @param strFocus - If this control have focus when it si displayed on the
257     * page say true or 1.
258     */

259    public void setFocus(
260       String JavaDoc strFocus
261    )
262    {
263       m_strFocus = strFocus;
264    }
265    
266    /**
267     * @param bFocus - Does this control have focus when it si displayed on the
268     * page or tab.
269     */

270    public void setFocus(
271       boolean bFocus
272    )
273    {
274       m_strFocus = Boolean.toString(bFocus);
275    }
276
277    /**
278     * @return boolean - true if this control has focus when it is displayed
279     * on a page or tab
280     */

281    public boolean isFocusedControl(
282    )
283    {
284       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus))
285              || ("1".equals(m_strFocus)));
286    }
287
288    /**
289     * @return String - If this control should be disabled then this attribute
290     * should say true or 1.
291     */

292    public String JavaDoc getDisabled(
293    )
294    {
295       return m_strDisabled;
296    }
297
298    /**
299     * @param strDisabled - If this control should be disabled then this attribute
300     * should say true or 1.
301     */

302    public void setDisabled(
303       String JavaDoc strDisabled
304    )
305    {
306       m_strDisabled = strDisabled;
307    }
308    
309    /**
310     * @param bDisabled - If this control should be disabled then this attribute
311     * should say true or 1.
312     */

313    public void setDisabled(
314       boolean bDisabled
315    )
316    {
317       m_strDisabled = Boolean.toString(bDisabled);
318    }
319
320    /**
321     * @return boolean - true if this control should be disabled
322     */

323    public boolean isDisabledControl(
324    )
325    {
326       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
327              || ("1".equals(m_strDisabled)));
328    }
329
330    /**
331     * @return String - JavaScript code to execute when the selection changes.
332     */

333    public String JavaDoc getOnchange(
334    )
335    {
336       return m_strOnchange;
337    }
338
339    /**
340     * @param strOnchange - JavaScript code to execute when the selection changes.
341     */

342    public void setOnchange(
343       String JavaDoc strOnchange
344    )
345    {
346       m_strOnchange = strOnchange;
347    }
348
349    /**
350     * @return String - If this control should be checked then this attribute
351     * should say true or 1.
352     */

353    public String JavaDoc getChecked(
354    )
355    {
356       return m_strDisabled;
357    }
358
359    /**
360     * @param strChecked - If this control should be checked then this attribute
361     * should say true or 1.
362     */

363    public void setChecked(
364       String JavaDoc strChecked
365    )
366    {
367       m_strChecked = strChecked;
368    }
369    
370    /**
371     * @param bChecked - If this control should be checked then this attribute
372     * should say true or 1.
373     */

374    public void setChecked(
375       boolean bChecked
376    )
377    {
378       m_strChecked = Boolean.toString(bChecked);
379    }
380
381    /**
382     * @return boolean - true if this control should be checked
383     */

384    public boolean isCheckedControl(
385    )
386    {
387       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strChecked))
388              || ("1".equals(m_strChecked)));
389    }
390 }
391
Popular Tags