KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: SelectControlTag.java,v 1.11 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 select control
32  * allowing user to select item from a list of elements displayed in the dialog
33  * row.
34  *
35  * @version $Id: SelectControlTag.java,v 1.11 2007/01/07 06:14:28 bastafidli Exp $
36  * @author Miro Halas
37  * @code.reviewer Miro Halas
38  * @code.reviewed 1.9 2006/09/01 22:06:51 jlegeny
39  */

40 public class SelectControlTag extends BlockElementTag
41 {
42    // Attributes ///////////////////////////////////////////////////////////////
43

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

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

52    protected String JavaDoc m_strName;
53    
54    /**
55     * Number of elementes visible to user at one time. If this is 1, the control
56     * will be rendered as a combo box, otherwise it will be rendered as a list
57     * box.
58     */

59    protected String JavaDoc m_strSize;
60
61    /**
62     * Class for the select control representing this select control.
63     */

64    protected String JavaDoc m_strSelectcssclass;
65
66    /**
67     * Flag which will tells us if the button is disabled.
68     */

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

77    protected String JavaDoc m_strFocus;
78
79    /**
80     * JavaScript code to execute when the selection changes.
81     */

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

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

89    public SelectControlTag()
90    {
91       super("clsComboControl", BlockElementTag.DIV_BLOCK_ELEMENT);
92       
93       m_strName = null;
94       m_strSize = null;
95       m_strSelectcssclass = null;
96       m_strDisabled = Boolean.FALSE.toString();
97       m_strFocus = Boolean.FALSE.toString();
98       m_strOnchange = null;
99    }
100    
101    // Business logic ///////////////////////////////////////////////////////////
102

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

106    public int doStartTag(
107    ) throws JspException JavaDoc
108    {
109       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
110
111       /*
112       <span id="<%=listcontext + "filtercontrol"%>" class="clsComboControl">
113          <select id="<%=listcontext + "filter"%>" size="1">
114             <option>No filter</option>
115             <option>New filter</option>
116             <option>TODO: Feature: Implement filters</option>
117          </select>
118       </span>
119       */

120       
121       // generate content of start tag
122
doStartTag(sbHtml, "control", "");
123       
124       TagUtils.write(pageContext, sbHtml.toString());
125       
126       if (isFocusedControl())
127       {
128          // Cache the content since it should be inserted at a row
129
// boundary and not at a field boundary
130
sbHtml.delete(0, sbHtml.length());
131          sbHtml.append(getCurrentId());
132          sbHtml.append(m_strId);
133    
134          cache(TabbedDialogTag.FOCUSED_CONTROL_ID, sbHtml.toString());
135       }
136       
137       return (EVAL_BODY_INCLUDE);
138    }
139
140    /**
141     * {@inheritDoc}
142     */

143    public int doEndTag(
144    ) throws JspException JavaDoc
145    {
146       // Finish the label
147
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
148       // generate content
149
doEndTag(sbHtml);
150       
151       TagUtils.write(pageContext, sbHtml.toString());
152       
153       return (EVAL_PAGE);
154    }
155
156    /**
157     * Generate content of the buffer within the start tag
158     *
159     * @param sbHtml - string buffer the content will be generated to
160     * @param strPostfix1 - postfix added to the div id
161     * @param strPostfix2 - postfix added to the edit input control id
162     */

163    protected void doStartTag(
164       StringBuffer JavaDoc sbHtml,
165       String JavaDoc strPostfix1,
166       String JavaDoc strPostfix2
167    )
168    {
169       // Generate the start of the select control
170
sbHtml.append("<");
171       sbHtml.append(m_strType);
172       sbHtml.append(" id=\"");
173       sbHtml.append(getCurrentId());
174       sbHtml.append(m_strId);
175       sbHtml.append(strPostfix1);
176       sbHtml.append("\"");
177       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
178       {
179          sbHtml.append(" class=\"");
180          sbHtml.append(m_strCssclass);
181          sbHtml.append("\"");
182       }
183       sbHtml.append(">\n");
184       sbHtml.append("<select id=\"");
185       sbHtml.append(getCurrentId());
186       sbHtml.append(m_strId);
187       sbHtml.append(strPostfix2);
188       sbHtml.append("\"");
189       if ((m_strSelectcssclass != null) && (m_strSelectcssclass.length() > 0))
190       {
191          sbHtml.append(" class=\"");
192          sbHtml.append(m_strSelectcssclass);
193          sbHtml.append("\"");
194       }
195       if ((m_strName != null) && (m_strName.length() > 0))
196       {
197          sbHtml.append(" name=\"");
198          sbHtml.append(m_strName);
199          sbHtml.append("\"");
200       }
201       if ((m_strSize != null) && (m_strSize.length() > 0))
202       {
203          sbHtml.append(" size=\"");
204          sbHtml.append(m_strSize);
205          sbHtml.append("\"");
206       }
207       if ((m_strOnchange != null) && (m_strOnchange.length() > 0))
208       {
209          sbHtml.append(" onChange=\"");
210          sbHtml.append(m_strOnchange);
211          sbHtml.append("\"");
212       }
213       if (isDisabledControl())
214       {
215          sbHtml.append(" disabled=\"disabled\"");
216       }
217       sbHtml.append(">");
218    }
219
220    /**
221     * Generate content of the buffer within the end tag
222     *
223     * @param sbHtml - generated string buffer
224     */

225    protected void doEndTag(
226       StringBuffer JavaDoc sbHtml
227    )
228    {
229       // Generate the end of the select control
230
sbHtml.append("</select>\n</");
231       sbHtml.append(m_strType);
232       sbHtml.append(">");
233    }
234
235    /**
236     * @return String - Class for the input control representing this single line edit
237     */

238    public String JavaDoc getSelectcssclass()
239    {
240       return m_strSelectcssclass;
241    }
242    
243    /**
244     * @return String - Name of the input tag used to identify submitted data
245     */

246    public String JavaDoc getName()
247    {
248       return m_strName;
249    }
250    
251    /**
252     * @return String - Size of the input tag used to limit viewable aread.
253     */

254    public String JavaDoc getSize()
255    {
256       return m_strSize;
257    }
258    
259    /**
260     * @return String - Does this control have focus when it si displayed on the
261     * page or not.
262     */

263    public String JavaDoc getFocus()
264    {
265       return m_strFocus;
266    }
267    
268    /**
269     * @param strInputcssclass - Class for the input control representing this
270     * single line edit
271     */

272    public void setSelectcssclass(
273       String JavaDoc strInputcssclass
274    )
275    {
276       m_strSelectcssclass = strInputcssclass;
277    }
278    
279    /**
280     * @param strName - Name of the input tag used to identify submitted data
281     */

282    public void setName(
283       String JavaDoc strName
284    )
285    {
286       m_strName = strName;
287    }
288    
289    /**
290     * @param strFocus - If this control have focus when it si displayed on the
291     * page say true or 1.
292     */

293    public void setFocus(
294       String JavaDoc strFocus
295    )
296    {
297       m_strFocus = strFocus;
298    }
299    
300    /**
301     * @param bFocus - Does this control have focus when it si displayed on the
302     * page or tab.
303     */

304    public void setFocus(
305       boolean bFocus
306    )
307    {
308       m_strFocus = Boolean.toString(bFocus);
309    }
310
311    /**
312     * @param strSize - Size of the input tag used to limit viewable aread.
313     */

314    public void setSize(
315       String JavaDoc strSize
316    )
317    {
318       m_strSize = strSize;
319    }
320
321    /**
322     * @return boolean - true if this control has focus when it is displayed
323     * on a page or tab
324     */

325    public boolean isFocusedControl(
326    )
327    {
328       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus))
329              || ("1".equals(m_strFocus)));
330    }
331
332    /**
333     * @return String - If this control should be disabled then this attribute
334     * should say true or 1.
335     */

