KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: TabbedDialogTag.java,v 1.19 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 java.util.Enumeration JavaDoc;
25
26 import javax.servlet.jsp.JspException JavaDoc;
27 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
28
29 import org.opensubsystems.core.www.BlockElementTag;
30 import org.opensubsystems.core.www.TagUtils;
31
32 /**
33  * Custom tag to generate all HTML code necessary to display tabbed dialog. This
34  * is the main tag which represents the dialog itself. The dialog will be created
35  * from the content of the body of this tag.
36  *
37  * @version $Id: TabbedDialogTag.java,v 1.19 2007/01/07 06:14:27 bastafidli Exp $
38  * @author Miro Halas
39  * @code.reviewer Miro Halas
40  * @code.reviewed 1.16 2006/02/18 05:31:32 bastafidli
41  */

42 public class TabbedDialogTag extends BlockElementTag
43 {
44    // Constants ////////////////////////////////////////////////////////////////
45

46    /**
47     * Id of the active tabbed dialog which will be used by all other related
48     * tags.
49     */

50    public static final String JavaDoc ACTIVE_TABBED_DIALOG_ID = "activetabdialogid";
51    
52    /**
53     * Id of the control which should have focus when the dialog or a tab of dialog
54     * is displayed. Each tab can have one focused control, if there are multiple,
55     * the first one will get the focus.
56     */

57    public static final String JavaDoc FOCUSED_CONTROL_ID = "focusedcontrolid";
58
59    /**
60     * Javascript function or value null that will be called by onswich event. This value
61     * will be cached here and can be used for use later within the related custom tags.
62     */

63    public static final String JavaDoc TABBED_DIALOG_ONSWITCH_JSFUNCTION = "tabdialogonswitchjsfunc";
64    
65    /**
66     * Name of the tabbed dialog that has no specified ID
67     */

68    public static final String JavaDoc TABBED_DIALOG_PREFIX = "unknowntabbeddialogid";
69
70    // Attributes ///////////////////////////////////////////////////////////////
71

72    /**
73     * Generated serial version id for this class.
74     */

75    private static final long serialVersionUID = -9155268056625844216L;
76
77    /**
78     * Class for the tab filler, which is the empty area on the right from tabs.
79     */

80    protected String JavaDoc m_strFillercssclass;
81    
82    /**
83     * JavaScript code to execute when the tabs are switched or null if nothing
84     * should be executed.
85     */

86    protected String JavaDoc m_strOnswitch;
87    
88    // Constructors /////////////////////////////////////////////////////////////
89

90    /**
91     * Constructor for custom tag.
92     */

93    public TabbedDialogTag()
94    {
95       super("clsTabbedDialog", BlockElementTag.DIV_BLOCK_ELEMENT);
96       
97       m_strFillercssclass = "clsTabHeaderFiller";
98       m_strOnswitch = null;
99    }
100    
101    // Business logic ///////////////////////////////////////////////////////////
102

103    /**
104     * {@inheritDoc}
105     */

106    public int doStartTag(
107    ) throws JspException JavaDoc
108    {
109       StringBuffer JavaDoc sbHtml = null;
110       StringBuffer JavaDoc sbOnSwitchJSFunction = new StringBuffer JavaDoc();
111       
112       sbHtml = new StringBuffer JavaDoc();
113
114 /*
115 This is how the tabbed dialog start looks like
116 <div id="sessiondialog" class="clsTabbedDialog"
117      onclick="switchTab(event, 'session', 'onResizeScrolltableWrapper();');dialogHelp(event);"
118      onKeyUp="showHelp(event);">
119    <div id="sessiontabfiller" class="clsTabHeaderFiller">
120       &nbsp;
121    </div>
122 */

123
124       // Generate hidden parameter that will store active tab name
125
sbHtml.append("<input type=\"hidden\" id=\"activetab\" name=\"activetab\">");
126       
127       // Generate the start of the tabbed dialog
128
sbHtml.append("<div id=\"");
129       sbHtml.append(m_strId);
130       sbHtml.append("dialog\"");
131       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
132       {
133          sbHtml.append(" class=\"");
134          sbHtml.append(m_strCssclass);
135          sbHtml.append("\"");
136       }
137
138       sbHtml.append(" onclick=\"focusTab(event, '");
139       sbHtml.append(m_strId);
140       sbHtml.append("', ");
141       if ((m_strOnswitch != null) && (m_strOnswitch.length() > 0))
142       {
143          sbOnSwitchJSFunction.append("'");
144          sbOnSwitchJSFunction.append(m_strOnswitch.replaceAll("\'", "\\\\'"));
145          sbOnSwitchJSFunction.append("'");
146          // Since this is JSP tag parameter, it wil be specified using ""
147
// and therefore if the javascript contains any quotes, they will
148
// be most likely specified as '. Since we are adding al this in
149
// between '', escape all ' into \'
150
sbHtml.append(sbOnSwitchJSFunction);
151       }
152       else
153       {
154          sbOnSwitchJSFunction.append("null");
155          sbHtml.append(sbOnSwitchJSFunction);
156       }
157       sbHtml.append(");dialogHelp(event);\" onKeyUp=\"showHelp(event);\">\n");
158       // Generate the tag for tab filler which is area over which the tabs will
159
// be places and which also covers the empty space to the right of the tabs
160
sbHtml.append("<div id=\"");
161       sbHtml.append(m_strId);
162       sbHtml.append("tabfiller\" class=\"clsTabHeaderFiller\">\n" +
163                     "&nbsp;\n" +
164                     "</div>");
165
166       Enumeration JavaDoc enumNames;
167       String JavaDoc strParam;
168       for (enumNames = pageContext.getRequest().getParameterNames();
169            enumNames.hasMoreElements();)
170       {
171          strParam = (String JavaDoc)enumNames.nextElement();
172          if (strParam.startsWith("activetab_"))
173          {
174             // if there was found inner activetab attribute, override activetab
175
// attribute by this value
176
pageContext.getRequest().setAttribute("activetab",
177                pageContext.getRequest().getParameterValues(strParam)[0]);
178          }
179       }
180
181       // Save the id to the page context so that other related tags don't have to
182
// specify it
183
pageContext.setAttribute(ACTIVE_TABBED_DIALOG_ID, m_strId);
184       // Cache value for defining js function that will be called onswitch
185
cache(TABBED_DIALOG_ONSWITCH_JSFUNCTION, sbOnSwitchJSFunction.toString());
186
187       TagUtils.write(pageContext, sbHtml.toString());
188
189       return (EVAL_BODY_BUFFERED);
190    }
191
192    /**
193     * {@inheritDoc}
194     */

195    public int doEndTag(
196    ) throws JspException JavaDoc
197    {
198       // Get the buffered body and replace all occurences of 'unknowntabbeddialogid'
199
// generated within the TabbedDialogHelpTabTag by actual tabbed dialog name.
200
// The real tabbed dialog wasn't known in the TabbedDialogHelpTabTag so we have
201
// just generated placeholders that will be rewrited now.
202
BodyContent JavaDoc content = getBodyContent();
203       String JavaDoc strContent = content.getString();
204       if (content != null)
205       {
206          strContent = strContent.replaceAll(TABBED_DIALOG_PREFIX , m_strId);
207       }
208       TagUtils.write(pageContext, strContent);
209
210       // Remove cached value for js function called onswitch
211
getCachedContent(TABBED_DIALOG_ONSWITCH_JSFUNCTION, true);
212       // Remove the attribute since we are done with this tabbed dialog
213
pageContext.removeAttribute(ACTIVE_TABBED_DIALOG_ID);
214       // Finish the tabbed dialog
215
TagUtils.write(pageContext, "</div>");
216       
217       return (EVAL_PAGE);
218    }
219
220    /**
221     * @return String - Class for the tab filler, which is the empty area on the
222     * right from tabs.
223     */

224    public String JavaDoc getFillercssclass(
225    )
226    {
227       return m_strFillercssclass;
228    }
229
230    /**
231     * @return String - JavaScript code to execute when the tabs are switched
232     * or null if nothing should be executed.
233     */

234    public String JavaDoc getOnswitch(
235    )
236    {
237       return m_strOnswitch;
238    }
239
240    /**
241     * @param strFillercssclass - Class for the tab filler, which is the empty
242     * area on the right from tabs.
243     */

244    public void setFillercssclass(
245       String JavaDoc strFillercssclass
246    )
247    {
248       m_strFillercssclass = strFillercssclass;
249    }
250
251    /**
252     * @param strOnswitch - JavaScript code to execute when the tabs are switched
253     * or null if nothing should be executed.
254     */

255    public void setOnswitch(
256       String JavaDoc strOnswitch
257    )
258    {
259       m_strOnswitch = strOnswitch;
260    }
261 }
262
Popular Tags