KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2006 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: MultiControlTag.java,v 1.6 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
29 /**
30  * Custom tag to generate all HTML code necessary to display dialog control
31  * consisting from multiple controls from which only one is dislayed at a time.
32  * This allows user to enter data using different type of control based on the
33  * data type, but the data can be still identified with the same label and context
34  * help. Currently this control supports only edit field and combo box.
35  *
36  * TODO: For Julo: TLD contains attribute maxlength but it is not implemented
37  * anywhere in this class. I think it is needed for the edit field so you need
38  * to add it here and implement all methods and passing it to the control. Once
39  * you do so update the TLD description for that attribute to demonstrate purpose.
40  * The same is for inputcssclass attribute in TLD.
41  *
42  * @version $Id: MultiControlTag.java,v 1.6 2007/01/07 06:14:28 bastafidli Exp $
43  * @author Julian Legeny
44  * @code.reviewer Miro Halas
45  * @code.reviewed 1.3 2006/09/05 23:36:08 jlegeny
46  */

47 public class MultiControlTag extends BlockElementTag
48 {
49    // Attributes ///////////////////////////////////////////////////////////////
50

51    /**
52     * Generated serial version id for this class.
53     */

54    private static final long serialVersionUID = 4570812626023302043L;
55
56    /**
57     * Flag specifying if a combobox control has to be generated or not as part
58     * of this multi control. Default value is true.
59     */

60    protected String JavaDoc m_strComboControl;
61
62    /**
63     * Flag specifying if an edit field control has to be generated as part of
64     * this multi control. Default value is true.
65     */

66    protected String JavaDoc m_strEditControl;
67    
68    /**
69     * Size of the input tag used to limit viewable area.
70     * TODO: For Julo: This attribute is never used.
71     */

72    protected String JavaDoc m_strSize;
73
74    /**
75     * JavaScript code to execute when the selection changes in combobox.
76     */

77    protected String JavaDoc m_strOnChangeCombo;
78
79    /**
80     * JavaScript code to execute on key up event of edit field.
81     */

82    protected String JavaDoc m_strOnKeyUpEdit;
83
84    // Constructors /////////////////////////////////////////////////////////////
85

86    /**
87     * Constructor for custom tag.
88     */

89    public MultiControlTag()
90    {
91       super("clsStrechControl", BlockElementTag.SPAN_BLOCK_ELEMENT);
92       
93       m_strComboControl = Boolean.TRUE.toString();
94       m_strEditControl = Boolean.TRUE.toString();
95       m_strSize = null;
96       m_strOnChangeCombo = null;
97       m_strOnKeyUpEdit = null;
98    }
99    
100    // Business logic ///////////////////////////////////////////////////////////
101

102    /**
103     * {@inheritDoc}
104     */

105    public int doStartTag(
106    ) throws JspException JavaDoc
107    {
108       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
109
110       if (isEditControl())
111       {
112          // Generate edit field control
113
SingleLineEditControlTag slect = new SingleLineEditControlTag();
114          if ((m_strOnKeyUpEdit != null) && (m_strOnKeyUpEdit.length() > 0))
115          {
116             slect.setOnkeyup(m_strOnKeyUpEdit);
117          }
118          slect.setPageContext(pageContext);
119          slect.doStartTag(sbHtml, "_editcontrolsection", "_editcontrol");
120          slect.doEndTag(sbHtml);
121       }
122       if (isComboControl())
123       {
124          // Generate combo box control
125
SelectControlTag sct = new SelectControlTag();
126          if ((m_strOnChangeCombo != null) && (m_strOnChangeCombo.length() > 0))
127          {
128             sct.setOnchange(m_strOnChangeCombo);
129          }
130          sct.setPageContext(pageContext);
131          sct.doStartTag(sbHtml, "_combocontrolsection", "_combocontrol");
132          sct.doEndTag(sbHtml);
133       }
134
135       TagUtils.write(pageContext, sbHtml.toString());
136
137       return (SKIP_BODY);
138    }
139
140    /**
141     * {@inheritDoc}
142     */

143    public int doEndTag(
144    ) throws JspException JavaDoc
145    {
146       return (EVAL_PAGE);
147    }
148
149    /**
150     * @return String - If combobox control should be shown then this attribute
151     * should say true or 1.
152     */

153    public String JavaDoc getCombocontrol(
154    )
155    {
156       return m_strComboControl;
157    }
158
159    /**
160     * @param strComboControl - If combobox control should be shown then this attribute
161     * should say true or 1.
162     */

163    public void setCombocontrol(
164       String JavaDoc strComboControl
165    )
166    {
167       m_strComboControl = strComboControl;
168    }
169    
170    /**
171     * @param bComboControl - If combobox control should be shown then this attribute
172     * should say true or 1.
173     */

174    public void setCombocontrol(
175       boolean bComboControl
176    )
177    {
178       m_strComboControl = Boolean.toString(bComboControl);
179    }
180    
181    /**
182     * @return boolean - true if combobox control has to be generated
183     */

184    public boolean isComboControl(
185    )
186    {
187       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strComboControl))
188              || ("1".equals(m_strComboControl)));
189    }
190
191    /**
192     * @return String - If edit control should be shown then this attribute
193     * should say true or 1.
194     */

195    public String JavaDoc getEditcontrol(
196    )
197    {
198       return m_strEditControl;
199    }
200
201    /**
202     * @param strEditControl - If edit control should be shown then this attribute
203     * should say true or 1.
204     */

205    public void setEditcontrol(
206       String JavaDoc strEditControl
207    )
208    {
209       m_strEditControl = strEditControl;
210    }
211    
212    /**
213     * @param bEditControl - If edit control should be shown then this attribute
214     * should say true or 1.
215     */

216    public void setEditcontrol(
217       boolean bEditControl
218    )
219    {
220       m_strEditControl = Boolean.toString(bEditControl);
221    }
222
223    /**
224     * @return boolean - true if combo has to be generated
225     */

226    public boolean isEditControl(
227    )
228    {
229       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strEditControl))
230              || ("1".equals(m_strEditControl)));
231    }
232    
233    /**
234     * @return String - Size of the input tag used to limit viewable area.
235     */

236    public String JavaDoc getSize()
237    {
238       return m_strSize;
239    }
240
241    /**
242     * @param strSize - Size of the input tag used to limit viewable area.
243     */

244    public void setSize(
245       String JavaDoc strSize
246    )
247    {
248       m_strSize = strSize;
249    }
250
251    /**
252     * @return String - JavaScript code to execute when the selection changes.
253     */

254    public String JavaDoc getOnchangecombo(
255    )
256    {
257       return m_strOnChangeCombo;
258    }
259
260    /**
261     * @param strOnChangeCombo - JavaScript code to execute when the selection changes.
262     */

263    public void setOnchangecombo(
264       String JavaDoc strOnChangeCombo
265    )
266    {
267       m_strOnChangeCombo = strOnChangeCombo;
268    }
269
270    /**
271     * @return String - JavaScript code to execute when the the content of edit field is changed.
272     */

273    public String JavaDoc getOnkeyupedit(
274    )
275    {
276       return m_strOnKeyUpEdit;
277    }
278
279    /**
280     * @param strOnKeyUpEdit - JavaScript code to execute on key up event of the edit field.
281     */

282    public void setOnkeyupedit(
283       String JavaDoc strOnKeyUpEdit
284    )
285    {
286       m_strOnKeyUpEdit = strOnKeyUpEdit;
287    }
288 }
289
Popular Tags