KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 import org.apache.beehive.netui.tags.IBehaviorConsumer;
28 import org.apache.beehive.netui.tags.IAttributeConsumer;
29 import org.apache.beehive.netui.tags.html.HtmlConstants;
30 import org.apache.beehive.netui.tags.html.IFormattable;
31 import org.apache.beehive.netui.tags.rendering.ThTag;
32 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
33 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
34 import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.HeaderCellModel;
35 import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
36 import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellDecorator;
37 import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
38 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.HeaderCellDecorator;
39 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.SortedCellDecorator;
40 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.table.TableRenderer;
41 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
42 import org.apache.beehive.netui.databinding.datagrid.runtime.util.ExtensionUtil;
43 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel;
44 import org.apache.beehive.netui.databinding.datagrid.api.filter.FilterModel;
45 import org.apache.beehive.netui.util.Bundle;
46
47 /**
48  * <p>
49  * This tag is used to render an HTML table header cell and should generally be used inside of the data grid's
50  * {@link Header} tag. Cells rendered with this tag usually appear at the top of a column of data displayed
51  * in a grid. Content for the body of a table header cell can be specified in one of two ways:
52  * <ul>
53  * <li>from the {@link #setHeaderText(String)} attribute</li>
54  * <li>from the tag's body</li>
55  * </ul>
56  * This tag can accept in its body any content which is allowable inside of a JSP {@link javax.servlet.jsp.tagext.SimpleTag}.
57  * If the header text attribute is provided, it will supercede the content rendered by the body, though the body
58  * will still be evaluated.
59  * </p>
60  * <p>
61  * The header cell is also able to display UI for showing and changing the sort and filter state of a data grid.
62  * By default, this tag renders a clickable arrow indicating the sort state and allow ing a page user to change
63  * the sort state. The state of a sort is usually associated with the data displayed in a column though the
64  * data in the column and the expression used to sort the data are loosely coupled via a 'sort expression'. The
65  * sort expression text is used to lookup the {@link org.apache.beehive.netui.databinding.datagrid.api.sort.Sort} state
66  * from the {@link org.apache.beehive.netui.databinding.datagrid.api.DataGridState} associated with the containing
67  * data grid. If sorts are found, this tag will render the appropriate UI for the sort. Only a single sort
68  * may be associated with the sort expression. The clickable link rendered for changing the sort state is built
69  * using either the {@link #setSortHref(String)} or the {@link #setSortAction(String)} attributes. Sort UI rendering
70  * can be disabled using the {@link #setDisableSortRendering(boolean)} attribute. Custom UI can be rendered
71  * for changing or displaying the sort state by providing a body for this tag and using the JSP EL data bindable
72  * {@link org.apache.beehive.netui.databinding.datagrid.api.DataGridState} object available via the data
73  * grid's <code>dataGrid</code> implicit object.
74  * </p>
75  * <p>
76  * The header cell provides attributes for supporting authoring of filter UI, but this tag does not by default
77  * implement a filter UI. The attributes are provided here so that their values can be data bound when building
78  * custom filter UI.
79  * </p>
80  * <p>
81  * The set of JSP implicit objects available to the body include:
82  * <ul>
83  * <li><code>dataGrid</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
84  * for the cell's containing data grid.</li>
85  * <li><code>cellModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel}
86  * containing state for the attributes of this tag.</li>
87  * </ul>
88  * </p>
89  *
90  * @jsptagref.tagdescription
91  * <p>
92  * This tag is used to render an HTML table header cell and should generally be used inside of the data grid's
93  * {@link Header} tag. Cells rendered with this tag usually appear at the top of a column of data displayed
94  * in a grid. Content for the body of a table header cell can be specified in one of two ways:
95  * <ul>
96  * <li>from the {@link #setHeaderText(String)} attribute</li>
97  * <li>from the tag's body</li>
98  * </ul>
99  * This tag can accept in its body any content which is allowable inside of a JSP {@link javax.servlet.jsp.tagext.SimpleTag}.
100  * If the header text attribute is provided, it will supercede the content rendered by the body, though the body
101  * will still be evaluated.
102  * </p>
103  * <p>
104  * The header cell is also able to display UI for showing and changing the sort and filter state of a data grid.
105  * By default, this tag renders a clickable arrow indicating the sort state and allow ing a page user to change
106  * the sort state. The state of a sort is usually associated with the data displayed in a column though the
107  * data in the column and the expression used to sort the data are loosely coupled via a 'sort expression'. The
108  * sort expression text is used to lookup the {@link org.apache.beehive.netui.databinding.datagrid.api.sort.Sort} state
109  * from the {@link org.apache.beehive.netui.databinding.datagrid.api.DataGridState} associated with the containing
110  * data grid. If sorts are found, this tag will render the appropriate UI for the sort. Only a single sort
111  * may be associated with the sort expression. The clickable link rendered for changing the sort state is built
112  * using either the {@link #setSortHref(String)} or the {@link #setSortAction(String)} attributes. Sort UI rendering
113  * can be disabled using the {@link #setDisableSortRendering(boolean)} attribute. Custom UI can be rendered
114  * for changing or displaying the sort state by providing a body for this tag and using the JSP EL data bindable
115  * {@link org.apache.beehive.netui.databinding.datagrid.api.DataGridState} object available via the data
116  * grid's <code>dataGrid</code> implicit object.
117  * </p>
118  * <p>
119  * The header cell provides attributes for supporting authoring of filter UI, but this tag does not by default
120  * implement a filter UI. The attributes are provided here so that their values can be data bound when building
121  * custom filter UI.
122  * </p>
123  * <p>
124  * The set of JSP implicit objects available to the body include:
125  * <ul>
126  * <li><code>dataGrid</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
127  * for the cell's containing data grid.</li>
128  * <li><code>cellModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel}
129  * containing state for the attributes of this tag.</li>
130  * </ul>
131  * </p>
132  * @netui:tag name="headerCell" body-content="scriptless"
133  * description="Render an HTML table head cell inside of a data grid"
134  */

