KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

56    protected String JavaDoc m_strTextareacssclass;
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 which will tells us if the textarea is disabled.
68     */

69    protected String JavaDoc m_strDisabled;
70    
71    /**
72     * How many rows do display for this text area.
73     */

74    protected String JavaDoc m_strRows;
75    
76    /**
77     * How many columns do display for this text area.
78     */

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

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

86    public MultiLineEditControlTag()
87    {
88       super("clsStrechControl", BlockElementTag.DIV_BLOCK_ELEMENT);
89       
90       m_strName = null;
91       m_strTextareacssclass = "clsStretchMultiLineEdit";
92       m_strDisabled = Boolean.FALSE.toString();
93       m_strRows = "5";
94       m_strCols = "20"; // required by HTML validation but not really used
95
}
96    
97    // Business logic ///////////////////////////////////////////////////////////
98

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

102    public int doStartTag(
103    ) throws JspException JavaDoc
104    {
105       StringBuffer JavaDoc sbHtml = null;
106       
107       sbHtml = new StringBuffer JavaDoc();
108
109       /*
110       <div id="roledescriptioncontrol" class="clsStrechControl">
111          <textarea id="roledescription" class="clsStretchMultiLineEdit"
112                   rows="5" name="ROLE_DESCRIPTION"
113                   <logic:notEqual name="roledata" property="userId"
114                         value="<%= DataObject.NEW_ID_STR%>">
115                      disabled="disabled"
116                   </logic:notEqual>
117                 ><bean:write name="roledata" property="description"/></textarea>
118       </div>
119       */

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

188    public int doEndTag(
189    ) throws JspException JavaDoc
190    {
191       // Finish the label
192
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
193
194       sbHtml.append("</textarea>\n");
195       sbHtml.append("</");
196       sbHtml.append(m_strType);
197       sbHtml.append(">");
198       
199       TagUtils.write(pageContext, sbHtml.toString());
200       
201       return (EVAL_PAGE);
202    }
203    
204    /**
205     * @return String - Class for the textarea control representing this single line edit
206     */

207    public String JavaDoc getTextareacssclass()
208    {
209       return m_strTextareacssclass;
210    }
211    
212    /**
213     * @return String - Name of the textarea tag used to identify submitted data
214     */

215    public String JavaDoc getName()
216    {
217       return m_strName;
218    }
219    
220    /**
221     * @return String - Size of the textarea tag used to limit viewable aread.
222     */

223    public String JavaDoc getRows()
224    {
225       return m_strRows;
226    }
227    
228    /**
229     * @return String - Size of the textarea tag used to limit viewable aread.
230     */

231    public String JavaDoc getCols()
232    {
233       return m_strCols;
234    }
235
236    /**
237     * @return String - Does this control have focus when it si displayed on the
238     * page or not.
239     */

240    public String JavaDoc getFocus()
241    {
242       return m_strFocus;
243    }
244    
245    /**
246     * @param strInputcssclass - Class for the textarea control representing this
247     * single line edit
248     */

249    public void setTextareacssclass(
250       String JavaDoc strInputcssclass
251    )
252    {
253       m_strTextareacssclass = strInputcssclass;
254    }
255    
256    /**
257     * @param strName - Name of the textarea tag used to identify submitted data
258     */

259    public void setName(
260       String JavaDoc strName
261    )
262    {
263       m_strName = strName;
264    }
265    
266    /**
267     * @param strFocus - If this control have focus when it si displayed on the
268     * page say true or 1.
269     */

270    public void setFocus(
271       String JavaDoc strFocus
272    )
273    {
274       m_strFocus = strFocus;
275    }
276    
277    /**
278     * @param bFocus - Does this control have focus when it si displayed on the
279     * page or tab.
280     */

281    public void setFocus(
282       boolean bFocus
283    )
284    {
285       m_strFocus = Boolean.toString(bFocus);
286    }
287
288    /**
289     * @param strRows - Size of the textarea tag used to limit viewable area.
290     */

291    public void setRows(
292       String JavaDoc strRows
293    )
294    {
295       m_strRows = strRows;
296    }
297
298    /**
299     * @param strCols - Size of the textarea tag used to limit viewable area.
300     */

301    public void setCols(
302       String JavaDoc strCols
303    )
304    {
305       m_strCols = strCols;
306    }
307
308    /**
309     * @return boolean - true if this control has focus when it is displayed
310     * on a page or tab
311     */

312    public boolean isFocusedControl(
313    )
314    {
315       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus))
316              || ("1".equals(m_strFocus)));
317    }
318
319    /**
320     * @return String - If this control should be disabled then this attribute
321     * should say true or 1.
322     */

323    public String JavaDoc getDisabled(
324    )
325    {
326       return m_strDisabled;
327    }
328
329    /**
330     * @param strDisabled - If this control should be disabled then this attribute
331     * should say true or 1.
332     */

333    public void setDisabled(
334       String JavaDoc strDisabled
335    )
336    {
337       m_strDisabled = strDisabled;
338    }
339    
340    /**
341     * @param bDisabled - If this control should be disabled then this attribute
342     * should say true or 1.
343     */

344    public void setDisabled(
345       boolean bDisabled
346    )
347    {
348       m_strDisabled = Boolean.toString(bDisabled);
349    }
350
351    /**
352     * @return boolean - true if this control should be disabled
353     */

354    public boolean isDisabledControl(
355    )
356    {
357       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
358              || ("1".equals(m_strDisabled)));
359    }
360 }
361
Popular Tags