KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: DoubleSelectRightHalfTag.java,v 1.16 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 right half of the
32  * double select control allowing user to move items between left and right list.
33  * The generated code will display the right select list with buttons allowing to
34  * reorder items in the right list. The list and the controls will be displayed
35  * in the right 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: DoubleSelectRightHalfTag.java,v 1.16 2007/01/07 06:14:28 bastafidli Exp $
45  * @author Julian Legeny
46  * @code.reviewer Miro Halas
47  * @code.reviewed 1.11 2006/02/18 05:29:32 bastafidli
48  */

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

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

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

61    protected String JavaDoc m_strDoubleselectcssclass;
62
63    /**
64     * Class for the buttons belonging to the right 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.
89     */

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

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

97    public DoubleSelectRightHalfTag()
98    {
99       super("clsDialogRowRightHalf", BlockElementTag.DIV_BLOCK_ELEMENT);
100       
101       m_strSize = "8";
102       m_strDoubleselectcssclass = "clsDoubleSelectListColumnRight";
103       m_strDoubleselectbuttonscssclass = "clsDoubleSelectListButtonColumnRight";
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       // getCurrentId() is faitly expensive so we call it just once
117
// and then we reuse the results.
118
String JavaDoc strCurrentId = getCurrentId();
119
120       /*
121       <div class="clsDialogRowRightHalf">
122          <div class="clsDoubleSelectListButtonColumnRight">
123             <div class="clsDSButton"><button style="width:100%;" type="button"
124                  class="clsDoubleSelectButtonMoveTop" id="XXX_dstop"
125                  onclick="moveSelectedItemsTop('destlist', 'XXX_assigned_items');"
126                  accesskey="T" >Top</button></div>
127             <div class="clsDSButton"><button style="width:100%;" type="button"
128                  class="clsDoubleSelectButtonMoveUp" id="XXX_dsup"
129                  onclick="moveSelectedItemsUp('destlist', 'XXX_assigned_items');"
130                  accesskey="U" >Up</button></div>
131             <div class="clsDSButton"><button style="width:100%;" type="button"
132                  class="clsDoubleSelectButtonMoveDown" id="XXX_dsdown"
133                  onclick="moveSelectedItemsDown('destlist', 'XXX_assigned_items');"
134                  accesskey="w" >Down</button></div>
135             <div class="clsDSButton"><button style="width:100%;" type="button"
136                  class="clsDoubleSelectButtonMoveBottom" id="XXX_dsbottom"
137                  onclick="moveSelectedItemsBottom('destlist', 'XXX_assigned_items');"
138                  accesskey="B" >Bottom</button></div>
139          </div>
140          <div class="clsDoubleSelectListColumnRight">
141             <select multiple class="clsStretchSingleLineEdit" id="destlist" size="8"
142                     onchange="changeDSButtons('dsid', 'destlist', 'sourcelist');"
143                     ondblclick="moveBetweenLists('dsid', 'destlist', 'sourcelist',
144                                                  false, 'XXX_assigned_items', true);">
145
146                <!-- options are defined within the jsp -->
147
148             </select>
149          </div>
150       </div>
151       */

152       
153       // Generate the start of the double select right half control
154
sbHtml.append("<");
155       sbHtml.append(m_strType);
156       sbHtml.append(" id=\"");
157       sbHtml.append(strCurrentId);
158       sbHtml.append(m_strId);
159       sbHtml.append("doubleselectrighthalf\" class=\"clsDialogRowRightHalf\">\n");
160
161       sbHtml.append("<");
162       sbHtml.append(m_strType);
163       if ((m_strDoubleselectbuttonscssclass != null)
164            && (m_strDoubleselectbuttonscssclass.length() > 0))
165       {
166          sbHtml.append(" class=\"");
167          sbHtml.append(m_strDoubleselectbuttonscssclass);
168          sbHtml.append("\"");
169       }
170       sbHtml.append(">\n");
171       // add button 'Top'
172
sbHtml.append("<div class=\"clsDSButton\"><button style=\"width:100%;\" " +
173                     "class=\"clsImageMoveTopTextButton\" type=\"button\" " +
174                     "accesskey=\"T\" id=\"");
175       sbHtml.append(strCurrentId);
176       sbHtml.append(m_strId);
177       sbHtml.append("_dstop\" onclick=\"moveSelectedItemsTop('");
178       sbHtml.append(strCurrentId);
179       sbHtml.append(m_strId);
180       sbHtml.append("doubleselectdestination', '");
181       sbHtml.append(strCurrentId);
182       sbHtml.append(m_strId);
183       sbHtml.append("_assigned_items');\"><u>T</u>op</button></div>\n");
184       // add button 'Up'
185
sbHtml.append("<div class=\"clsDSButton\"><button style=\"width:100%;\" " +
186                     "class=\"clsImageMoveOneUpTextButton\" type=\"button\" " +
187                     "accesskey=\"U\" id=\"");
188       sbHtml.append(strCurrentId);
189       sbHtml.append(m_strId);
190       sbHtml.append("_dsup\" onclick=\"moveSelectedItemsUp('");
191       sbHtml.append(strCurrentId);
192       sbHtml.append(m_strId);
193       sbHtml.append("doubleselectdestination', '");
194       sbHtml.append(strCurrentId);
195       sbHtml.append(m_strId);
196       sbHtml.append("_assigned_items');\"><u>U</u>p</button></div>\n");
197       // add button 'Down'
198
sbHtml.append("<div class=\"clsDSButton\"><button style=\"width:100%;\" " +
199                     "class=\"clsImageMoveOneDownTextButton\" type=\"button\" " +
200                     "accesskey=\"w\" id=\"");
201       sbHtml.append(strCurrentId);
202       sbHtml.append(m_strId);
203       sbHtml.append("_dsdown\" onclick=\"moveSelectedItemsDown('");
204       sbHtml.append(strCurrentId);
205       sbHtml.append(m_strId);
206       sbHtml.append("doubleselectdestination', '");
207       sbHtml.append(strCurrentId);
208       sbHtml.append(m_strId);
209       sbHtml.append("_assigned_items');\">Do<u>w</u>n</button></div>\n");
210       // Add button 'Bottom'
211
sbHtml.append("<div class=\"clsDSButton\"><button style=\"width:100%;\" " +
212                     "class=\"clsImageMoveBottomTextButton\" type=\"button\" " +
213                     "accesskey=\"B\" id=\"");
214       sbHtml.append(strCurrentId);
215       sbHtml.append(m_strId);
216       sbHtml.append("_dsbottom\" onclick=\"moveSelectedItemsBottom('");
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("_assigned_items');\"><u>B</u>ottom</button></div>\n");
223
224       sbHtml.append("</");
225       sbHtml.append(m_strType);
226       sbHtml.append(">\n");
227       
228       sbHtml.append("<");
229       sbHtml.append(m_strType);
230       sbHtml.append(" id=\"");
231       sbHtml.append(strCurrentId);
232       sbHtml.append(m_strId);
233       sbHtml.append("doubleselectrightcolumn\"");
234       if ((m_strDoubleselectcssclass != null) && (m_strDoubleselectcssclass.length() > 0))
235       {
236          sbHtml.append(" class=\"");
237          sbHtml.append(m_strDoubleselectcssclass);
238          sbHtml.append("\"");
239       }
240       sbHtml.append(">\n");
241
242       sbHtml.append("<select multiple id=\"");
243       sbHtml.append(strCurrentId);
244       sbHtml.append(m_strId);
245       sbHtml.append("doubleselectdestination\" class=\"clsStretchSingleLineEdit\" size=\"");
246       sbHtml.append(m_strSize);
247       sbHtml.append("\" ondblclick=\"moveBetweenLists('");
248       sbHtml.append(strCurrentId);
249       sbHtml.append(m_strId);
250       sbHtml.append("', '");
251       sbHtml.append(strCurrentId);
252       sbHtml.append(m_strId);
253       sbHtml.append("doubleselectdestination', '");
254       sbHtml.append(strCurrentId);
255       sbHtml.append(m_strId);
256       sbHtml.append("doubleselectsource', false, '");
257       sbHtml.append(strCurrentId);
258       sbHtml.append(m_strId);
259       sbHtml.append("_assigned_items', true);\" onchange=\"changeDSButtons('");
260       sbHtml.append(strCurrentId);
261       sbHtml.append(m_strId);
262       sbHtml.append("', '");
263       sbHtml.append(strCurrentId);
264       sbHtml.append(m_strId);
265       sbHtml.append("doubleselectdestination', '");
266       sbHtml.append(strCurrentId);
267       sbHtml.append(m_strId);
268       sbHtml.append("doubleselectsource');\"");
269
270       if (isDisabledControl())
271       {
272          sbHtml.append(" disabled=\"disabled\"");
273       }
274       sbHtml.append(">\n");
275
276       TagUtils.write(pageContext, sbHtml.toString());
277       
278       if (isFocusedControl())
279       {
280          // TODO: For Julo: Did you tested that the focus actually works? The
281
// elect control has a different id than the one you are setting here
282
// so how it is possible to set the focus to the right half of the
283
// control to the list?
284

285          // Cache the content since it should be inserted at a row
286
// boundary and not at a field boundary
287
sbHtml.delete(0, sbHtml.length());
288          sbHtml.append(strCurrentId);
289          sbHtml.append(m_strId);
290    
291          cache(TabbedDialogTag.FOCUSED_CONTROL_ID, sbHtml.toString());
292       }
293       
294       return (EVAL_BODY_INCLUDE);
295    }
296
297    /**
298     * {@inheritDoc}
299     */

