KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > databinding > datagrid > Caption


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.databinding.datagrid;
19
20 import java.io.IOException JavaDoc;
21 import java.io.StringWriter JavaDoc;
22 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.JspContext JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 import org.apache.beehive.netui.tags.html.HtmlConstants;
28 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
29 import org.apache.beehive.netui.tags.rendering.CaptionTag;
30 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
31 import org.apache.beehive.netui.tags.rendering.WriteRenderAppender;
32 import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
33 import org.apache.beehive.netui.databinding.datagrid.api.rendering.StyleModel;
34 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.table.TableRenderer;
35 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
36 import org.apache.beehive.netui.util.Bundle;
37
38 /**
39  * <p>
40  * The Caption tag is used to render an HTML &lt;caption&gt; inside of a data grid. The caption
41  * tag should be placed inside of a &lt;netui-data:dataGrid&gt; tag and will produce the
42  * caption for the HTML table that the dataGrid renders.
43  * </p>
44  * <p>
45  * To set HTML attributes on the rendered caption tag, use the attribute setters defined in this tag
46  * </p>
47  * <p>
48  * The set of JSP implicit objects available to the body include:
49  * <ul>
50  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
51  * for the cell's containing data grid.</li>
52  * </ul>
53  * </p>
54  * @jsptagref.tagdescription
55  * <p>
56  * The Caption tag is used to render an HTML &lt;caption&gt; inside of a data grid. The caption
57  * tag should be placed inside of a &lt;netui-data:dataGrid&gt; tag and will produce the
58  * caption for the HTML table that the dataGrid renders.
59  * </p>
60  * <p>
61  * To set HTML attributes on the rendered caption tag, use the attribute setters defined in this tag
62  * </p>
63  * <p>
64  * The set of JSP implicit objects available to the body include:
65  * <ul>
66  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
67  * for the cell's containing data grid.</li>
68  * </ul>
69  * </p>
70  * @netui:tag name="caption" body-content="scriptless"
71  * description="Renders the caption for the HTML table produced by the data grid tag"
72  */

73 public class Caption
74     extends AbstractDataGridHtmlTag {
75
76     private CaptionTag.State _captionTag = new CaptionTag.State();
77
78     /**
79      * The name of this tag; this value is used for error reporting.
80      * @return the String name of this tag
81      */

82     public String JavaDoc getTagName() {
83         return "Caption";
84     }
85
86     /**
87      * Sets the onClick JavaScript event for the HTML attribute.
88      *
89      * @param onClick the onClick event
90      * @jsptagref.attributedescription The onClick JavaScript event for the HTML caption.
91      * @jsptagref.attributesyntaxvalue <i>string_onClick</i>
92      * @netui:attribute required="false" rtexprvalue="true" description="The onClick JavaScript event for the HTML caption."
93      */

94     public void setOnClick(String JavaDoc onClick) {
95         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONCLICK, onClick);
96     }
97
98     /**
99      * Sets the onDblClick JavaScript event for the HTML caption.
100      *
101      * @param onDblClick the onDblClick event
102      * @jsptagref.attributedescription The onDblClick JavaScript event for the HTML caption.
103      * @jsptagref.attributesyntaxvalue <i>string_onDblClick</i>
104      * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript event for the HTML caption."
105      */

106     public void setOnDblClick(String JavaDoc onDblClick) {
107         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONDBLCLICK, onDblClick);
108     }
109
110     /**
111      * Sets the onKeyDown JavaScript event for the HTML caption.
112      *
113      * @param onKeyDown the onKeyDown event
114      * @jsptagref.attributedescription The onKeyDown JavaScript event for the HTML caption.
115      * @jsptagref.attributesyntaxvalue <i>string_onKeyDown</i>
116      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript event for the HTML caption."
117      */

118     public void setOnKeyDown(String JavaDoc onKeyDown) {
119         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYDOWN, onKeyDown);
120     }
121
122     /**
123      * Sets the onKeyUp JavaScript event for the HTML caption.
124      *
125      * @param onKeyUp the onKeyUp event.
126      * @jsptagref.attributedescription The onKeyUp JavaScript event for the HTML caption.
127      * @jsptagref.attributesyntaxvalue <i>string_onKeyUp</i>
128      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript event for the HTML caption."
129      */