336    public String JavaDoc getDisabled(
337    )
338    {
339       return m_strDisabled;
340    }
341
342    /**
343     * @param strDisabled - If this control should be disabled then this attribute
344     * should say true or 1.
345     */

346    public void setDisabled(
347       String JavaDoc strDisabled
348    )
349    {
350       m_strDisabled = strDisabled;
351    }
352    
353    /**
354     * @param bDisabled - If this control should be disabled then this attribute
355     * should say true or 1.
356     */

357    public void setDisabled(
358       boolean bDisabled
359    )
360    {
361       m_strDisabled = Boolean.toString(bDisabled);
362    }
363
364    /**
365     * @return boolean - true if this control should be disabled
366     */

367    public boolean isDisabledControl(
368    )
369    {
370       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
371              || ("1".equals(m_strDisabled)));
372    }
373
374    /**
375     * @return String - JavaScript code to execute when the selection changes.
376     */

377    public String JavaDoc getOnchange(
378    )
379    {
380       return m_strOnchange;
381    }
382
383    /**
384     * @param strOnchange - JavaScript code to execute when the selection changes.
385     */

386    public void setOnchange(
387       String JavaDoc strOnchange
388    )
389    {
390       m_strOnchange = strOnchange;
391    }
392 }
393
Popular Tags