KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: DoubleSelectLeftHalfTag.java,v 1.18 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 left half of the
32  * double select control allowing user to move items between left and right list.
33  * The generated code will display the left select list with buttons allowing to
34  * move items between 2 select lists. The list and the controls will be displayed
35  * in the left half of where the entire control should be generated. The content
36  * of the body of this tag will be used to generate the content of this list.
37  *
38  * TODO: For Julo: The tag allows to specify cssclass attribute but this
39  * attribute is used nowhere in the code. This attribute should be used as the
40  * class for the column instead of m_strDoubleselectcssclass.
41  * m_strDoubleselectcssclass should be used as a class for the select control
42  * and not on the column. We are also missing class for the buttons.
43  *
44  * @version $Id: DoubleSelectLeftHalfTag.java,v 1.18 2007/01/07 06:14:28 bastafidli Exp $
45  * @author Julian Legeny
46  * @code.reviewer Miro Halas
47  * @code.reviewed 1.13 2006/02/18 05:29:32 bastafidli
48  */

49 public class DoubleSelectLeftHalfTag extends BlockElementTag
50 {
51    // Attributes ///////////////////////////////////////////////////////////////
52

53    /**
54     * Generated serial version id for this class.
55     */

56    private static final long serialVersionUID = 6079284091799337577L;
57
58    /**
59     * Class for the left part of the double select control.
60     */

61    protected String JavaDoc m_strDoubleselectcssclass;
62
63    /**
64     * Class for the buttons belonging to the left half of double select control.
65     */

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

74    protected String JavaDoc m_strFocus;
75
76    /**
77     * Flag which will tells us if the buttons are disabled.
78     * TODO: For Julo: The description of this flag doesn't reflect the usage.
79     * It actually disables the select and not the buttons. This is not correct.
80     * Why would you want to disable left half and not the right half. It it
81     * should work on both, you should implement it as a flag of DoubleSelectTag
82     * class and just use it here. Once you fix it do not forget to put correct
83     * description of all changes for attributes and tags to the tld file.
84     */

85    protected String JavaDoc m_strDisabled;
86
87    /**
88     * Size of the select list specifying how many items are visible at once.
89     */

90    protected String JavaDoc m_strSize;
91
92    // Constructors /////////////////////////////////////////////////////////////
93

94    /**
95     * Constructor for custom tag.
96     */

97    public DoubleSelectLeftHalfTag()
98    {
99       super("clsDialogRowLeftHalf", BlockElementTag.DIV_BLOCK_ELEMENT);
100       
101       m_strSize = "8";
102       m_strDoubleselectcssclass = "clsDoubleSelectListColumnLeft";
103       m_strDoubleselectbuttonscssclass = "clsDoubleSelectListButtonColumnLeft";
104       m_strDisabled = Boolean.FALSE.toString();
105    }
106    
107    // Business logic ///////////////////////////////////////////////////////////
108

109    /**
110     * {@inheritDoc}
111     */

112    public int doStartTag(
113    ) throws JspException JavaDoc
114    {
115       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
116
117       // getCurrentId() is faitly expensive so we call it just once
118
// and then we reuse the results.
119
String JavaDoc strCurrentId = getCurrentId();
120
121       /*
122       <div class="clsDialogRowLeftHalf">
123         <div class="clsDoubleSelectListButtonColumnLeft">
124            <div><button class="clsImageRightTextButton" type="button"
125               id="XXX_dsadd" onclick="moveBetweenLists('dsid', 'sourcelist',
126               'destlist', false, 'XXX_assigned_items', false);"
127                accesskey="A">Add</button></div>
128            <div><button class="clsImageMoveRightAllTextButton" type="button"
129               id="XXX_dsaddall" onclick="moveBetweenLists('dsid', 'sourcelist',
130               'destlist', true, 'XXX_assigned_items', false);"
131               accesskey="l">Add all</button></div>
132            <div><button class="clsImageLeftTextButton" type="button"
133               id="XXX_dsremove" onclick="moveBetweenLists('dsid', 'destlist',
134               'sourcelist', false, 'XXX_assigned_items', true);"
135               accesskey="m">Remove</button></div>
136            <div><button class="clsImageMoveLeftAllTextButton" type="button"
137               id="XXX_dsremoveall" onclick="moveBetweenLists('dsid', 'destlist',
138               'sourcelist', true, 'XXX_assigned_items', true);"
139               accesskey="v">Remove all</button></div>
140         </div>
141         <div class="clsDoubleSelectListColumnLeft">
142            <select multiple class="clsStretchSingleLineEdit" id="sourcelist" size="8"
143            onchange="changeDSButtons('dsid', 'destlist', 'sourcelist');"
144            ondblclick="moveBetweenLists('dsid', 'sourcelist', 'destlist',
145                                         false, 'XXX_assigned_items', false);">
146               
147               <!-- options are defined within the jsp -->
148               
149            </select>
150         </div>
151       </div>
152       */

153       
154       // Generate the start of the double select left half control
155
sbHtml.append("<");
156       sbHtml.append(m_strType);
157       sbHtml.append(" id=\"");
158       sbHtml.append(strCurrentId);
159       sbHtml.append(m_strId);
160       sbHtml.append("doubleselectlefthalf\" class=\"clsDialogRowLeftHalf\">\n");
161
162       sbHtml.append("<");
163       sbHtml.append(m_strType);
164       if ((m_strDoubleselectbuttonscssclass != null)
165            && (m_strDoubleselectbuttonscssclass.length() > 0))
166       {
167          sbHtml.append(" class=\"");
168          sbHtml.append(m_strDoubleselectbuttonscssclass);
169          sbHtml.append("\"");
170       }
171       sbHtml.append(">\n");
172       // add button 'Add'
173
sbHtml.append("<div><button class=\"clsImageRightTextButton\"" +
174                     " type=\"button\" accesskey=\"A\" id=\"");
175       sbHtml.append(strCurrentId);
176       sbHtml.append(m_strId);
177       sbHtml.append("_dsadd\" onclick=\"moveBetweenLists('");
178       sbHtml.append(strCurrentId);
179       sbHtml.append(m_strId);
180       sbHtml.append("', '");
181       sbHtml.append(strCurrentId);
182       sbHtml.append(m_strId);
183       sbHtml.append("doubleselectsource', '");
184       sbHtml.append(strCurrentId);
185       sbHtml.append(m_strId);
186       sbHtml.append("doubleselectdestination', false, '");
187       sbHtml.append(strCurrentId);
188       sbHtml.append(m_strId);
189       sbHtml.append("_assigned_items', false);\"><u>A</u>dd</button></div>\n");
190       // add button 'Add all'
191
sbHtml.append("<div><button class=\"clsImageMoveRightAllTextButton\" type=\"button\"" +
192                     " accesskey=\"l\" id=\"");
193       sbHtml.append(strCurrentId);
194       sbHtml.append(m_strId);
195       sbHtml.append("_dsaddall\" onclick=\"moveBetweenLists('");
196       sbHtml.append(strCurrentId);
197       sbHtml.append(m_strId);
198       sbHtml.append("', '");
199       sbHtml.append(strCurrentId);
200       sbHtml.append(m_strId);
201       sbHtml.append("doubleselectsource', '");
202       sbHtml.append(strCurrentId);
203       sbHtml.append(m_strId);
204       sbHtml.append("doubleselectdestination', true, '");
205       sbHtml.append(strCurrentId);
206       sbHtml.append(m_strId);
207       sbHtml.append("_assigned_items', false);\">Add a<u>l</u>l</button></div>\n");
208       // add button 'Remove'
209
sbHtml.append("<div><button class=\"clsImageLeftTextButton\" type=\"button\"" +
210                     " accesskey=\"m\" id=\"");
211       sbHtml.append(strCurrentId);
212       sbHtml.append(m_strId);
213       sbHtml.append("_dsremove\" onclick=\"moveBetweenLists('");
214       sbHtml.append(strCurrentId);
215       sbHtml.append(m_strId);
216       sbHtml.append("', '");
217       sbHtml.append(strCurrentId);
218       sbHtml.append(m_strId);
219       sbHtml.append("doubleselectdestination', '");
220       sbHtml.append(strCurrentId);
221       sbHtml.append(m_strId);
222       sbHtml.append("doubleselectsource', false, '");
223       sbHtml.append(strCurrentId);
224       sbHtml.append(m_strId);
225       sbHtml.append("_assigned_items', true);\">Re<u>m</u>ove</button></div>\n");
226       // Add button 'Remove all'
227
sbHtml.append("<div><button class=\"clsImageMoveLeftAllTextButton\" type=\"button\"" +
228                     " accesskey=\"v\" id=\"");
229       sbHtml.append(strCurrentId);
230       sbHtml.append(m_strId);
231       sbHtml.append("_dsremoveall\" onclick=\"moveBetweenLists('");
232       sbHtml.append(strCurrentId);
233       sbHtml.append(m_strId);
234       sbHtml.append("', '");
235       sbHtml.append(strCurrentId);
236       sbHtml.append(m_strId);
237       sbHtml.append("doubleselectdestination', '");
238       sbHtml.append(strCurrentId);
239       sbHtml.append(m_strId);
240       sbHtml.append("doubleselectsource', true, '");
241       sbHtml.append(strCurrentId);
242       sbHtml.append(m_strId);
243       sbHtml.append("_assigned_items', true);\">Remo<u>v</u>e all</button></div>\n");
244
245       sbHtml.append("</");
246       sbHtml.append(m_strType);
247       sbHtml.append(">\n");
248
249       sbHtml.append("<");
250       sbHtml.append(m_strType);
251       sbHtml.append(" id=\"");
252       sbHtml.append(strCurrentId);
253       sbHtml.append(m_strId);
254       sbHtml.append("doubleselectleftcolumn\"");
255       if ((m_strDoubleselectcssclass != null) && (m_strDoubleselectcssclass.length() > 0))
256       {
257          sbHtml.append(" class=\"");
258          sbHtml.append(m_strDoubleselectcssclass);
259          sbHtml.append("\"");
260       }
261       sbHtml.append(">\n");
262
263       sbHtml.append("<select multiple id=\"");
264       sbHtml.append(strCurrentId);
265       sbHtml.append(m_strId);
266       sbHtml.append("doubleselectsource\" class=\"clsStretchSingleLineEdit\" size=\"");
267       sbHtml.append(m_strSize);
268       sbHtml.append("\" ondblclick=\"moveBetweenLists('");
269       sbHtml.append(strCurrentId);
270       sbHtml.append(m_strId);
271       sbHtml.append("', '");
272       sbHtml.append(strCurrentId);
273       sbHtml.append(m_strId);
274       sbHtml.append("doubleselectsource', '");
275       sbHtml.append(strCurrentId);
276       sbHtml.append(m_strId);
277       sbHtml.append("doubleselectdestination', false, '");
278       sbHtml.append(strCurrentId);
279       sbHtml.append(m_strId);
280       sbHtml.append("_assigned_items', false);\" onchange=\"changeDSButtons('");
281       sbHtml.append(strCurrentId);
282       sbHtml.append(m_strId);
283       sbHtml.append("','");
284       sbHtml.append(strCurrentId);
285       sbHtml.append(m_strId);
286       sbHtml.append("doubleselectsource', '");
287       sbHtml.append(strCurrentId);
288       sbHtml.append(m_strId);
289       sbHtml.append("doubleselectdestination');\"");
290
291       if (isDisabledControl())
292       {
293          sbHtml.append(" disabled=\"disabled\"");
294       }
295       sbHtml.append(">\n");
296
297       TagUtils.write(pageContext, sbHtml.toString());
298       
299       if (isFocusedControl())
300       {
301          // TODO: For Julo: Did you tested that the focus actually works? The
302
// elect control has a different id than the one you are setting here
303
// so how it is possible to set the focus to the left half of the
304
// control to the list?
305

306          // Cache the content since it should be inserted at a row
307
// boundary and not at a field boundary
308
sbHtml.delete(0, sbHtml.length());
309          sbHtml.append(strCurrentId);
310          sbHtml.append(m_strId);
311    
312          cache(TabbedDialogTag.FOCUSED_CONTROL_ID, sbHtml.toString());
313       }
314       
315       return (EVAL_BODY_INCLUDE);
316    }
317
318    /**
319     * {@inheritDoc}
320     */

321    public int doEndTag(
322    ) throws JspException JavaDoc
323    {
324       // Finish the label
325
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
326       
327       sbHtml.append("</select>\n");
328       sbHtml.append("</");
329       sbHtml.append(m_strType);
330       sbHtml.append(">\n");
331       
332
333       sbHtml.append("</");
334       sbHtml.append(m_strType);
335       sbHtml.append(">");
336       
337       TagUtils.write(pageContext, sbHtml.toString());
338       
339       return (EVAL_PAGE);
340    }
341    
342    /**
343     * @return String - Class for the double select left control
344     */

345    public String JavaDoc getDoubleselectcssclass()
346    {
347       return m_strDoubleselectcssclass;
348    }
349    
350    /**
351     * @return String - Class for the buttons belonging to the double select left control
352     */

353    public String JavaDoc getDoubleselectbuttonscssclass()
354    {
355       return m_strDoubleselectbuttonscssclass;
356    }
357
358    /**
359     * @return String - Does this control have focus when it si displayed on the
360     * page or not.
361     */

362    public String JavaDoc getFocus()
363    {
364       return m_strFocus;
365    }
366    
367    /**
368     * @param strDoubleselectcssclass - Class for the left double select control
369     */

370    public void setDoubleselectcssclass(
371       String JavaDoc strDoubleselectcssclass
372    )
373    {
374       m_strDoubleselectcssclass = strDoubleselectcssclass;
375    }
376    
377    /**
378     * @param strDoubleselectbuttonscssclass - Class for the buttons belonging to the
379     * left double select control
380     */

381    public void setDoubleselectbuttonscssclass(
382       String JavaDoc strDoubleselectbuttonscssclass
383    )
384    {
385       m_strDoubleselectbuttonscssclass = strDoubleselectbuttonscssclass;
386    }
387
388    /**
389     * @param strFocus - If this control have focus when it si displayed on the
390     * page say true or 1.
391     */

392    public void setFocus(
393       String JavaDoc strFocus
394    )
395    {
396       m_strFocus = strFocus;
397    }
398    
399    /**
400     * @param bFocus - Does this control have focus when it si displayed on the
401     * page or tab.
402     */

403    public void setFocus(
404       boolean bFocus
405    )
406    {
407       m_strFocus = Boolean.toString(bFocus);
408    }
409
410    /**
411     * @return boolean - true if this control has focus when it is displayed
412     * on a page or tab
413     */

414    public boolean isFocusedControl(
415    )
416    {
417       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus))
418              || ("1".equals(m_strFocus)));
419    }
420
421    /**
422     * @return String - If this control should be disabled then this attribute
423     * should say true or 1.
424     */

425    public String JavaDoc getDisabled(
426    )
427    {
428       return m_strDisabled;
429    }
430
431    /**
432     * @param strDisabled - If this control should be disabled then this attribute
433     * should say true or 1.
434     */

435    public void setDisabled(
436       String JavaDoc strDisabled
437    )
438    {
439       m_strDisabled = strDisabled;
440    }
441    
442    /**
443     * @param bDisabled - If this control should be disabled then this attribute
444     * should say true or 1.
445     */

446    public void setDisabled(
447       boolean bDisabled
448    )
449    {
450       m_strDisabled = Boolean.toString(bDisabled);
451    }
452
453    /**
454     * @return boolean - true if this control should be disabled
455     */

456    public boolean isDisabledControl(
457    )
458    {
459       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
460              || ("1".equals(m_strDisabled)));
461    }
462
463    /**
464     * @return String - Size of the control
465     */

466    public String JavaDoc getSize(
467    )
468    {
469       return m_strSize;
470    }
471
472    /**
473     * @param strSize - Size of the control
474     */

475    public void setSize(
476       String JavaDoc strSize
477    )
478    {
479       m_strSize = strSize;
480    }
481 }
482
Popular Tags