135 public class HeaderCell
136     extends AbstractCell
137     implements IFormattable, IBehaviorConsumer, IAttributeConsumer {
138
139     private static final String JavaDoc TAG_NAME = "HeaderCell";
140     private static final String JavaDoc ATTRIBUTE_HEADER_NAME = "header";
141     private static final String JavaDoc BEHAVIOR_RENDERER_NAME = "renderer";
142     private static final String JavaDoc BEHAVIOR_RENDERER_NAME_DEFAULT = "default";
143     private static final String JavaDoc BEHAVIOR_RENDERER_NAME_SORT = "sort";
144     private static final String JavaDoc BEHAVIOR_RENDERER_NAME_EXTENDS = "extends";
145
146     private static final CellDecorator DECORATOR_HEADER_DEFAULT;
147     private static final CellDecorator DECORATOR_HEADER_SORTED;
148
149     static {
150         DECORATOR_HEADER_DEFAULT = new HeaderCellDecorator();
151         DECORATOR_HEADER_SORTED = new SortedCellDecorator(DECORATOR_HEADER_DEFAULT);
152     }
153
154     private String JavaDoc _headerText = null;
155     private ThTag.State _cellState = new ThTag.State();
156     private HeaderCellModel _headerCellModel = new HeaderCellModel();
157     private CellDecorator _cellDecorator = null;
158
159     /**
160      * The name of this tag; this value is used for error reporting.
161      * @return the String name of this tag
162      */

163     public String JavaDoc getTagName() {
164         return TAG_NAME;
165     }
166
167     /**
168      * Sets the text to render for this table header cell. This text will be rendered inside of the
169      * &lt;th&gt; tags.
170      *
171      * @param headerText The text to render.
172      * @jsptagref.attributedescription
173      * Sets the text to render for this table header cell. This text will be rendered inside of the
174      * &lt;th&gt; tags.
175      * @jsptagref.attributesyntaxvalue <i>string_headerText</i>
176      * @netui:attribute required="false" rtexprvalue="true"
177      * description="The text to render inside of the HTML th tag."
178      */

179     public void setHeaderText(String JavaDoc headerText) {
180         _headerText = headerText;
181     }
182
183     /**
184      * Sets the scopeId for any anchors rendered by this header cell.
185      *
186      * @param scopeId
187      * @jsptagref.attributedescription
188      * Sets the scopeId for any anchors rendered by this header cell.
189      * @jsptagref.attributesyntaxvalue <i>string_scopeId</i>
190      * @netui:attribute required="false" rtexprvalue="true"
191      * description="Optional String scopeId that qualifies URL parameters into a particular scope"
192      */

193     public void setScopeId(String JavaDoc scopeId) {
194         _headerCellModel.setScopeId(scopeId);
195     }
196
197     /**
198      * Set a boolean which can be used to enable / disable rendering of UI associated with filtering inside
199      * of the data grid.
200      * @param disableFilterRendering boolean to enable / disable filter UI rendering
201      * @jsptagref.attributedescription
202      * Set a boolean which can be used to enable / disable rendering of UI associated with filtering inside
203      * of the data grid.
204      * @jsptagref.attributesyntaxvalue <i>string_disableFilterRendering</i>
205      * @netui:attribute required="false" rtexprvalue="true"
206      * description="Boolean to enable / disable filter UI rendering"
207      */

208     public void setDisableFilterRendering(boolean disableFilterRendering) {
209         _headerCellModel.setDisableFilterRendering(disableFilterRendering);
210     }
211
212     /**
213      * Set the filter expression for this header cell. The value of this attribute is used to lookup
214      * {@link org.apache.beehive.netui.databinding.datagrid.api.filter.Filter} state for a data grid
215      * If filters are found matching this filter expression, the column is said to be 'filtered'. When
216      * a column is filtered, it is possible for the header cell UI to change to allow changing or
217      * removing the filter. By default, no UI is rendered for filtered columns. To have data cells
218      * rendered with filter information, this filter expression value should be set on the
219      * {@link AbstractHtmlTableCell#setFilterExpression(String)} attribute for cell tags rendered
220      * inside of the {@link Rows} tag.
221      *
222      * @param filterExpression the filter expression
223      * @jsptagref.attributedescription
224      * Set the filter expression for this header cell. The value of this attribute is used to lookup
225      * {@link org.apache.beehive.netui.databinding.datagrid.api.filter.Filter} state for a data grid
226      * If filters are found matching this filter expression, the column is said to be 'filtered'. When
227      * a column is filtered, it is possible for the header cell UI to change to allow changing or
228      * removing the filter. By default, no UI is rendered for filtered columns. To have data cells
229      * rendered with filter information, this filter expression value should be set on the
230      * {@link AbstractHtmlTableCell#setFilterExpression(String)} attribute for cell tags rendered
231      * inside of the {@link Rows} tag.
232      * @jsptagref.attributesyntaxvalue <i>string_filterExpression</i>
233      * @netui:attribute required="false" rtexprvalue="true"
234      * description="String filter expression that is used to lookup a data grid's Filter state"
235      */

236     public void setFilterExpression(String JavaDoc filterExpression) {
237         _headerCellModel.setFilterExpression(filterExpression);
238     }
239
240     /**
241      * Set the name of an action used to perform filtering on a data grid. This action must exist in the context
242      * of the current Page Flow. It is used to build anchor URIs that when clicked change or display UI that allows
243      * for change to the cell's filter state. Only one of this and the {@link #setFilterHref(String)} may be
244      * set on this tag.
245      * @param filterAction the filter action
246      * @jsptagref.attributedescription
247      * Set the name of an action used to perform filtering on a data grid. This action must exist in the context
248      * of the current Page Flow. It is used to build anchor URIs that when clicked change or display UI that allows
249      * for change to the cell's filter state. Only one of this and the {@link #setFilterHref(String)} may be
250      * set on this tag.
251      * @jsptagref.attributesyntaxvalue <i>string_filterAction</i>
252      * @netui:attribute required="false" rtexprvalue="true"
253      * description="The action used to build URIs used to change the filter state of this cell"
254      */

255     public void setFilterAction(String JavaDoc filterAction) {
256         _headerCellModel.setFilterAction(filterAction);
257     }
258
259     /**
260      * Set an href used to build URIs to change the filter state for this header cell. Only one of this and
261      * the {@link #setFilterAction(String)} attribute may be set on this tag.
262      * @param filterHref the filter href
263      * @jsptagref.attributedescription
264      * Set an href used to build URIs to change the filter state for this header cell. Only one of this and
265      * the {@link #setFilterAction(String)} attribute may be set on this tag.
266      * @jsptagref.attributesyntaxvalue <i>string_filterHref</i>
267      * @netui:attribute required="false" rtexprvalue="true"
268      * description="The href to use when performing a filter on this column"
269      */

270     public void setFilterHref(String JavaDoc filterHref) {
271         _headerCellModel.setFilterHref(filterHref);
272     }
273
274     /**
275      * Set a boolean which can be used to enable / disable rendering of UI associated with sorting inside
276      * of the data grid.
277      * @param disableSortRendering boolean to enable / disable sort UI rendering
278      * @jsptagref.attributedescription
279      * Set a boolean which can be used to enable / disable rendering of UI associated with sorting inside
280      * of the data grid.
281      * @jsptagref.attributesyntaxvalue <i>string_disableSortRendering</i>
282      * @netui:attribute required="false" rtexprvalue="true"
283      * description="Boolean to enable / disable sort UI rendering"
284      */

285     public void setDisableSortRendering(boolean disableSortRendering) {
286         _headerCellModel.setDisableSortRendering(disableSortRendering);
287     }
288
289     /**
290      * Set the sort expression for this header cell. The value of this attribute is used to lookup
291      * {@link org.apache.beehive.netui.databinding.datagrid.api.sort.Sort} state for a data grid
292      * If sorts are found matching this filter expression, the column is said to be 'sorted'. When
293      * a column is sorted, it is possible for the header cell UI to change to allow changing or
294      * removing the filter. By default, the UI for sorting is a clickable arrow that indicates whether
295      * a column of data is sorted ascending, descending, or not at all. To have data cells
296      * rendered with sort information, this sort expression value should be set on the
297      * {@link AbstractHtmlTableCell#setSortExpression(String)} attribute for cell tags rendered
298      * inside of the {@link Rows} tag.
299      *
300      * @param sortExpression the sort expression
301      * @jsptagref.attributedescription
302      * @jsptagref.attributesyntaxvalue <i>string_sortExpression</i>
303      * @netui:attribute required="false" rtexprvalue="true"
304      * description="String sort expression that is used to lookup a data grid's Sort state"
305      */

306     public void setSortExpression(String JavaDoc sortExpression) {
307         _headerCellModel.setSortExpression(sortExpression);
308     }
309
310     /**
311      * Set the name of an action used to perform sorting on a data grid. This action must exist in the context
312      * of the current Page Flow. It is used to build anchor URIs that when clicked change or display UI that allows
313      * for change to the cell's sort state. Only one of this and the {@link #setSortHref(String)} may be
314      * set on this tag.
315      * @param sortAction the sort action
316      * @jsptagref.attributedescription
317      * @jsptagref.attributesyntaxvalue <i>string_sortAction</i>
318      * @netui:attribute required="false" rtexprvalue="true"
319      * description="The action used to build URIs used to change the sort state of this cell"
320      */

321     public void setSortAction(String JavaDoc sortAction) {
322         _headerCellModel.setSortAction(sortAction);
323     }
324
325     /**
326      * Set an href used to build URIs to change the sort state for this header cell. Only one of this and
327      * the {@link #setSortAction(String)} attribute may be set on this tag.
328      * @param sortHref the sort href
329      * @jsptagref.attributedescription
330      * Set an href used to build URIs to change the sort state for this header cell. Only one of this and
331      * the {@link #setSortAction(String)} attribute may be set on this tag.
332      * @jsptagref.attributesyntaxvalue <i>string_sortHref</i>
333      * @netui:attribute required="false" rtexprvalue="true"
334      * description="The href to use when performing a sort on this column"
335      */

336     public void setSortHref(String JavaDoc sortHref) {
337         _headerCellModel.setSortHref(sortHref);
338     }
339
340     /* --------------------------------------------------------------
341      *
342      * <th> attributes
343      *
344      * --------------------------------------------------------------
345      */

346
347     /**
348      * Sets the onClick JavaScript for the HTML th tag.
349      *
350      * @param onClick the onClick event.
351      * @jsptagref.attributedescription The onClick JavaScript for the HTML th tag.
352      * @jsptagref.attributesyntaxvalue <i>string_cellOnClick</i>
353      * @netui:attribute required="false" rtexprvalue="true" description="The onClick JavaScript for the HTML th tag."
354      */

355     public void setCellOnClick(String JavaDoc onClick) {
356         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONCLICK, onClick);
357     }
358
359     /**
360      * Sets the onDblClick JavaScript for the HTML th tag.
361      *
362      * @param onDblClick the onDblClick event.
363      * @jsptagref.attributedescription The onDblClick JavaScript for the HTML th tag.
364      * @jsptagref.attributesyntaxvalue <i>string_cellOnDblClick</i>
365      * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript for the HTML th tag."
366      */

