KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: TabbedDialogHelpTabTag.java,v 1.14 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.BlockElementTag;
27 import org.opensubsystems.core.www.TagUtils;
28 import org.opensubsystems.patterns.dialoglayout.www.ImageButtonControlTag;
29
30 /**
31  * Custom tag to generate all HTML code necessary to display one tab of the
32  * tabbed dialog, which is displayed, when user clicks on the help button
33  * associated with the tabbed dialog. This tab doesn't have any tab heading so
34  * it is not visible by default.
35  *
36  * @version $Id: TabbedDialogHelpTabTag.java,v 1.14 2007/01/07 06:14:27 bastafidli Exp $
37  * @author Peter Satury
38  * @code.reviewer Miro Halas
39  * @code.reviewed 1.10 2006/04/19 14:20:39 bastafidli
40  */

41 public class TabbedDialogHelpTabTag extends BlockElementTag
42 {
43    // Attributes ///////////////////////////////////////////////////////////////
44

45    /**
46     * Generated serial version id for this class.
47     */

48    private static final long serialVersionUID = 4417351921144093076L;
49
50    /**
51     * String for dialog help header.
52     */

53    protected String JavaDoc m_strHeader;
54    
55    /**
56     * JavaScript code to execute when the help is closed.
57     */

58    protected String JavaDoc m_strOnhelpclose;
59    
60    // Constructors /////////////////////////////////////////////////////////////
61

62    /**
63     * Constructor for custom tag.
64     */

65    public TabbedDialogHelpTabTag()
66    {
67       super("clsTab", BlockElementTag.DIV_BLOCK_ELEMENT);
68
69       m_strHeader = null;
70       m_strOnhelpclose = null;
71    }
72
73    // Business logic ///////////////////////////////////////////////////////////
74

75    /**
76     * {@inheritDoc}
77     */

78    public int doStartTag(
79    ) throws JspException JavaDoc
80    {
81       StringBuffer JavaDoc sbHtml = null;
82       Object JavaDoc objTemp;
83       String JavaDoc strTabbedDialogId;
84
85       objTemp = pageContext.getAttribute(TabbedDialogTag.ACTIVE_TABBED_DIALOG_ID);
86       if (objTemp == null)
87       {
88          // assign prefix for unknown tabbed dialog ID
89
objTemp = TabbedDialogTag.TABBED_DIALOG_PREFIX;
90          // throw new JspException("Cannot find tabbed dialog id on the page. Probable" +
91
// " cause is that the tabbed dialog open tag is missing.");
92
}
93       strTabbedDialogId = (String JavaDoc)objTemp;
94
95       sbHtml = new StringBuffer JavaDoc();
96
97       /*
98       <div id="sessionbasicdialoghelpheader" style="display: none;" class="clsTabHeader">
99          <a HREF="#basic" rel="Subsection" rev="Subsection">Basic information</a>
100       </div>
101       <div id="sessionbasicdialoghelp" class="clsTabBody">
102          <div class="clsDialogHint">
103             <div class="clsHintHeader">
104                ? Basic info
105             </div>
106             <div class="clsHintBody">
107       */

108
109       sbHtml.append("<div id=\"");
110       sbHtml.append(strTabbedDialogId);
111       sbHtml.append(m_strId);
112       sbHtml.append("dialoghelpheader\" style=\"display: none;\"");
113       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
114       {
115          sbHtml.append(" class=\"");
116          sbHtml.append(m_strCssclass);
117          sbHtml.append("Header\"");
118       }
119       sbHtml.append(">\n");
120
121       // Generate the text on the tab as a hyperlink so that user can get there
122
// using Tab
123
sbHtml.append("<a HREF=\"#");
124       sbHtml.append(m_strId);
125       sbHtml.append("\" rel=\"Subsection\" rev=\"Subsection\">");
126       sbHtml.append(getHeader());
127       sbHtml.append("</a>\n");
128       // Generate the end of the tabbed dialog tab header
129
sbHtml.append("</div>\n");
130       
131       sbHtml.append("<div id=\"");
132       sbHtml.append(strTabbedDialogId);
133       sbHtml.append(m_strId);
134       sbHtml.append("dialoghelp\"");
135       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
136       {
137          sbHtml.append(" class=\"");
138          sbHtml.append(m_strCssclass);
139          sbHtml.append("Body\"");
140       }
141       sbHtml.append(">\n");
142       
143       sbHtml.append("<div class=\"clsDialogHint\">\n" +
144                     "<div class=\"clsHintHeader\">\n");
145       sbHtml.append(m_strHeader);
146       sbHtml.append("\n" +
147                     "</div>\n" +
148                     "<div class=\"clsHintBody\">");
149
150       TagUtils.write(pageContext, sbHtml.toString());
151
152       return (EVAL_BODY_INCLUDE);
153    }
154
155    /**
156     * {@inheritDoc}
157     */

158    public int doEndTag(
159    ) throws JspException JavaDoc
160    {
161       StringBuffer JavaDoc sbHtml = null;
162       Object JavaDoc objTemp;
163       String JavaDoc strTabbedDialogId;
164       StringBuffer JavaDoc sbTemp = new StringBuffer JavaDoc();
165
166       objTemp = pageContext.getAttribute(TabbedDialogTag.ACTIVE_TABBED_DIALOG_ID);
167       if (objTemp == null)
168       {
169          // assign prefix for unknown tabbed dialog ID
170
objTemp = TabbedDialogTag.TABBED_DIALOG_PREFIX;
171          // throw new JspException("Cannot find tabbed dialog id on the page. Probable" +
172
// " cause is that the tabbed dialog open tag is missing.");
173
}
174       strTabbedDialogId = (String JavaDoc)objTemp;
175
176       sbHtml = new StringBuffer JavaDoc();
177
178       /*
179             </div>
180             <div class="clsDialogHintCloseButton clsImageOnlyFakeButton clsImageCloseButton"><a
181               onClick="switchHelpTab('sessionbasicdialoghelpheader', 'session', null);">
182               href="#" class="clsHintClose"><img
183               src="<%=contextpath%>/patterns/images/transparentbutton.gif"
184               alt="Close" title="Close"></a></div>
185          </div>
186       </div>
187       */

188       
189       sbHtml.append("</div>\n");
190                
191       // Close button
192
sbTemp.append("switchHelpTab('");
193       sbTemp.append(strTabbedDialogId);
194       sbTemp.append(m_strId);
195       sbTemp.append("dialoghelpheader', '");
196       sbTemp.append(strTabbedDialogId);
197       sbTemp.append("', ");
198       if ((m_strOnhelpclose != null) && (m_strOnhelpclose.length() > 0))
199       {
200          sbTemp.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
sbTemp.append(m_strOnhelpclose.replaceAll("\'", "\\\\'"));
206          sbTemp.append("'");
207       }
208       else
209       {
210          sbTemp.append("null");
211       }
212       sbTemp.append(");");
213
214       ImageButtonControlTag close = new ImageButtonControlTag();
215       close.setCssclass("clsHintDialogCloseButton clsImageOnlyFakeButton clsImageCloseButton");
216       close.setFake(Boolean.TRUE.toString());
217       close.setFakecssclass("clsHintDialogClose");
218       close.setOnclick(sbTemp.toString());
219       close.setTitle("Close the help");
220       close.setPageContext(pageContext);
221       close.doEndTag(sbHtml, "");
222                     
223       sbHtml.append("</div>\n" +
224                     "</div>");
225       
226       TagUtils.write(pageContext, sbHtml.toString());
227
228       return (EVAL_PAGE);
229    }
230
231    /**
232     * @return String - Text of the header for this tab
233     */

234    public String JavaDoc getHeader(
235    )
236    {
237       return m_strHeader;
238    }
239
240    /**
241     * @return String - JavaScript code to execute when the help is closed
242     * or null if nothing should be executed.
243     */

244    public String JavaDoc getOnhelpclose(
245    )
246    {
247       return m_strOnhelpclose;
248    }
249
250    /**
251     * @param strHeader - Text of the header for this tab
252     */

253    public void setHeader(
254       String JavaDoc strHeader
255    )
256    {
257       m_strHeader = strHeader;
258    }
259
260    /**
261     * @param strOnhelpclose - JavaScript code to execute when the help is closed
262     * or null if nothing should be executed.
263     */

264    public void setOnhelpclose(
265       String JavaDoc strOnhelpclose
266    )
267    {
268       m_strOnhelpclose = strOnhelpclose;
269    }
270 }
271
Popular Tags