KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > ordereddata > www > OrderedDataButtonsTag


1 /*
2  * Copyright (c) 2006 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: OrderedDataButtonsTag.java,v 1.9 2007/01/07 06:14:53 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.ordereddata.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.ordereddata.util.OrderedDataUtils;
29
30 /**
31  * Custom tag to generate buttons allowing to ordering data items in a table.
32  *
33  * @version $Id: OrderedDataButtonsTag.java,v 1.9 2007/01/07 06:14:53 bastafidli Exp $
34  * @author Julian Legeny
35  * @code.reviewer Miro Halas
36  * @code.reviewed 1.4 2006/04/29 00:26:35 jlegeny
37  */

38 public class OrderedDataButtonsTag extends BlockElementTag
39 {
40    // Attributes ///////////////////////////////////////////////////////////////
41

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

45    private static final long serialVersionUID = -3719587838643454408L;
46
47    /**
48     * Prefix used for all html fields generated by this tag.
49     */

50    protected String JavaDoc m_strPrefix;
51
52    /**
53     * If the controls generated by this tag should be disabled then this
54     * attribute should say true or 1.
55     */

56    protected String JavaDoc m_strDisabled;
57
58    /**
59     * Values specifying mapping between ids of data objects managed by the
60     * controls and artificial order number specifying order of those data objects,
61     * The format for order is following:
62     * ID1:ORDER_NUMBER1;ID2:ORDER_NUMBER2;...;IDn:ORDER_NUMBERn
63     */

64    protected String JavaDoc m_strOrderedItems;
65
66    /**
67     * Flag which will configures if an artificial order number will be computed
68     * when item is reordered. If the order should be computed for reordered item
69     * this should say true or 1. If this is false or 0 then then item will be
70     * just moved on the gui without computing new order value. Default value is
71     * true.
72     */

73    protected String JavaDoc m_strComputedOrder;
74
75    // Constructors /////////////////////////////////////////////////////////////
76

77    /**
78     * Constructor for custom tag.
79     */

80    public OrderedDataButtonsTag()
81    {
82       super("", BlockElementTag.SPAN_BLOCK_ELEMENT);
83
84       m_strStyle = "";
85       m_strPrefix = "";
86       m_strComputedOrder = Boolean.TRUE.toString();
87    }
88
89    // Business logic ///////////////////////////////////////////////////////////
90

91    /**
92     * {@inheritDoc}
93     */

94    public int doStartTag(
95    ) throws JspException JavaDoc
96    {
97       return (EVAL_BODY_BUFFERED);
98    }
99
100    /**
101     * {@inheritDoc}
102     */

103    public int doEndTag(
104    ) throws JspException JavaDoc
105    {
106       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
107       /*
108       <div id="sortingcriteriamovebuttons" class="">
109          &nbsp;<button id="sortingcriteriamovetop" type="button"
110                        class="clsImageMoveTopTextButton"
111                        title="Move selected items to top place"
112                        onclick="moveSelectedTop('sortingcriteria');"
113                        accesskey="T" disabled>Top</button>
114          &nbsp;<button id="sortingcriteriamoveup" type="button"
115                        class="clsImageMoveOneUpTextButton"
116                        title="Move selected items up"
117                        onclick="moveSelectedUp('sortingcriteria');"
118                        accesskey="U" disabled>Up<button>
119          &nbsp;<button id="sortingcriteriamovedown" type="button"
120                        sclass="clsImageMoveOneDownTextButton"
121                        title="Move selected items down"
122                        onclick="moveSelectedDown('sortingcriteria');"
123                        accesskey="W" disabled>Down</button>
124          &nbsp;<button id="sortingcriteriamovebottom" type="button"
125                        class="clsImageMoveBottomTextButton"
126                        title="Move selected items to bottom place"
127                        onclick="moveSelectedEnd('sortingcriteria');"
128                        accesskey="B" disabled>Bottom</button>
129       </div>
130       <input type="hidden" id="sortingcriteriaordereditems"
131              name="CRITERIA_ORDERED_ITEMS" value="1:100;2:200;3:300">
132       */

133       sbHtml.append("<");
134       sbHtml.append(m_strType);
135       sbHtml.append(" id=\"");
136       sbHtml.append(m_strId);
137       sbHtml.append("movebuttons\"");
138       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
139       {
140          sbHtml.append(" class=\"");
141          sbHtml.append(m_strCssclass);
142          sbHtml.append("\"");
143       }
144       if ((m_strStyle != null) && (m_strStyle.length() > 0))
145       {
146          sbHtml.append(" style=\"");
147          sbHtml.append(m_strStyle);
148          sbHtml.append("\"");
149       }
150       sbHtml.append(">\n");
151
152       // Add button 'Top'
153
sbHtml.append("&nbsp;<button id=\"");
154       sbHtml.append(m_strId);
155       sbHtml.append("movetop\" class=\"clsImageMoveTopTextButton\" type=\"button\" " +
156                     "title=\"Move selected items to top place\" " +
157                     "onclick=\"moveSelectedTop('");
158       sbHtml.append(m_strId);
159       // Add flag as javascript parameter that will say if order should be counted
160
// when function for moving of the row is called. Default value is true.
161
sbHtml.append("', ");
162       sbHtml.append(isComputedOrder());
163       sbHtml.append(");\" accesskey=\"T\"");
164       if (isDisabledButtons())
165       {
166          sbHtml.append(" disabled");
167       }
168       sbHtml.append("><u>T</u>op</button>\n");
169
170       // Add button 'Up'
171
sbHtml.append("&nbsp;<button id=\"");
172       sbHtml.append(m_strId);
173       sbHtml.append("moveup\" class=\"clsImageMoveOneUpTextButton\" type=\"button\" " +
174                     "title=\"Move selected items up\" " +
175                     "onclick=\"moveSelectedUp('");
176       sbHtml.append(m_strId);
177       // Add flag as javascript parameter that will say if order should be counted
178
// when function for moving of the row is called. Default value is true.
179
sbHtml.append("', ");
180       sbHtml.append(isComputedOrder());
181       sbHtml.append(");\" accesskey=\"U\"");
182       if (isDisabledButtons())
183       {
184          sbHtml.append(" disabled");
185       }
186       sbHtml.append("><u>U</u>p</button>\n");
187
188       // Add button 'Down'
189
sbHtml.append("&nbsp;<button id=\"");
190       sbHtml.append(m_strId);
191       sbHtml.append("movedown\" class=\"clsImageMoveOneDownTextButton\" type=\"button\" " +
192                     "title=\"Move selected items down\" " +
193                     "onclick=\"moveSelectedDown('");
194       sbHtml.append(m_strId);
195       // Add flag as javascript parameter that will say if order should be counted
196
// when function for moving of the row is called. Default value is true.
197
sbHtml.append("', ");
198       sbHtml.append(isComputedOrder());
199       sbHtml.append(");\" accesskey=\"w\"");
200       if (isDisabledButtons())
201       {
202          sbHtml.append(" disabled");
203       }
204       sbHtml.append(">Do<u>w</u>n</button>\n");
205
206       // Add button 'Bottom'
207
sbHtml.append("&nbsp;<button id=\"");
208       sbHtml.append(m_strId);
209       sbHtml.append("movebottom\" class=\"clsImageMoveBottomTextButton\" type=\"button\" " +
210                     "title=\"Move selected items to bottom place\" " +
211                     "onclick=\"moveSelectedEnd('");
212       sbHtml.append(m_strId);
213       // Add flag as javascript parameter that will say if order should be counted
214
// when function for moving of the row is called. Default value is true.
215
sbHtml.append("', ");
216       sbHtml.append(isComputedOrder());
217       sbHtml.append(");\" accesskey=\"B\"");
218       if (isDisabledButtons())
219       {
220          sbHtml.append(" disabled");
221       }
222       sbHtml.append("><u>B</u>ottom</button>\n");
223
224       // Add hidden variable storing changed IDs for updated dataobjects
225
sbHtml.append("<input type=\"hidden\" id=\"");
226       sbHtml.append(m_strId);
227       sbHtml.append("ordereditems\" name=\"");
228       sbHtml.append(m_strPrefix);
229       sbHtml.append(OrderedDataUtils.ORDERED_ITEMS_POSTFIX);
230       sbHtml.append("\" value=\"");
231       if ((m_strOrderedItems != null) && (m_strOrderedItems.length() > 0))
232       {
233          sbHtml.append(m_strOrderedItems);
234       }
235       else
236       {
237          // if m_strOrderedItems is not specified try to set up value
238
// sent within the particular request hidden variable
239
String JavaDoc strOrderedItems = (String JavaDoc)pageContext.getRequest().getAttribute(
240                    m_strPrefix + OrderedDataUtils.ORDERED_ITEMS_POSTFIX);
241          
242          if (strOrderedItems != null)
243          {
244             sbHtml.append(strOrderedItems);
245          }
246       }
247       sbHtml.append("\">\n");
248
249       sbHtml.append("</");
250       sbHtml.append(m_strType);
251       sbHtml.append('>');
252
253       TagUtils.write(pageContext, sbHtml.toString());
254
255       return (EVAL_PAGE);
256    }
257
258    /**
259     * @return String - prefix used for all html fields generated by this tag.
260     */

261    public String JavaDoc getPrefix(
262    )
263    {
264       return m_strPrefix;
265    }
266
267    /**
268     * @param strPrefix - prefix used for all html fields generated by this tag.
269     */

270    public void setPrefix(
271       String JavaDoc strPrefix
272    )
273    {
274       m_strPrefix = strPrefix;
275    }
276
277    /**
278     * @return String - If the controls generated by this tag should be disabled
279     * then this attribute should say true or 1.
280     */

281    public String JavaDoc getDisabled(
282    )
283    {
284       return m_strDisabled;
285    }
286
287    /**
288     * @param strDisabled - If the controls generated by this tag should be disabled
289     * then this attribute should say true or 1.
290     */

291    public void setDisabled(
292       String JavaDoc strDisabled
293    )
294    {
295       m_strDisabled = strDisabled;
296    }
297    
298    /**
299     * @param bDisabled - If this button should be disabled then this attribute
300     * should say true or 1.
301     */

302    public void setDisabled(
303       boolean bDisabled
304    )
305    {
306       m_strDisabled = Boolean.toString(bDisabled);
307    }
308
309    /**
310     * @return boolean - true if this button should be disabled
311     */

312    public boolean isDisabledButtons(
313    )
314    {
315       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
316              || ("1".equals(m_strDisabled)));
317    }
318
319    /**
320     * @return - ordered items value
321     */