367     public void setCellOnDblClick(String JavaDoc onDblClick) {
368         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONDBLCLICK, onDblClick);
369     }
370
371     /**
372      * Sets the onKeyDown JavaScript for the HTML th tag.
373      *
374      * @param onKeyDown the onKeyDown event.
375      * @jsptagref.attributedescription The onKeyDown JavaScript for the HTML th tag.
376      * @jsptagref.attributesyntaxvalue <i>string_cellOnKeyDown</i>
377      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript for the HTML th tag."
378      */

379     public void setCellOnKeyDown(String JavaDoc onKeyDown) {
380         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYDOWN, onKeyDown);
381     }
382
383     /**
384      * Sets the onKeyUp JavaScript for the HTML th tag.
385      *
386      * @param onKeyUp the onKeyUp event.
387      * @jsptagref.attributedescription The onKeyUp JavaScript for the HTML th tag.
388      * @jsptagref.attributesyntaxvalue <i>string_cellOnKeyUp</i>
389      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript for the HTML th tag."
390      */

391     public void setCellOnKeyUp(String JavaDoc onKeyUp) {
392         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYUP, onKeyUp);
393     }
394
395     /**
396      * Sets the onKeyPress JavaScript for the HTML th tag.
397      *
398      * @param onKeyPress the onKeyPress event.
399      * @jsptagref.attributedescription The onKeyPress JavaScript event for the HTML th tag.
400      * @jsptagref.attributesyntaxvalue <i>string_cellOnKeyPress</i>
401      * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript for the HTML th tag."
402      */