130     public void setOnKeyUp(String JavaDoc onKeyUp) {
131         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYUP, onKeyUp);
132     }
133
134     /**
135      * Sets the onKeyPress JavaScript event for the HTML caption.
136      *
137      * @param onKeyPress the onKeyPress event.
138      * @jsptagref.attributedescription The onKeyPress JavaScript event for the HTML caption.
139      * @jsptagref.attributesyntaxvalue <i>string_onKeyPress</i>
140      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript event for the HTML caption."
141      */

142     public void setOnKeyPress(String JavaDoc onKeyPress) {
143         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYPRESS, onKeyPress);
144     }
145
146     /**
147      * Sets the onMouseDown JavaScript event for the HTML caption.
148      *
149      * @param onMouseDown the onMouseDown event.
150      * @jsptagref.attributedescription The onMouseDown JavaScript event for the HTML caption.
151      * @jsptagref.attributesyntaxvalue <i>string_onMouseDown</i>
152      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript event for the HTML caption."
153      */

154     public void setOnMouseDown(String JavaDoc onMouseDown) {
155         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEDOWN, onMouseDown);
156     }
157
158     /**
159      * Sets the onMouseUp JavaScript event for the HTML caption.
160      *
161      * @param onMouseUp the onMouseUp event.
162      * @jsptagref.attributedescription The onMouseUp JavaScript event for the HTML caption.
163      * @jsptagref.attributesyntaxvalue <i>string_onMouseUp</i>
164      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript event for the HTML caption."
165      */

166     public void setOnMouseUp(String JavaDoc onMouseUp) {
167         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEUP, onMouseUp);
168     }
169
170     /**
171      * Sets the onMouseMove JavaScript event for the HTML caption.
172      *
173      * @param onMouseMove the onMouseMove event.
174      * @jsptagref.attributedescription The onMouseMove JavaScript event for the HTML caption.
175      * @jsptagref.attributesyntaxvalue <i>string_onMouseMove</i>
176      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript event for the HTML caption."
177      */

178     public void setOnMouseMove(String JavaDoc onMouseMove) {
179         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEMOVE, onMouseMove);
180     }
181
182     /**
183      * Sets the onMouseOut JavaScript event for the HTML caption.
184      *
185      * @param onMouseOut the onMouseOut event.
186      * @jsptagref.attributedescription The onMouseOut JavaScript event for the HTML caption.
187      * @jsptagref.attributesyntaxvalue <i>string_onMouseOut</i>
188      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript event for the HTML caption."
189      */

190     public void setOnMouseOut(String JavaDoc onMouseOut) {
191         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOUT, onMouseOut);
192     }
193
194     /**
195      * Sets the onMouseOver JavaScript event for the HTML caption.
196      *
197      * @param onMouseOver the onMouseOver event.
198      * @jsptagref.attributedescription The onMouseOver JavaScript event for the HTML caption.
199      * @jsptagref.attributesyntaxvalue <i>string_onMouseOver</i>
200      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript event for the HTML caption."
201      */

202     public void setOnMouseOver(String JavaDoc onMouseOver) {
203         _captionTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOVER, onMouseOver);
204     }
205
206     /**
207      * Sets the style of the HTML caption.
208      *
209      * @param style the caption attribute.
210      * @jsptagref.attributedescription The style of the HTML caption
211      * @jsptagref.attributesyntaxvalue <i>string_style</i>
212      * @netui:attribute required="false" rtexprvalue="true" description="The style of the HTML caption"
213      */

214     public void setStyle(String JavaDoc style) {
215         if("".equals(style)) return;
216
217         _captionTag.style = style;
218     }
219
220     /**
221      * Sets the style class of the HTML caption.
222      *
223      * @param styleClass the style class
224      * @jsptagref.attributedescription The style class of the HTML caption.
225      * @jsptagref.attributesyntaxvalue <i>string_style_class</i>
226      * @netui:attribute required="false" rtexprvalue="true" description="The style class for the HTML caption"
227      */

