KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22
23 import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
24 import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.SpanCellModel;
25 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.SpanCellDecorator;
26 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
27 import org.apache.beehive.netui.tags.html.HtmlConstants;
28 import org.apache.beehive.netui.tags.html.IFormattable;
29 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
30 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
31 import org.apache.beehive.netui.tags.rendering.SpanTag;
32 import org.apache.beehive.netui.tags.IHtmlCore;
33 import org.apache.beehive.netui.tags.IHtmlI18n;
34 import org.apache.beehive.netui.tags.IHtmlEvents;
35
36 /**
37  * <p>
38  * Data grid cell that renders an HTML &lt;span&gt; tag containing the tag's <code>value</code> attribute. The
39  * span cell is rendered inside of an HTML table &lt;td&gt;. The span cell supports various nested tags including
40  * those that provide formatting via the NetUI {@link IFormattable} interface and those that augment the
41  * available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface.
42  * </p>
43  * <p>
44  * The set of JSP implicit objects available to the body include:
45  * <ul>
46  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
47  * for the cell's containing data grid.</li>
48  * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
49  * that exposes the current data item and the current item's index</li>
50  * </ul>
51  * </p>
52  *
53  * @jsptagref.tagdescription
54  * <p>
55  * Data grid cell that renders an HTML &lt;span&gt; tag containing the tag's <code>value</code> attribute. The
56  * span cell is rendered inside of an HTML table &lt;td&gt;. The span cell supports various nested tags including
57  * those that provide formatting via the NetUI {@link IFormattable} interface and those that augment the
58  * available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface.
59  * </p>
60  * <p>
61  * The set of JSP implicit objects available to the body include:
62  * <ul>
63  * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
64  * for the cell's containing data grid.</li>
65  * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
66  * that exposes the current data item and the current item's index</li>
67  * </ul>
68  * </p>
69  *
70  * @netui:tag name="spanCell" body-content="scriptless"
71  * description="Data grid cell that renders its value attribute into an HTML &lt;span&gt;"
72  */

73 public class SpanCell
74     extends AbstractHtmlTableCell
75     implements IFormattable, IHtmlCore, IHtmlEvents, IHtmlI18n {
76
77     private static final SpanCellDecorator DECORATOR = new SpanCellDecorator();
78     private static final String JavaDoc SPAN_FACET_NAME = "span";
79
80     private SpanCellModel _spanCellModel = new SpanCellModel();
81     private SpanTag.State _spanState = _spanCellModel.getSpanState();
82
83     /**
84      * The name of this tag; this value is used for error reporting.
85      * @return the String name of this tag
86      */

87     public String JavaDoc getTagName() {
88         return "SpanCell";
89     }
90
91     /**
92      * Sets the onClick JavaScript event for the HTML span.
93      *
94      * @param onClick the onClick event for the HTML span.
95      * @jsptagref.attributedescription The onClick JavaScript event for the HTML span.
96      * @jsptagref.attributesyntaxvalue <i>string_onClick</i>
97      * @netui:attribute required="false" rtexprvalue="true" description="The onClick JavaScript event."
98      */

99     public void setOnClick(String JavaDoc onClick) {
100         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONCLICK, onClick);
101     }
102
103     /**
104      * Sets the onDblClick JavaScript event for the HTML span.
105      *
106      * @param onDblClick the onDblClick event for the HTML span.
107      * @jsptagref.attributedescription The onDblClick JavaScript event for the HTML span.
108      * @jsptagref.attributesyntaxvalue <i>string_onDblClick</i>
109      * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript event for the HTML span."
110      */

111     public void setOnDblClick(String JavaDoc onDblClick) {
112         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONDBLCLICK, onDblClick);
113     }
114
115     /**
116      * Sets the onKeyDown JavaScript event for the HTML span.
117      *
118      * @param onKeyDown the onKeyDown event for the HTML span.
119      * @jsptagref.attributedescription The onKeyDown JavaScript event for the HTML span.
120      * @jsptagref.attributesyntaxvalue <i>string_onKeyDown</i>
121      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript event for the HTML span."
122      */

123     public void setOnKeyDown(String JavaDoc onKeyDown) {
124         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYDOWN, onKeyDown);
125     }
126
127     /**
128      * Sets the onKeyUp JavaScript event for the HTML span.
129      *
130      * @param onKeyUp the onKeyUp event.
131      * @jsptagref.attributedescription The onKeyUp JavaScript event for the HTML span.
132      * @jsptagref.attributesyntaxvalue <i>string_onKeyUp</i>
133      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript event for the HTML span."
134      */