403     public void setCellOnKeyPress(String JavaDoc onKeyPress) {
404         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYPRESS, onKeyPress);
405     }
406
407     /**
408      * Sets the onMouseDown JavaScript for the HTML th tag.
409      *
410      * @param onMouseDown the onMouseDown event.
411      * @jsptagref.attributedescription The onMouseDown JavaScript for the HTML th tag.
412      * @jsptagref.attributesyntaxvalue <i>string_cellOnMouseDown</i>
413      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript for the HTML th tag."
414      */

415     public void setCellOnMouseDown(String JavaDoc onMouseDown) {
416         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEDOWN, onMouseDown);
417     }
418
419     /**
420      * Sets the onMouseUp JavaScript for the HTML th tag.
421      *
422      * @param onMouseUp the onMouseUp event.
423      * @jsptagref.attributedescription The onMouseUp JavaScript for the HTML th tag.
424      * @jsptagref.attributesyntaxvalue <i>string_cellOnMouseUp</i>
425      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript for the HTML th tag."
426      */

427     public void setCellOnMouseUp(String JavaDoc onMouseUp) {
428         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEUP, onMouseUp);
429     }
430
431     /**
432      * Sets the onMouseMove JavaScript for the HTML th tag.
433      *
434      * @param onMouseMove the onMouseMove event.
435      * @jsptagref.attributedescription The onMouseMove JavaScript for the HTML th tag.
436      * @jsptagref.attributesyntaxvalue <i>string_cellOnMouseMove</i>
437      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript for the HTML th tag."
438      */