300    public int doEndTag(
301    ) throws JspException JavaDoc
302    {
303       // Finish the label
304
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
305
306       sbHtml.append("</select>\n");
307       sbHtml.append("</");
308       sbHtml.append(m_strType);
309       sbHtml.append(">\n");
310       
311       sbHtml.append("</");
312       sbHtml.append(m_strType);
313       sbHtml.append(">");
314       
315       TagUtils.write(pageContext, sbHtml.toString());
316       
317       return (EVAL_PAGE);
318    }
319    
320    /**
321     * @return String - Class for the double select left control
322     */

323    public String JavaDoc getDoubleselectcssclass()
324    {
325       return m_strDoubleselectcssclass;
326    }
327
328    /**
329     * @return String - Class for the buttons belonging to the double select left control
330     */

331    public String JavaDoc getDoubleselectbuttonscssclass()
332    {
333       return m_strDoubleselectbuttonscssclass;
334    }
335
336    /**
337     * @return String - Does this control have focus when it si displayed on the
338     * page or not.
339     */

340    public String JavaDoc getFocus()
341    {
342       return m_strFocus;
343    }
344    
345    /**
346     * @param strInputcssclass - Class for the left double select control
347     */

348    public void setDoubleselectcssclass(
349       String JavaDoc strInputcssclass
350    )
351    {
352       m_strDoubleselectcssclass = strInputcssclass;
353    }
354
355    /**
356     * @param strDoubleselectbuttonscssclass - Class for the buttons belonging to the
357     * left double select control
358     */

