KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ContextHelpTag.java,v 1.13 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 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
26
27 import org.opensubsystems.core.www.BlockElementTag;
28 import org.opensubsystems.core.www.TagUtils;
29
30 /**
31  * Custom tag to generate all HTML required to display context help for a control.
32  * You can use the HelpLabelTag to display this context help when user clicks on
33  * the label. It is expected that this tag will be placed in the dialog row or
34  * column of a dialog row immediately following the control it belongs to.
35  * The context help will be by default displayed at the row boundary (in case
36  * the row is split into left and right half) and not at the field boundary.
37  *
38  * @version $Id: ContextHelpTag.java,v 1.13 2007/01/07 06:14:28 bastafidli Exp $
39  * @author Miro Halas
40  * @code.reviewer Miroslav Halas
41  * @code.reviewed 1.9 2006/04/19 14:20:39 bastafidli
42  */

43 public class ContextHelpTag extends BlockElementTag
44 {
45    // Constants ////////////////////////////////////////////////////////////////
46

47    /**
48     * Identifier used to store context help until it is ready to be retrieved.
49     */

50    public static final String JavaDoc CONTEXT_HELP_CACHE = "contexthelp";
51    
52    // Attributes ///////////////////////////////////////////////////////////////
53

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

57    private static final long serialVersionUID = 120478197670421422L;
58    
59    /**
60     * Context help title.
61     */

62    protected String JavaDoc m_strTitle;
63
64    /**
65     * Flag that specifies if the context help is written directly to the page at
66     * the location where the tag is placed in the page or if the custom tag can
67     * move it to a different place in the structure of the page. Default value
68     * is false (content can be moved to a different place in the structure of
69     * the page).
70     */

71    protected String JavaDoc m_strDirect;
72
73    // Constructors /////////////////////////////////////////////////////////////
74

75    /**
76     * Constructor for custom tag.
77     */

78    public ContextHelpTag(
79    )
80    {
81       super(null, BlockElementTag.DIV_BLOCK_ELEMENT);
82       m_strDirect = Boolean.FALSE.toString();
83    }
84    
85    // Business logic ///////////////////////////////////////////////////////////
86

87    /**
88     * {@inheritDoc}
89     */

90    public int doStartTag(
91    ) throws JspException JavaDoc
92    {
93       // Buffer the context help since we will neeed to display at a row
94
// boundary and not at a field boundary
95
return (EVAL_BODY_BUFFERED);
96    }
97
98    /**
99     * {@inheritDoc}
100     */

101    public int doEndTag(
102    ) throws JspException JavaDoc
103    {
104       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
105
106       /*
107       <div id="sessionloginhint" class="clsHint">
108          <div class="clsHintHeader">
109             <a name="sessionloginhelp" rel="Help" rev="Help"></a>
110             ? System maintenance
111          </div>
112          <div class="clsHintBody">
113             BODY OF THE HELP
114          </div>
115          <div class="clsHintCloseButton clsImageOnlyFakeButton clsImageCloseButton"><a
116               href="#" class="clsHintClose"><img
117               src="<%=contextpath%>/patterns/images/transparentbutton.gif"
118               alt="Close" title="Close"></a></div>
119       </div>
120       */

121       sbHtml.append("<div id=\"");
122       sbHtml.append(getCurrentId());
123       sbHtml.append(m_strId);
124       sbHtml.append("hint\" class=\"clsHint\">" +
125                     "<div class=\"clsHintHeader\">" +
126                     "<a name=\"");
127       sbHtml.append(getCurrentId());
128       sbHtml.append(m_strId);
129       sbHtml.append("help\" rel=\"Help\" rev=\"Help\"></a>");
130       sbHtml.append(m_strTitle);
131       sbHtml.append("</div>" +
132                     "<div class=\"clsHintBody\">");
133       // Insert the buffered body representing the text of the context help
134
BodyContent JavaDoc content = getBodyContent();
135       
136       if (content != null)
137       {
138          sbHtml.append(content.getString());
139       }
140       else
141       {
142          sbHtml.append("Missing context help for ");
143          sbHtml.append(getCurrentId());
144          sbHtml.append(m_strId);
145       }
146       sbHtml.append("</div>");
147                
148       // Close button
149
ImageButtonControlTag close = new ImageButtonControlTag();
150       close.setCssclass("clsHintCloseButton clsImageOnlyFakeButton clsImageCloseButton");
151       close.setFake(Boolean.TRUE.toString());
152       close.setFakecssclass("clsHintClose");
153       close.setTitle("Close the context help");
154       close.setPageContext(pageContext);
155       close.doEndTag(sbHtml, "");
156       
157       sbHtml.append("</div>\n");
158
159       // TODO: Improve: This looks like a generic functionality so maybe we
160
// should move it to the base class
161
if (isDirectWritten())
162       {
163          // Don't cache and write context directly
164
TagUtils.write(pageContext, sbHtml.toString());
165       }
166       else
167       {
168          // Cache the content since it should be inserted at a row
169
// boundary and not at a field boundary
170
cache(CONTEXT_HELP_CACHE, sbHtml.toString());
171       }
172       
173       return (EVAL_PAGE);
174    }
175
176    /**
177     * @return String - Context help title.
178     */

179    public String JavaDoc getTitle(
180    )
181    {
182       return m_strTitle;
183    }
184
185    /**
186     * @param strTitle - Context help title.
187     */

188    public void setTitle(
189       String JavaDoc strTitle
190    )
191    {
192       m_strTitle = strTitle;
193    }
194
195    /**
196     * @return String - flag which will tells us if the context will be written
197     * directly - then this attribute should say true or 1.
198     */

199    public String JavaDoc getDirect(
200    )
201    {
202       return m_strDirect;
203    }
204
205    /**
206     * @param strDirect - If context should be written then this attribute
207     * should say true or 1.
208     */

209    public void setDirect(
210       String JavaDoc strDirect
211    )
212    {
213       m_strDirect = strDirect;
214    }
215    
216    /**
217     * @param bDirect - If context should be written then this attribute
218     * should say true or 1.
219     */

220    public void setDirect(
221       boolean bDirect
222    )
223    {
224       m_strDirect = Boolean.toString(bDirect);
225    }
226
227    /**
228     * @return boolean - true if this control should be disabled
229     */

230    public boolean isDirectWritten(
231    )
232    {
233       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDirect))
234              || ("1".equals(m_strDirect)));
235    }
236 }
237
Popular Tags