439     public void setCellOnMouseMove(String JavaDoc onMouseMove) {
440         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEMOVE, onMouseMove);
441     }
442
443     /**
444      * Sets the onMouseOut JavaScript for the HTML th tag.
445      *
446      * @param onMouseOut the onMouseOut event.
447      * @jsptagref.attributedescription The onMouseOut JavaScript event for the HTML th tag.
448      * @jsptagref.attributesyntaxvalue <i>string_cellOnMouseOut</i>
449      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript for the HTML th tag."
450      */

451     public void setCellOnMouseOut(String JavaDoc onMouseOut) {
452         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOUT, onMouseOut);
453     }
454
455     /**
456      * Sets the onMouseOver JavaScript for the HTML th tag.
457      *
458      * @param onMouseOver the onMouseOver event.
459      * @jsptagref.attributedescription The onMouseOver JavaScript for the HTML th tag.
460      * @jsptagref.attributesyntaxvalue <i>string_cellOnMouseOver</i>
461      * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript for the HTML th tag."
462      */

463     public void setCellOnMouseOver(String JavaDoc onMouseOver) {
464         _cellState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOVER, onMouseOver);
465     }
466
467     /**
468      * Sets the style for the HTML th tag.
469      *
470      * @param style the style
471      * @jsptagref.attributedescription The style for the HTML th tag.
472      * @jsptagref.attributesyntaxvalue <i>string_cellStyle</i>
473      * @netui:attribute required="false" rtexprvalue="true" description="The style for the HTML th tag."
474      */

475     public void setCellStyle(String JavaDoc style) {
476         if("".equals(style)) return;
477
478         _cellState.style = style;
479     }
480
481     /**
482      * Sets the style class for the HTML th tag.
483      *
484      * @param styleClass the style class
485      * @jsptagref.attributedescription The style class for the HTML th tag.
486      * @jsptagref.attributesyntaxvalue <i>string_cellStyleClass</i>
487      * @netui:attribute required="false" rtexprvalue="true" description="The style class for the HTML th tag."
488      */

489     public void setCellStyleClass(String JavaDoc styleClass) {
490         if("".equals(styleClass)) return;
491
492         _cellState.styleClass = styleClass;
493     }
494
495     /**
496      * Sets the value of the title attribute for the HTML th tag.
497      *
498      * @param title the title
499      * @jsptagref.attributedescription The title for the HTML th tag.
500      * @jsptagref.attributesyntaxvalue <i>string_cellTitle</i>
501      * @netui:attribute required="false" rtexprvalue="true" description="The title for the HTML th tag."
502      */

503     public void setCellTitle(String JavaDoc title) {
504         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TITLE, title);
505     }
506
507     /**
508      * Sets the value of the rowspan attribute for the HTML th tag.
509      *
510      * @param rowSpan the rowspan
511      * @jsptagref.attributedescription The row span for the HTML th tag.
512      * @jsptagref.attributesyntaxvalue <i>int_cellRowspan</i>
513      * @netui:attribute required="false" rtexprvalue="true" description="The rowspan for the HTML th tag."
514      */

515     public void setCellRowspan(int rowSpan) {
516         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ROWSPAN, "" + rowSpan);
517     }
518
519     /**
520      * Sets the value of the colspan attribute for the HTML th tag.
521      *
522      * @param colSpan the colspan
523      * @jsptagref.attributedescription The colspan for the HTML th tag.
524      * @jsptagref.attributesyntaxvalue <i>int_cellColspan</i>
525      * @netui:attribute required="false" rtexprvalue="true" description="The colspan for the HTML th tag."
526      */

527     public void setCellColspan(int colSpan) {
528         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.COLSPAN, "" + colSpan);
529     }
530
531     /**
532      * Sets the value of the horizontal align attribute for the HTML th tag..
533      *
534      * @param align the horizontal alignment
535      * @jsptagref.attributedescription The horizontal alignment for the HTML th tag.
536      * @jsptagref.attributesyntaxvalue <i>string_cellAlign</i>
537      * @netui:attribute required="false" rtexprvalue="true"
538      * description="The horizontal alignment for the HTML th tag"
539      */

540     public void setCellAlign(String JavaDoc align) {
541         /* todo: should this enforce left|center|right|justify|char as in the spec */
542         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ALIGN, align);
543     }
544
545     /**
546      * Sets the value of the horizontal alignment character attribute for the HTML th tag.
547      *
548      * @param alignChar the alignment character
549      * @jsptagref.attributedescription The horizontal alignment character for the HTML th tag.
550      * @jsptagref.attributesyntaxvalue <i>string_cellAlignChar</i>
551      * @netui:attribute required="false" rtexprvalue="true"
552      * description="The horizontal alignment character for the HTML th tag."
553      */