135     public void setOnKeyUp(String JavaDoc onKeyUp) {
136         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYUP, onKeyUp);
137     }
138
139     /**
140      * Sets the onKeyPress JavaScript event for the HTML span.
141      *
142      * @param onKeyPress the onKeyPress event.
143      * @jsptagref.attributedescription The onKeyPress JavaScript event for the HTML span.
144      * @jsptagref.attributesyntaxvalue <i>string_onKeyPress</i>
145      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript event for the HTML span."
146      */

147     public void setOnKeyPress(String JavaDoc onKeyPress) {
148         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYPRESS, onKeyPress);
149     }
150
151     /**
152      * Sets the onMouseDown JavaScript event for the HTML span.
153      *
154      * @param onMouseDown the onMouseDown event.
155      * @jsptagref.attributedescription The onMouseDown JavaScript event for the HTML span.
156      * @jsptagref.attributesyntaxvalue <i>string_onMouseDown</i>
157      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript event for the HTML span."
158      */

159     public void setOnMouseDown(String JavaDoc onMouseDown) {
160         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEDOWN, onMouseDown);
161     }
162
163     /**
164      * Sets the onMouseUp JavaScript event for the HTML span.
165      *
166      * @param onMouseUp the onMouseUp event.
167      * @jsptagref.attributedescription The onMouseUp JavaScript event for the HTML span.
168      * @jsptagref.attributesyntaxvalue <i>string_onMouseUp</i>
169      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript event for the HTML span."
170      */

171     public void setOnMouseUp(String JavaDoc onMouseUp) {
172         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEUP, onMouseUp);
173     }
174
175     /**
176      * Sets the onMouseMove JavaScript event for the HTML span.
177      *
178      * @param onMouseMove the onMouseMove event.
179      * @jsptagref.attributedescription The onMouseMove JavaScript event for the HTML span.
180      * @jsptagref.attributesyntaxvalue <i>string_onMouseMove</i>
181      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript event for the HTML span."
182      */

183     public void setOnMouseMove(String JavaDoc onMouseMove) {
184         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEMOVE, onMouseMove);
185     }
186
187     /**
188      * Sets the onMouseOut JavaScript event for the HTML span.
189      *
190      * @param onMouseOut the onMouseOut event.
191      * @jsptagref.attributedescription The onMouseOut JavaScript event for the HTML span.
192      * @jsptagref.attributesyntaxvalue <i>string_onMouseOut</i>
193      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript event for the HTML span."
194      */

195     public void setOnMouseOut(String JavaDoc onMouseOut) {
196         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOUT, onMouseOut);
197     }
198
199     /**
200      * Sets the onMouseOver JavaScript event for the HTML span.
201      *
202      * @param onMouseOver the onMouseOver event.
203      * @jsptagref.attributedescription The onMouseOver JavaScript event for the HTML span.
204      * @jsptagref.attributesyntaxvalue <i>string_onMouseOver</i>
205      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript event for the HTML span."
206      */

207     public void setOnMouseOver(String JavaDoc onMouseOver) {
208         _spanState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOVER, onMouseOver);
209     }
210
211     /**
212      * Sets the style for the HTML span.
213      *
214      * @param style the html style.
215      * @jsptagref.attributedescription The style for the HTML span
216      * @jsptagref.attributesyntaxvalue <i>string_style</i>
217      * @netui:attribute required="false" rtexprvalue="true" description="The style for the HTML span"
218      */

219     public void setStyle(String JavaDoc style) {
220         if("".equals(style)) return;
221
222         _spanState.style = style;
223     }
224
225     /**
226      * Sets the style class for the HTML span.
227      *
228      * @param styleClass the html style class.
229      * @jsptagref.attributedescription The style class for the HTML span
230      * @jsptagref.attributesyntaxvalue <i>string_style_class</i>
231      * @netui:attribute required="false" rtexprvalue="true" description="The style class for the HTML span."
232      */

233     public void setStyleClass(String JavaDoc styleClass) {
234         if("".equals(styleClass)) return;
235
236         _spanState.styleClass = styleClass;
237     }
238
239     /**
240      * Sets the value of the title attribute for the HTML span.
241      *
242      * @param title
243      * @jsptagref.attributedescription The title for the HTML span.
244      * @jsptagref.attributesyntaxvalue <i>string_title</i>
245      * @netui:attribute required="false" rtexprvalue="true" description="The title for the HTML span."
246      */