228     public void setStyleClass(String JavaDoc styleClass) {
229         if("".equals(styleClass)) return;
230
231         _captionTag.styleClass = styleClass;
232     }
233
234     /**
235      * Sets the value of the title attribute for the HTML caption.
236      *
237      * @param title the title attribute
238      * @jsptagref.attributedescription The title attribute for the HTML caption
239      * @jsptagref.attributesyntaxvalue <i>string_title</i>
240      * @netui:attribute required="false" rtexprvalue="true" description="The title attribute for the HTML caption"
241      */

242     public void setTitle(String JavaDoc title) {
243         _captionTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TITLE, title);
244     }
245
246     /**
247      * Sets the value of the language attribute for the HTML caption.
248      *
249      * @param lang the language attribute
250      * @jsptagref.attributedescription The language attribute for the HTML caption
251      * @jsptagref.attributesyntaxvalue <i>string_lang</i>
252      * @netui:attribute required="false" rtexprvalue="true" description="The language attribute for the HTML caption."
253      */

254     public void setLang(String JavaDoc lang) {
255         _captionTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LANG, lang);
256     }
257
258     /**
259      * Sets the value of the text direction attribute for the HTML caption.
260      *
261      * @param dir the dir attribute
262      * @jsptagref.attributedescription The text direction attribute for the caption
263      * @jsptagref.attributesyntaxvalue <i>string_dir</i>
264      * @netui:attribute required="false" rtexprvalue="true" description="The cell's text direction"
265      */

266     public void setDir(String JavaDoc dir) {
267         _captionTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.DIR, dir);
268     }
269
270     /**
271      * Set the name of the tagId for the HTML caption. The page author is responsible for ensuring that the
272      * tagId value is unique within the current page scope.
273      *
274      * @param tagId the the name of the tagId for the caption.
275      * @jsptagref.attributedescription The tagId.
276      * @jsptagref.attributesyntaxvalue <i>string_tagId</i>
277      * @netui:attribute required="false" rtexprvalue="true"
278      * description="String value. Sets the id (or name) attribute of the rendered HTML tag. "
279      */

280     public void setTagId(String JavaDoc tagId)
281         throws JspException JavaDoc {
282         applyTagId(_captionTag, tagId);
283     }
284
285     /**
286      * <p>
287      * Render the caption tag. This tag renders during the data grid's {@link DataGridTagModel#RENDER_STATE_CAPTION}
288      * state and produces an HTML &lt;caption&gt; which contains the result of having evaluated
289      * the body of this tag.
290      * </p>
291      * @throws IOException
292      * @throws JspException when the {@link DataGridTagModel} can not be found in the {@link JspContext}
293      */

294     public void doTag()
295             throws IOException JavaDoc, JspException JavaDoc {
296
297         JspContext JavaDoc jspContext = getJspContext();
298         DataGridTagModel dgm = DataGridUtil.getDataGridTagModel(jspContext);
299         if(dgm == null)
300             throw new JspException JavaDoc(Bundle.getErrorString("DataGridTags_MissingDataGridModel"));
301
302         if(dgm.getRenderState() == DataGridTagModel.RENDER_STATE_CAPTION) {
303             JspFragment JavaDoc fragment = getJspBody();
304             if(fragment != null) {
305                 String JavaDoc captionScript = null;
306                 if(_captionTag.id != null) {
307                     HttpServletRequest JavaDoc request = JspUtil.getRequest(getJspContext());
308                     captionScript = renderNameAndId(request, _captionTag, null);
309                 }
310
311                 StringWriter JavaDoc sw = new StringWriter JavaDoc();
312                 TableRenderer tableRenderer = dgm.getTableRenderer();
313                 StyleModel stylePolicy = dgm.getStyleModel();
314                 AbstractRenderAppender appender = new WriteRenderAppender(jspContext);
315
316                 if(_captionTag.styleClass == null)
317                     _captionTag.styleClass = stylePolicy.getCaptionClass();
318
319                 tableRenderer.openCaption(_captionTag, appender);
320
321                 fragment.invoke(sw);
322                 appender.append(sw.toString());
323
324                 tableRenderer.closeCaption(appender);
325
326                 if(captionScript != null)
327                     appender.append(captionScript);
328             }
329         }
330     }
331 }
332
Popular Tags