554     public void setCellChar(String JavaDoc alignChar) {
555         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.CHAR, alignChar);
556     }
557
558     /**
559      * Sets the value of the horizontal alignment character offset for the HTML th tag..
560      *
561      * @param alignCharOff the horizontal alignment character offset
562      * @jsptagref.attributedescription The horizontal alignment character offset for the HTML th tag.
563      * @jsptagref.attributesyntaxvalue <i>string_cellAlignCharOff</i>
564      * @netui:attribute required="false" rtexprvalue="true"
565      * description="The horizontal alignment character offset for the HTML th tag."
566      */

567     public void setCellCharoff(String JavaDoc alignCharOff) {
568         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.CHAROFF, alignCharOff);
569     }
570
571     /**
572      * Sets the value of the vertical alignment attribute for the HTML th tag.
573      *
574      * @param align the vertical alignment attribute
575      * @jsptagref.attributedescription The vertical alignment for the HTML th tag.
576      * @jsptagref.attributesyntaxvalue <i>string_cellValign</i>
577      * @netui:attribute required="false" rtexprvalue="true"
578      * description="The cell's vertical alignment for the HTML th tag."
579      */

580     public void setCellValign(String JavaDoc align) {
581         /* todo: should this enforce top|middle|bottom|baseline as in the spec */
582         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.VALIGN, align);
583     }
584
585     /**
586      * Sets the value of the language attribute for the HTML th tag.
587      *
588      * @param lang the language attribute
589      * @jsptagref.attributedescription The language for the HTML th tag.
590      * @jsptagref.attributesyntaxvalue <i>string_cellLang</i>
591      * @netui:attribute required="false" rtexprvalue="true" description="The language attribute for the HTML th tag."
592      */

593     public void setCellLang(String JavaDoc lang) {
594         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LANG, lang);
595     }
596
597     /**
598      * Sets the value of the text direction attribute for the HTML th tag.
599      *
600      * @param dir the text direction
601      * @jsptagref.attributedescription The text direction attribute for the HTML th tag.
602      * @jsptagref.attributesyntaxvalue <i>string_cellDir</i>
603      * @netui:attribute required="false" rtexprvalue="true" description="The text direction for the HTML th tag."
604      */

605     public void setCellDir(String JavaDoc dir) {
606         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.DIR, dir);
607     }
608
609     /**
610      * Sets the value of the abbreviated form of the content for the HTML th tag.
611      *
612      * @param abbr the abbr
613      * @jsptagref.attributedescription The abbreviated form of the cell's content for the HTML th tag.
614      * @jsptagref.attributesyntaxvalue <i>string_cellDir</i>
615      * @netui:attribute required="false" rtexprvalue="true" description="The abbreviated form of the cell's content for the HTML th tag."
616      */

617     public void setCellAbbr(String JavaDoc abbr) {
618         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ABBR, abbr);
619     }
620
621     /**
622      * Sets the value of the axis attribute for the HTML th tag.
623      *
624      * @param axis the axis
625      * @jsptagref.attributedescription The axis attribute for the HTML th tag.
626      * @jsptagref.attributesyntaxvalue <i>string_cellAxis</i>
627      * @netui:attribute required="false" rtexprvalue="true" description="The axis attribute for the HTML th tag"
628      */

629     public void setCellAxis(String JavaDoc axis) {
630         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.AXIS, axis);
631     }
632
633     /**
634      * Sets the value of the headers attribute for the HTML th tag.
635      *
636      * @param headers the headers
637      * @jsptagref.attributedescription The headers attribute for the HTML th tag.
638      * @jsptagref.attributesyntaxvalue <i>string_cellHeaders</i>
639      * @netui:attribute required="false" rtexprvalue="true" description="The headers attribute for the HTML th tag."
640      */

641     public void setCellHeaders(String JavaDoc headers) {
642         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.HEADERS, headers);
643     }
644
645     /**
646      * Sets the value of the scope attribute for the HTML th tag.
647      *
648      * @param scope the scope
649      * @jsptagref.attributedescription The scope attribute for the HTML th tag.
650      * @jsptagref.attributesyntaxvalue <i>string_cellScope</i>
651      * @netui:attribute required="false" rtexprvalue="true" description="The scope attribute for the HTML th tag.
652      */

653     public void setCellScope(String JavaDoc scope) {
654         _cellState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.SCOPE, scope);
655     }
656
657     /**
658      * Set the name of the tagId for the HTML th tag.
659      *
660      * @param tagId the the name of the tagId for the th tag.
661      * @jsptagref.attributedescription The tagId for the HTML th tag.
662      * @jsptagref.attributesyntaxvalue <i>string_cellTagId</i>
663      * @netui:attribute required="false" rtexprvalue="true"
664      * description="String value. Sets the id (or name) attribute of the HTML th tag."
665      */

