KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > tabbeddialog > www > TabbedDialogJSTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: TabbedDialogJSTag.java,v 1.16 2007/01/07 06:14:27 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.tabbeddialog.www;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25
26 import org.opensubsystems.core.www.PageElementCacheTag;
27 import org.opensubsystems.core.www.TagUtils;
28
29 /**
30  * Custom tag to generate JavaScript required to interact with the tabbed dialog.
31  *
32  * Currently supported functions are
33  * onload - param1 - id of area to display messages
34  * - param2 - id of div which the tab should completely fill. This is
35  * usually content area (containing all the content).
36  * - param3 - name of the variable containing height of the content area
37  * - if this is "default" then no size adjustment will be made
38  * to the tabbed dialog and the dialog will be left to be
39  * resized by the browser otherwise the dialog will be stretched
40  * to fill the whole content area.
41  * - param4 - boolean value indicating if the content of the tab can scroll
42  * or not
43  * - param5 - boolean value indicating if all the tabs should have the same
44  * height or not. The default value is false. If true then all
45  * tabs will have equal height, which will be the height
46  * specified either by application layout or by the height of
47  * the first tab.
48  * onresize - the same parameters as onload except param5 which is not used
49  * ondialoghelp - param1 - id of the help tab
50  * - param2 - javascript to execute when the tabs are switched
51  * For any string withing the javascript you have to
52  * use ' (single quote)
53  *
54  * @version $Id: TabbedDialogJSTag.java,v 1.16 2007/01/07 06:14:27 bastafidli Exp $
55  * @author Miro Halas
56  * @code.reviewer Miro Halas
57  * @code.reviewed 1.12 2006/02/18 05:31:32 bastafidli
58  */