322    public String JavaDoc getOrdereditems(
323    )
324    {
325       return m_strOrderedItems;
326    }
327
328    /**
329     * @param strOrderedItems - new ordered items value
330     */

331    public void setOrdereditems(
332       String JavaDoc strOrderedItems
333    )
334    {
335       m_strOrderedItems = strOrderedItems;
336    }
337
338    /**
339     * @return String - If the order should be computed for reordered item this
340     * should say true or 1. If this is false or 0 then then
341     * item will be just moved on the gui without computing new
342     * order value.
343     */

344    public String JavaDoc getComputeorder(
345    )
346    {
347       return m_strComputedOrder;
348    }
349
350    /**
351     * @param strComputedOrder - If the order should be computed for reordered
352     * item this should say true or 1. If this is false
353     * or 0 then then item will be just moved on the
354     * gui without computing new order value.
355     */

356    public void setComputeorder(
357       String JavaDoc strComputedOrder
358    )
359    {
360       m_strComputedOrder = strComputedOrder;
361    }
362    
363    /**
364     * @param bComputedOrder - If the order should be computed should say true or 1.
365     */

366    public void setComputeorder(
367       boolean bComputedOrder
368    )
369    {
370       m_strComputedOrder = Boolean.toString(bComputedOrder);
371    }
372
373    /**
374     * @return boolean - true if the order has to be computed
375     */

376    public boolean isComputedOrder(
377    )
378    {
379       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strComputedOrder))
380              || ("1".equals(m_strComputedOrder)));
381    }
382 }
383
Popular Tags