666     public void setCellTagId(String JavaDoc tagId)
667         throws JspException JavaDoc {
668         applyTagId(_cellState, tagId);
669     }
670
671     /**
672      * <p>
673      * Implementation of the {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface. This
674      * allows users of the anchorCell tag to extend the attribute set that is rendered by the HTML
675      * anchor. This method accepts the following facets:
676      * <table>
677      * <tr><td>Facet Name</td><td>Operation</td></tr>
678      * <tr><td><code>header</code></td><td>Adds an attribute with the provided <code>name</code> and <code>value</code> to the
679      * attributes rendered on the &lt;th&gt; tag.</td></tr>
680      * </table>
681      * The HeaderCell tag defaults to the setting attributes on the header when the facet name is unset.
682      * </p>
683      * @param name the name of the attribute
684      * @param value the value of the attribute
685      * @param facet the facet for the attribute
686      * @throws JspException thrown when the facet is not recognized
687      */

688     public void setAttribute(String JavaDoc name, String JavaDoc value, String JavaDoc facet) throws JspException JavaDoc {
689         if(facet == null || facet.equals(ATTRIBUTE_HEADER_NAME)) {
690             super.addStateAttribute(_cellState, name, value);
691         }
692         else {
693             String JavaDoc s = Bundle.getString("Tags_AttributeFacetNotSupported", new Object JavaDoc[]{facet});
694             throw new JspException JavaDoc(s);
695         }
696     }
697
698     /**
699      * <p>
700      * Implementation of the {@link IBehaviorConsumer} interface that extends the functionality of this
701      * tag beyond that exposed via the JSP tag attributes. This method accepts the following facets:
702      * <table>
703      * <tr><td>Facet Name</td><td>Operation</td></tr>
704      * <tr><td><code>renderer</code></td><td>Extends the cell decorator chain used to implement rendering for this tag</td></tr>
705      * </table>
706      * The <code>renderer</code> facet accepts the following behavior names. The value of each should be a String classname
707      * of a class that extends the {@link CellDecorator} base class.
708      * <table>
709      * <tr><td>extends</td><td>Add an additional decorator to the currently configured cell decorator chain.</td></tr>
710      * <tr><td>sort</td><td>Replace the currently configured sort decorator with one created from this class name.</td></tr>
711      * </table>
712      * </p>
713      * @param name the name of the behavior
714      * @param value the value of the behavior
715      * @param facet th ebehavior's facet
716      * @throws JspException when the behavior's facet isnot recognized
717      */

718     public void setBehavior(String JavaDoc name, Object JavaDoc value, String JavaDoc facet) throws JspException JavaDoc {
719         if(facet != null && facet.equals(BEHAVIOR_RENDERER_NAME)) {
720             String JavaDoc className = value != null ? value.toString() : null;
721             /* provides a way to extend the existing decorators */
722             CellDecorator cellDecorator = (CellDecorator)ExtensionUtil.instantiateClass(className, CellDecorator.class);
723             if(name.equals(BEHAVIOR_RENDERER_NAME_EXTENDS)) {
724                 cellDecorator.setNestedDecorator(getCellDecorator());
725             }
726             else if(name.equals(BEHAVIOR_RENDERER_NAME_SORT)) {
727                 cellDecorator.setNestedDecorator(DECORATOR_HEADER_SORTED);
728             }
729             /* replace the core cell decorator with a new default */
730             else if(name.equals(BEHAVIOR_RENDERER_NAME_DEFAULT)) {
731                 /* nyi */
732             }
733
734             _cellDecorator = cellDecorator;
735         }
736         else {
737             String JavaDoc s = Bundle.getString("Tags_BehaviorFacetNotSupported", new Object JavaDoc[]{facet});
738             throw new JspException JavaDoc(s);
739         }
740     }
741
742     /**
743      * Implementation of {@link AbstractHtmlTableCell#internalGetCellModel()} that exposes the
744      * {@link org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.HeaderCellModel}
745      * which is storing state for this tag.
746      * @return this tag's cell model
747      */

748     protected CellModel internalGetCellModel() {
749         return _headerCellModel;
750     }
751
752     /**
753      * Render the header cell's contents. This method sets the style information on the HTML
754      * th tag and then calls the
755      * {@link #renderHeaderCellContents(org.apache.beehive.netui.tags.rendering.AbstractRenderAppender, String)}
756      * method to render the contents of the cell.
757      * @param appender the {@link AbstractRenderAppender} to which the output from this tag should be added
758      * @throws IOException
759      * @throws JspException
760      */