359    public void setDoubleselectbuttonscssclass(
360       String JavaDoc strDoubleselectbuttonscssclass
361    )
362    {
363       m_strDoubleselectbuttonscssclass = strDoubleselectbuttonscssclass;
364    }
365
366    /**
367     * @param strFocus - If this control have focus when it si displayed on the
368     * page say true or 1.
369     */

370    public void setFocus(
371       String JavaDoc strFocus
372    )
373    {
374       m_strFocus = strFocus;
375    }
376    
377    /**
378     * @param bFocus - Does this control have focus when it si displayed on the
379     * page or tab.
380     */

381    public void setFocus(
382       boolean bFocus
383    )
384    {
385       m_strFocus = Boolean.toString(bFocus);
386    }
387
388    /**
389     * @return boolean - true if this control has focus when it is displayed
390     * on a page or tab
391     */

392    public boolean isFocusedControl(
393    )
394    {
395       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus))
396              || ("1".equals(m_strFocus)));
397    }
398
399    /**
400     * @return String - If this control should be disabled then this attribute
401     * should say true or 1.
402     */

403    public String JavaDoc getDisabled(
404    )
405    {
406       return m_strDisabled;
407    }
408
409    /**
410     * @param strDisabled - If this control should be disabled then this attribute
411     * should say true or 1.
412     */

413    public void setDisabled(
414       String JavaDoc strDisabled
415    )
416    {
417       m_strDisabled = strDisabled;
418    }
419    
420    /**
421     * @param bDisabled - If this control should be disabled then this attribute
422     * should say true or 1.
423     */

424    public void setDisabled(
425       boolean bDisabled
426    )
427    {
428       m_strDisabled = Boolean.toString(bDisabled);
429    }
430
431    /**
432     * @return boolean - true if this control should be disabled
433     */

434    public boolean isDisabledControl(
435    )
436    {
437       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
438              || ("1".equals(m_strDisabled)));
439    }
440
441
442    /**
443     * @return String - Size of the control
444     */

445    public String JavaDoc getSize(
446    )
447    {
448       return m_strSize;
449    }
450
451    /**
452     * @param strSize - Size of the control
453     */

454    public void setSize(
455       String JavaDoc strSize
456    )
457    {
458       m_strSize = strSize;
459    }
460 }
461
Popular Tags