59 public class TabbedDialogJSTag extends PageElementCacheTag
60 {
61    // Attributes ///////////////////////////////////////////////////////////////
62

63    /**
64     * Generated serial version id for this class.
65     */

66    private static final long serialVersionUID = -3534110354211896981L;
67
68    /**
69     * Name of the function to generate the javascript for. Currently supported
70     * functions are onload, onresize, ondialoghelp.
71     */

72    protected String JavaDoc m_strFunction;
73
74    /**
75     * Parameter 1 to pass to the function if it allows it.
76     */

77    protected String JavaDoc m_strParam1;
78
79    /**
80     * Parameter 2 to pass to the function if it allows it.
81     */

82    protected String JavaDoc m_strParam2;
83
84    /**
85     * Parameter 3 to pass to the function if it allows it.
86     */

87    protected String JavaDoc m_strParam3;
88
89    /**
90     * Parameter 4 to pass to the function if it allows it.
91     */

92    protected String JavaDoc m_strParam4;
93
94    /**
95     * Parameter 5 to pass to the function if it allows it.
96     */

97    protected String JavaDoc m_strParam5;
98
99    // Constructors /////////////////////////////////////////////////////////////
100

101    /**
102     * Constructor for custom tag.
103     */

104    public TabbedDialogJSTag()
105    {
106       super();
107       m_strParam1 = null;
108       m_strParam2 = null;
109       m_strParam3 = null;
110       m_strParam4 = null;
111       m_strParam5 = null;
112    }
113    
114    // Business logic ///////////////////////////////////////////////////////////
115

116    /**
117     * {@inheritDoc}
118     */

119    public int doStartTag(
120    ) throws JspException JavaDoc
121    {
122       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
123
124       if (("onload".equalsIgnoreCase(m_strFunction))
125          || ("onresize".equalsIgnoreCase(m_strFunction)))
126       {
127          if ((m_strParam1 == null) || (m_strParam1.length() == 0))
128          {
129             m_strParam1 = "dialogmessages";
130          }
131          if ((m_strParam2 == null) || (m_strParam2.length() == 0))
132          {
133             m_strParam2 = "bodycontent";
134          }
135          if ((m_strParam3 == null) || (m_strParam3.length() == 0))
136          {
137             m_strParam3 = "iBodyContentHeight";
138          }
139          if ((m_strParam4 == null) || (m_strParam4.length() == 0))
140          {
141             m_strParam4 = "true";
142          }
143          if ((m_strParam5 == null) || (m_strParam5.length() == 0))
144          {
145             m_strParam5 = "false";
146          }
147
148          if ("onload".equalsIgnoreCase(m_strFunction))
149          {
150             // Initialize array of heights and tab IDs for all existing tabs
151
sbHtml.append("initAllTabs('");
152             sbHtml.append(m_strId);
153             sbHtml.append("',");
154             sbHtml.append(m_strParam5);
155             sbHtml.append(");\n");
156          }
157
158          /*
159          resizeTabbedDialog("test", "testdialog", "testtabfiller", "dialogmessages",
160                             "bodycontent", iBodyContentHeight);
161          */

162          if (!"default".equalsIgnoreCase(m_strParam3))
163          {
164             sbHtml.append("resizeTabbedDialog('");
165             sbHtml.append(m_strId);
166             sbHtml.append("', '");
167             sbHtml.append(m_strId);
168             sbHtml.append("dialog', '");
169             sbHtml.append(m_strId);
170             sbHtml.append("tabfiller', '");
171             sbHtml.append(m_strParam1);
172             sbHtml.append("', '");
173             sbHtml.append(m_strParam2);
174             sbHtml.append("', ");
175             sbHtml.append(m_strParam3);
176             sbHtml.append(", ");
177             sbHtml.append(m_strParam4);
178             sbHtml.append(");\n");
179          }
180          
181          if ("onload".equalsIgnoreCase(m_strFunction))
182          {
183             // When the dialog is loaded, focus to the first control
184
sbHtml.append("focusSpecifiedControl();");
185          }
186       }
187       else if ("ondialoghelp".equalsIgnoreCase(m_strFunction))
188       {
189          /*
190          switchHelpTab("testhelpdialoghelpheader", "test", null)
191          */

192          sbHtml.append("switchHelpTab('");
193          sbHtml.append(m_strId);
194          sbHtml.append(m_strParam1);
195          sbHtml.append("dialoghelpheader', '");
196          sbHtml.append(m_strId);
197          sbHtml.append("', ");
198          if ((m_strParam2 != null) && (m_strParam2.length() > 0))
199          {
200             sbHtml.append("'");
201             // Since this is JSP tag parameter, it wil be specified using ""
202
// and therefore if the javascript contains any quotes, they will
203
// be most likely specified as '. Since we are adding al this in
204
// between '', escape all ' into \'
205
sbHtml.append(m_strParam2.replaceAll("\'", "\\\\'"));
206             sbHtml.append("'");
207          }
208          else
209          {
210             sbHtml.append("null");
211          }
212          sbHtml.append(");");
213       }
214       else
215       {
216          sbHtml.append("<!-- Tabbed dialog doesnt support method ");
217          sbHtml.append(m_strFunction);
218          sbHtml.append(" with parameters ");
219          if (m_strParam1 != null)
220          {
221             sbHtml.append(" param1=");
222             sbHtml.append(m_strParam1);
223             sbHtml.append(" ");
224          }
225          else
226          {
227             sbHtml.append(" param1=null ");
228          }
229          if (m_strParam2 != null)
230          {
231             sbHtml.append(" param2=");
232             sbHtml.append(m_strParam2);
233             sbHtml.append(" ");
234          }
235          else
236          {
237             sbHtml.append(" param2=null ");
238          }
239          if (m_strParam3 != null)
240          {
241             sbHtml.append(" param3=");
242             sbHtml.append(m_strParam3);
243             sbHtml.append(" ");
244          }
245          else
246          {
247             sbHtml.append(" param3=null ");
248          }
249          sbHtml.append(" -->");
250          
251       }
252       
253       if ((m_strCacheas != null) && (m_strCacheas.length() > 0))
254       {
255          cache(m_strCacheas, sbHtml.toString());
256       }
257       else
258       {
259          TagUtils.write(pageContext, sbHtml.toString());
260       }
261                
262       return (SKIP_BODY);
263    }
264
265    /**
266     * {@inheritDoc}
267     */

268    public int doEndTag(
269    ) throws JspException JavaDoc
270    {
271       return (EVAL_PAGE);
272    }
273
274    /**
275     * @return String - Name of the function to generate the javascript for.
276     * Currently supported functions are onload, onresize,
277     * ondialoghelp.
278     */

279    public String JavaDoc getFunction(
280    )
281    {
282       return m_strFunction;
283    }
284
285    /**
286     * @return String - Value of parameter 1 if the function requires it.
287     */

288    public String JavaDoc getParam1(
289    )
290    {
291       return m_strParam1;
292    }
293
294    /**
295     * @return String - Value of parameter 2 if the function requires it.
296     */

297    public String JavaDoc getParam2(
298    )
299    {
300       return m_strParam2;
301    }
302
303    /**
304     * @return String - Value of parameter 3 if the function requires it.
305     */

306    public String JavaDoc getParam3(
307    )
308    {
309       return m_strParam3;
310    }
311
312    /**
313     * @return String - Value of parameter 4 if the function requires it.
314     */

315    public String JavaDoc getParam4(
316    )
317    {
318       return m_strParam4;
319    }
320
321    /**
322     * @return String - Value of parameter 5 if the function requires it.
323     */

324    public String JavaDoc getParam5(
325    )
326    {
327       return m_strParam5;
328    }
329
330    /**
331     * @param strFunction - Name of the function to generate the javascript for.
332     * Currently supported functions are onload, onresize,
333     * ondialoghelp.
334     */

335    public void setFunction(
336       String JavaDoc strFunction
337    )
338    {
339       m_strFunction = strFunction;
340    }
341
342    /**
343     * @param strParam1 - Value of parameter 1 if the function requires it.
344     */

345    public void setParam1(
346       String JavaDoc strParam1
347    )
348    {
349       m_strParam1 = strParam1;
350    }
351
352    /**
353     * @param strParam2 - Value of parameter 2 if the function requires it.
354     */

355    public void setParam2(
356       String JavaDoc strParam2
357    )
358    {
359       m_strParam2 = strParam2;
360    }
361
362    /**
363     * @param strParam3 - Value of parameter 3 if the function requires it.
364     */

365    public void setParam3(
366       String JavaDoc strParam3
367    )
368    {
369       m_strParam3 = strParam3;
370    }
371
372    /**
373     * @param strParam4 - Value of parameter 4 if the function requires it.
374     */

375    public void setParam4(
376       String JavaDoc strParam4
377    )
378    {
379       m_strParam4 = strParam4;
380    }
381
382    /**
383     * @param strParam5 - Value of parameter 5 if the function requires it.
384     */

385    public void setParam5(
386       String JavaDoc strParam5
387    )
388    {
389       m_strParam5 = strParam5;
390    }
391 }
392
Popular Tags