761     protected void renderCell(AbstractRenderAppender appender)
762             throws IOException JavaDoc, JspException JavaDoc {
763
764         DataGridTagModel dataGridModel = DataGridUtil.getDataGridTagModel(getJspContext());
765         assert dataGridModel != null;
766
767         TableRenderer tableRenderer = dataGridModel.getTableRenderer();
768         assert tableRenderer != null;
769
770         ArrayList JavaDoc/*<String>*/ styleClasses = new ArrayList JavaDoc/*<String>*/();
771
772         /* todo: refactor. add a chain of style decorators here; easier to extend this way. */
773         FilterModel filterModel = dataGridModel.getState().getFilterModel();
774         if(filterModel.isFiltered(_headerCellModel.getFilterExpression()))
775             styleClasses.add(dataGridModel.getStyleModel().getHeaderCellFilteredClass());
776
777         SortModel sortModel = dataGridModel.getState().getSortModel();
778         if(sortModel.isSorted(_headerCellModel.getSortExpression()))
779             styleClasses.add(dataGridModel.getStyleModel().getHeaderCellSortedClass());
780
781         if(_headerCellModel.isSortable())
782             styleClasses.add(dataGridModel.getStyleModel().getHeaderCellSortableClass());
783
784         if(_cellState.styleClass == null)
785             styleClasses.add(dataGridModel.getStyleModel().getHeaderCellClass());
786         else
787             styleClasses.add(_cellState.styleClass);
788
789         _cellState.styleClass = dataGridModel.getStyleModel().buildStyleClassValue(styleClasses);
790
791         JspFragment JavaDoc fragment = getJspBody();
792         StringWriter JavaDoc sw = new StringWriter JavaDoc();
793         String JavaDoc jspFragmentOutput = null;
794         if(fragment != null) {
795             fragment.invoke(sw);
796             jspFragmentOutput = sw.toString();
797         }
798
799         tableRenderer.openHeaderCell(_cellState, appender);
800         renderHeaderCellContents(appender, jspFragmentOutput);
801         tableRenderer.closeHeaderCell(appender);
802
803         /* render any JavaScript needed to support framework features */
804         if (_cellState.id != null) {
805             HttpServletRequest JavaDoc request = JspUtil.getRequest(getJspContext());
806             String JavaDoc script = renderNameAndId(request, _cellState, null);
807
808             if(script != null)
809                 appender.append(script);
810         }
811     }
812
813     /**
814      * Render the contents of the body of the HTML th tag into the given {@link AbstractRenderAppender}
815      * @param appender the {@link AbstractRenderAppender} for the output
816      * @param jspFragmentOutput the result of having evaluated the tag's {@link JspFragment}
817      * @throws IOException when an error occurs writing to the output stream
818      * @throws JspException when an error occurs evaluating the {@link JspFragment} for this body
819      */

820     protected void renderHeaderCellContents(AbstractRenderAppender appender, String JavaDoc jspFragmentOutput)
821             throws IOException JavaDoc, JspException JavaDoc {
822
823         if(_headerText == null) {
824             appender.append(jspFragmentOutput);
825         }
826         else {
827             _headerCellModel.setDataGridTagModel(DataGridUtil.getDataGridTagModel(getJspContext()));
828                 _headerCellModel.setBodyContent(jspFragmentOutput);
829             _headerCellModel.setHeaderText(_headerText);
830
831             getCellDecorator().decorate(getJspContext(), appender, _headerCellModel);
832         }
833     }
834
835     /**
836      * Apply the tag's attributes to the {@link HeaderCellModel}.
837      * @throws JspException when errors are encountered applying the attributes
838      */

839     protected void applyAttributes()
840             throws JspException JavaDoc {
841         super.applyAttributes();
842
843         if(_headerCellModel.getFilterHref() != null && _headerCellModel.getFilterAction() != null)
844             throw new JspException JavaDoc(Bundle.getErrorString("HeaderCell_CantSetHrefAndAction"));
845
846         if(_headerCellModel.getSortHref() != null && _headerCellModel.getSortAction() != null)
847             throw new JspException JavaDoc(Bundle.getErrorString("HeaderCell_CantSetSortHrefAndAction"));
848
849         if(_headerCellModel.isSortable()) {
850             if(_headerCellModel.getSortExpression() == null)
851                 throw new JspException JavaDoc(Bundle.getErrorString("HeaderCell_CantEnableSorting"));
852
853             /* set an intelligent default for the sorting HREF */
854             if(_headerCellModel.getSortHref() == null && _headerCellModel.getSortAction() == null)
855                 _headerCellModel.setSortHref(JspUtil.getRequest(getJspContext()).getRequestURI());
856         }
857
858         if(_headerCellModel.isFilterable()) {
859             if(_headerCellModel.getFilterExpression() == null)
860                 throw new JspException JavaDoc(Bundle.getErrorString("HeaderCell_CantEnableFiltering"));
861
862             /* set an intelligent default for the filtering HREF */
863             if(_headerCellModel.getFilterHref() == null && _headerCellModel.getFilterAction() == null)
864                 _headerCellModel.setFilterHref(JspUtil.getRequest(getJspContext()).getRequestURI());
865         }
866     }
867
868     /**
869      * Internal method used to get the outer {@link CellDecorator}.
870      * @return the outer cell decorator
871      */

872     private CellDecorator getCellDecorator() {
873         if(_cellDecorator != null)
874             return _cellDecorator;
875         else {
876             assert DECORATOR_HEADER_SORTED != null;
877             return DECORATOR_HEADER_SORTED;
878         }
879     }
880 }
881
Popular Tags