247     public void setTitle(String JavaDoc title) {
248         _spanState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TITLE, title);
249     }
250
251     /**
252      * Sets the lang attribute for the HTML span.
253      * @param lang
254      * @jsptagref.attributedescription The lang for the HTML span.
255      * @jsptagref.attributesyntaxvalue <i>string_lang</i>
256      * @netui:attribute required="false" rtexprvalue="true"
257      * description="The lang for the HTML span"
258      */

259     public void setLang(String JavaDoc lang)
260     {
261         _spanState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LANG, lang);
262     }
263
264     /**
265      * Sets the dir attribute for the HTML span.
266      * @param dir
267      * @jsptagref.attributedescription The dir.
268      * @jsptagref.attributesyntaxvalue <i>string_dir</i>
269      * @netui:attribute required="false" rtexprvalue="true"
270      * description="The dir for the HTML span."
271      */

272     public void setDir(String JavaDoc dir)
273     {
274         _spanState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.DIR, dir);
275     }
276
277     /**
278      * <p>
279      * Set the name of the tagId for the HTML span. This value will have the index of the current data item
280      * in the data set appended to the tagId so that the identifiers are unique in the rendered JSP.
281      * </p>
282      * <p>
283      * For example, if a data set contains {"foo", "bar", "baz"} rendered using a spanCell with a tagId
284      * "theTagId", the resulting tagId values will be {"theTagId0", "theTagId1", "theTagId2"}.
285      *
286      * @param tagId the the name of the tagId for the HTML span.
287      * @jsptagref.attributedescription The tagId.
288      * @jsptagref.attributesyntaxvalue <i>string_tagId</i>
289      * @netui:attribute required="false" rtexprvalue="true"
290      * description="String value. Sets the id (or name) attribute of the rendered HTML span."
291      */

292     public void setTagId(String JavaDoc tagId)
293         throws JspException JavaDoc {
294         applyIndexedTagId(_spanState, tagId);
295     }
296
297     /**
298      * <p>
299      * Set the value rendered inside of the HTML span. This is the visible text that is displayed in the HTML
300      * rendered by this tag.
301      * </p>
302      *
303      * @jsptagref.attributedescription The value of the visible text rendered inside of the HTML span.
304      * @netui:attribute required="true" rtexprvalue="true"
305      */

306     public void setValue(String JavaDoc value) {
307         _spanCellModel.setValue(value);
308     }
309
310     /**
311      * <p>
312      * Implementation of {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface. This
313      * allows a page author to add additional attributes to the HTML rendered by this tag. The attribute
314      * facets which can be consumed include:
315      * <ul>
316      * <li><code>span</code> -- attributes set using this facet will be rendered as HTML attributes on the
317      * rendered HTML &lt;span&gt; tag.</li>
318      * </ul>
319      * </p>
320      * <p>
321      * This tag also accepts facets supported by {@link AbstractHtmlTableCell#setAttribute(String, String, String)}
322      * </p>
323      *
324      * @param name the name of the attribute
325      * @param value the value of the attribute
326      * @param facet the facet for the attribute; this value must be match one of the facets supported by the JSP tags
327      * @throws JspException thrown when the given facet String is not recognized as a valid facet name
328      */

329     public void setAttribute(String JavaDoc name, String JavaDoc value, String JavaDoc facet)
330             throws JspException JavaDoc {
331         if(facet == null || facet.equals(SPAN_FACET_NAME))
332             super.addStateAttribute(_spanState, name, value);
333         else
334             super.setAttribute(name, value, facet);
335     }
336
337     /**
338      * Render the cell's contents. This method implements support for executing the span cell's decorator.
339      * @param appender the {@link AbstractRenderAppender} used to collect the rendered output
340      * @param jspFragmentOutput the String result of having evaluated the span cell's {@link javax.servlet.jsp.tagext.JspFragment}
341      */

342     protected void renderDataCellContents(AbstractRenderAppender appender, String JavaDoc jspFragmentOutput) {
343         /* render any JavaScript needed to support framework features */
344         if (_spanState.id != null) {
345             HttpServletRequest JavaDoc request = JspUtil.getRequest(getJspContext());
346             String JavaDoc script = renderNameAndId(request, _spanState, null);
347             if(script != null)
348                 _spanCellModel.setJavascript(script);
349         }
350
351         DECORATOR.decorate(getJspContext(), appender, _spanCellModel);
352     }
353
354     /**
355      * Implementation of {@link AbstractHtmlTableCell#internalGetCellModel()} that exposes the
356      * {@link org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.SpanCellModel}
357      * which is storing state for this tag.
358      * @return this tag's span cell model
359      */

360     protected CellModel internalGetCellModel() {
361         return _spanCellModel;
362     }
363 }
364
Popular Tags