001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.databinding.datagrid;
020:
021: import javax.servlet.jsp.JspException;
022: import javax.servlet.http.HttpServletRequest;
023:
024: import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
025: import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.ImageCellModel;
026: import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.ImageCellDecorator;
027: import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
028: import org.apache.beehive.netui.tags.rendering.AbstractHtmlState;
029: import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender;
030: import org.apache.beehive.netui.tags.rendering.ImageTag;
031: import org.apache.beehive.netui.tags.html.HtmlConstants;
032: import org.apache.beehive.netui.tags.IHtmlEvents;
033: import org.apache.beehive.netui.tags.IHtmlCore;
034: import org.apache.beehive.netui.tags.IHtmlI18n;
035:
036: /**
037: * <p>
038: * Data grid cell that renders an HTML <image> tag containing the tag's <code>source</code> attribute. The
039: * span cell is rendered inside of an HTML table <td>. The image cell supports various nested tags including
040: * those that augment the available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer}
041: * interface.
042: * </p>
043: * <p>
044: * The set of JSP implicit objects available to the body include:
045: * <ul>
046: * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
047: * for the cell's containing data grid.</li>
048: * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
049: * that exposes the current data item and the current item's index</li>
050: * </ul>
051: * </p>
052: *
053: * @jsptagref.tagdescription
054: * <p>
055: * Data grid cell that renders an HTML <image> tag containing the tag's <code>source</code> attribute. The
056: * span cell is rendered inside of an HTML table <td>. The image cell supports various nested tags including
057: * those that augment the available attribute set via the NetUI {@link org.apache.beehive.netui.tags.IAttributeConsumer}
058: * interface.
059: * </p>
060: * <p>
061: * The set of JSP implicit objects available to the body include:
062: * <ul>
063: * <li><code>dataGridModel</code> -- the {@link org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel}
064: * for the cell's containing data grid.</li>
065: * <li><code>container</code> -- the {@link org.apache.beehive.netui.script.common.IDataAccessProvider} instance
066: * that exposes the current data item and the current item's index</li>
067: * </ul>
068: * </p>
069: * @netui:tag name="imageCell" body-content="scriptless"
070: * description="Data grid cell tag that renders an HTML img inside of an HTML table cell."
071: */
072: public class ImageCell extends AbstractHtmlTableCell implements
073: IHtmlCore, IHtmlEvents, IHtmlI18n {
074:
075: private static final ImageCellDecorator DECORATOR = new ImageCellDecorator();
076: private static final String IMAGE_FACET_NAME = "image";
077:
078: private ImageCellModel _imageCellModel = new ImageCellModel();
079: private ImageTag.State _imageState = _imageCellModel
080: .getImageState();
081:
082: /**
083: * The name of this tag; this value is used for error reporting.
084: * @return the String name of this tag
085: */
086: public String getTagName() {
087: return "ImageCell";
088: }
089:
090: /**
091: * Sets the onClick JavaScript event on the image tag.
092: *
093: * @param onClick the onClick event.
094: * @jsptagref.attributedescription The onClick JavaScript event on the image tag.
095: * @jsptagref.attributesyntaxvalue <i>string_onClick</i>
096: * @netui:attribute required="false" rtexprvalue="true" description="The onClick JavaScript event on the image tag."
097: */
098: public void setOnClick(String onClick) {
099: _imageState.registerAttribute(
100: AbstractHtmlState.ATTR_JAVASCRIPT,
101: HtmlConstants.ONCLICK, onClick);
102: }
103:
104: /**
105: * Sets the onDblClick JavaScript event on the image tag.
106: *
107: * @param onDblClick the onDblClick event.
108: * @jsptagref.attributedescription The onDblClick JavaScript event on the image tag.
109: * @jsptagref.attributesyntaxvalue <i>string_onDblClick</i>
110: * @netui:attribute required="false" rtexprvalue="true" description="The onDblClick JavaScript event on the image tag."
111: */
112: public void setOnDblClick(String onDblClick) {
113: _imageState.registerAttribute(
114: AbstractHtmlState.ATTR_JAVASCRIPT,
115: HtmlConstants.ONDBLCLICK, onDblClick);
116: }
117:
118: /**
119: * Sets the onKeyDown JavaScript event on the image tag.
120: *
121: * @param onKeyDown the onKeyDown event.
122: * @jsptagref.attributedescription The onKeyDown JavaScript event on the image tag.
123: * @jsptagref.attributesyntaxvalue <i>string_onKeyDown</i>
124: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyDown JavaScript event on the image tag."
125: */
126: public void setOnKeyDown(String onKeyDown) {
127: _imageState.registerAttribute(
128: AbstractHtmlState.ATTR_JAVASCRIPT,
129: HtmlConstants.ONKEYDOWN, onKeyDown);
130: }
131:
132: /**
133: * Sets the onKeyUp JavaScript event on the image tag.
134: *
135: * @param onKeyUp the onKeyUp event.
136: * @jsptagref.attributedescription The onKeyUp JavaScript event on the image tag.
137: * @jsptagref.attributesyntaxvalue <i>string_onKeyUp</i>
138: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyUp JavaScript event on the image tag."
139: */
140: public void setOnKeyUp(String onKeyUp) {
141: _imageState.registerAttribute(
142: AbstractHtmlState.ATTR_JAVASCRIPT,
143: HtmlConstants.ONKEYUP, onKeyUp);
144: }
145:
146: /**
147: * Sets the onKeyPress JavaScript event on the image tag.
148: *
149: * @param onKeyPress the onKeyPress event.
150: * @jsptagref.attributedescription The onKeyPress JavaScript event on the image tag.
151: * @jsptagref.attributesyntaxvalue <i>string_onKeyPress</i>
152: * @netui:attribute required="false" rtexprvalue="true" description="The onKeyPress JavaScript event on the image tag."
153: */
154: public void setOnKeyPress(String onKeyPress) {
155: _imageState.registerAttribute(
156: AbstractHtmlState.ATTR_JAVASCRIPT,
157: HtmlConstants.ONKEYPRESS, onKeyPress);
158: }
159:
160: /**
161: * Sets the onMouseDown JavaScript event on the image tag.
162: *
163: * @param onMouseDown the onMouseDown event.
164: * @jsptagref.attributedescription The onMouseDown JavaScript event on the image tag.
165: * @jsptagref.attributesyntaxvalue <i>string_onMouseDown</i>
166: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseDown JavaScript event on the image tag."
167: */
168: public void setOnMouseDown(String onMouseDown) {
169: _imageState.registerAttribute(
170: AbstractHtmlState.ATTR_JAVASCRIPT,
171: HtmlConstants.ONMOUSEDOWN, onMouseDown);
172: }
173:
174: /**
175: * Sets the onMouseUp JavaScript event on the image tag.
176: *
177: * @param onMouseUp the onMouseUp event.
178: * @jsptagref.attributedescription The onMouseUp JavaScript event on the image tag.
179: * @jsptagref.attributesyntaxvalue <i>string_onMouseUp</i>
180: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseUp JavaScript event on the image tag."
181: */
182: public void setOnMouseUp(String onMouseUp) {
183: _imageState.registerAttribute(
184: AbstractHtmlState.ATTR_JAVASCRIPT,
185: HtmlConstants.ONMOUSEUP, onMouseUp);
186: }
187:
188: /**
189: * Sets the onMouseMove JavaScript event on the image tag.
190: *
191: * @param onMouseMove the onMouseMove event.
192: * @jsptagref.attributedescription The onMouseMove JavaScript event on the image tag.
193: * @jsptagref.attributesyntaxvalue <i>string_onMouseMove</i>
194: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseMove JavaScript event on the image tag."
195: */
196: public void setOnMouseMove(String onMouseMove) {
197: _imageState.registerAttribute(
198: AbstractHtmlState.ATTR_JAVASCRIPT,
199: HtmlConstants.ONMOUSEMOVE, onMouseMove);
200: }
201:
202: /**
203: * Sets the onMouseOut JavaScript event on the image tag.
204: *
205: * @param onMouseOut the onMouseOut event.
206: * @jsptagref.attributedescription The onMouseOut JavaScript event on the image tag.
207: * @jsptagref.attributesyntaxvalue <i>string_onMouseOut</i>
208: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOut JavaScript event on the image tag."
209: */
210: public void setOnMouseOut(String onMouseOut) {
211: _imageState.registerAttribute(
212: AbstractHtmlState.ATTR_JAVASCRIPT,
213: HtmlConstants.ONMOUSEOUT, onMouseOut);
214: }
215:
216: /**
217: * Sets the onMouseOver JavaScript event on the image tag.
218: *
219: * @param onMouseOver the onMouseOver event.
220: * @jsptagref.attributedescription The onMouseOver JavaScript event on the image tag.
221: * @jsptagref.attributesyntaxvalue <i>string_onMouseOver</i>
222: * @netui:attribute required="false" rtexprvalue="true" description="The onMouseOver JavaScript event on the image tag."
223: */
224: public void setOnMouseOver(String onMouseOver) {
225: _imageState.registerAttribute(
226: AbstractHtmlState.ATTR_JAVASCRIPT,
227: HtmlConstants.ONMOUSEOVER, onMouseOver);
228: }
229:
230: /**
231: * Sets the style of the rendered html tag.
232: *
233: * @param style the html style.
234: * @jsptagref.attributedescription The style.
235: * @jsptagref.attributesyntaxvalue <i>string_style</i>
236: * @netui:attribute required="false" rtexprvalue="true" description="The style."
237: */
238: public void setStyle(String style) {
239: if ("".equals(style))
240: return;
241:
242: _imageState.style = style;
243: }
244:
245: /**
246: * Sets the style class of the rendered html tag.
247: *
248: * @param styleClass the html style class.
249: * @jsptagref.attributedescription The style class.
250: * @jsptagref.attributesyntaxvalue <i>string_style_class</i>
251: * @netui:attribute required="false" rtexprvalue="true" description="The style class."
252: */
253: public void setStyleClass(String styleClass) {
254: if ("".equals(styleClass))
255: return;
256:
257: _imageState.styleClass = styleClass;
258: }
259:
260: /**
261: * Sets the value of the title attribute.
262: *
263: * @param title
264: * @jsptagref.attributedescription The title.
265: * @jsptagref.attributesyntaxvalue <i>string_title</i>
266: * @netui:attribute required="false" rtexprvalue="true" description="The title. "
267: */
268: public void setTitle(String title) {
269: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
270: HtmlConstants.TITLE, title);
271: }
272:
273: /**
274: * Sets the lang attribute for the HTML element.
275: * @param lang
276: * @jsptagref.attributedescription The lang.
277: * @jsptagref.attributesyntaxvalue <i>string_lang</i>
278: * @netui:attribute required="false" rtexprvalue="true"
279: * description="The lang."
280: */
281: public void setLang(String lang) {
282: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
283: HtmlConstants.LANG, lang);
284: }
285:
286: /**
287: * Sets the dir attribute for the HTML image tag.
288: * @param dir
289: * @jsptagref.attributedescription The dir for the image tag.
290: * @jsptagref.attributesyntaxvalue <i>string_dir</i>
291: * @netui:attribute required="false" rtexprvalue="true" description="The dir attribhte on the image tag."
292: */
293: public void setDir(String dir) {
294: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
295: HtmlConstants.DIR, dir);
296: }
297:
298: /**
299: * Set the image source to render on the HTML image tag.
300: *
301: * @jsptagref.attributedescription The source of the image to display.
302: * @jsptagref.attributesyntaxvalue <i>literal_or_expression_src</i>
303: * @netui:attribute required="true" rtexprvalue="true" description="The image source to render on the HTML image tag"
304: */
305: public void setSrc(String src) {
306: _imageState.src = src;
307: }
308:
309: /**
310: * Sets the property to specify where to align the image.
311: *
312: * @param align the image alignment.
313: * @jsptagref.attributedescription The alignment of the image.
314: * @jsptagref.attributesyntaxvalue <i>string_align</i>
315: * @netui:attribute required="false" rtexprvalue="true" description="The alignment of the image."
316: */
317: public void setAlign(String align) {
318: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
319: HtmlConstants.ALIGN, align);
320: }
321:
322: /**
323: * Sets the the horizontal spacing around the image.
324: *
325: * @param hspace the horizontal spacing.
326: * @jsptagref.attributedescription The horizontal spacing around the image.
327: * @jsptagref.attributesyntaxvalue <i>integer_hspace</i>
328: * @netui:attribute required="false" rtexprvalue="true" description="The horizontal spacing around the image."
329: */
330: public void setHspace(String hspace) {
331: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
332: HtmlConstants.HSPACE, hspace);
333: }
334:
335: /**
336: * Set the vertical spacing around the image.
337: *
338: * @jsptagref.attributedescription The width of the border around the image.
339: * @jsptagref.attributesyntaxvalue <i>integer_border</i>
340: * @netui:attribute required="false" rtexprvalue="true" description="The vertical spacing around the image"
341: */
342: public void setVspace(String vspace) {
343: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
344: HtmlConstants.VSPACE, vspace);
345: }
346:
347: /**
348: * Set the border attribute for the image.
349: *
350: * @jsptagref.attributedescription The border attribute of the image.
351: * @jsptagref.attributesyntaxvalue <i>height</i>
352: * @netui:attribute required="false" rtexprvalue="true" description="The border attribute for the image"
353: */
354: public void setBorder(String border) {
355: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
356: HtmlConstants.BORDER, border);
357: }
358:
359: /**
360: * Set the height of the image to display.
361: *
362: * @jsptagref.attributedescription The height of the image to be displayed.
363: * @jsptagref.attributesyntaxvalue <i>integer_height</i>
364: * @netui:attribute required="false" rtexprvalue="true" description="The height attribute for the image."
365: */
366: public void setHeight(String height) {
367: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
368: HtmlConstants.HEIGHT, height);
369: }
370:
371: /**
372: * Set the width of the image to display.
373: *
374: * @jsptagref.attributedescription The width of the image to be displayed.
375: * @jsptagref.attributesyntaxvalue <i>width</i>
376: * @netui:attribute required="false" rtexprvalue="true" description="The width attribute for the image"
377: */
378: public void setWidth(String width) {
379: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
380: HtmlConstants.WIDTH, width);
381: }
382:
383: /**
384: * Sets the property to specify the longdesc of the image tag.
385: *
386: * @param longdesc the longdesc attribute
387: * @jsptagref.attributedescription The alternative text of the image tag
388: * @jsptagref.attributesyntaxvalue <i>string_longdesc</i>
389: * @netui:attribute required="false" rtexprvalue="true" description="The longdesc of the image tag."
390: */
391: public void setLongdesc(String longdesc) {
392: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
393: HtmlConstants.LONGDESC, longdesc);
394: }
395:
396: /**
397: * Sets the property to specify the alt text of the image tag.
398: *
399: * @param alt the image alignment.
400: * @jsptagref.attributedescription The alternative text of the image tag
401: * @jsptagref.attributesyntaxvalue <i>string_alt</i>
402: * @netui:attribute required="false" rtexprvalue="true" description="The alternative text for the image tag."
403: */
404: public void setAlt(String alt) {
405: _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL,
406: HtmlConstants.ALT, alt);
407: }
408:
409: /**
410: * Set the name of the tagId for the image tag.
411: *
412: * @param tagId the the name of the tagId for the image tag.
413: * @jsptagref.attributedescription The tagId.
414: * @jsptagref.attributesyntaxvalue <i>string_tagId</i>
415: * @netui:attribute required="false" rtexprvalue="true"
416: * description="String value. Sets the id (or name) attribute of the rendered HTML image tag."
417: */
418: public void setTagId(String tagId) throws JspException {
419: applyIndexedTagId(_imageState, tagId);
420: }
421:
422: /**
423: * <p>
424: * Implementation of {@link org.apache.beehive.netui.tags.IAttributeConsumer} interface. This
425: * allows a page author to add additional attributes to the HTML rendered by this tag. The attribute
426: * facets which can be consumed include:
427: * <ul>
428: * <li><code>image</code> -- attributes set using this facet will be rendered as HTML attributes on the
429: * rendered HTML <image> tag.</li>
430: * </ul>
431: * </p>
432: * <p>
433: * This tag also accepts facets supported by {@link AbstractHtmlTableCell#setAttribute(String, String, String)}
434: * </p>
435: *
436: * @param name the name of the attribute
437: * @param value the value of the attribute
438: * @param facet the facet for the attribute; this value must be match one of the facets supported by the JSP tags
439: * @throws JspException thrown when the given facet String is not recognized as a valid facet name
440: */
441: public void setAttribute(String name, String value, String facet)
442: throws JspException {
443: if (facet == null || facet.equals(IMAGE_FACET_NAME))
444: super .addStateAttribute(_imageState, name, value);
445: else
446: super .setAttribute(name, value, facet);
447: }
448:
449: /**
450: * Render the cell's contents. This method implements support for executing the image cell's decorator.
451: *
452: * @param appender the {@link AbstractRenderAppender} used to collect the rendered output
453: * @param jspFragmentOutput the String result of having evaluated the image cell's {@link javax.servlet.jsp.tagext.JspFragment}
454: */
455: protected void renderDataCellContents(
456: AbstractRenderAppender appender, String jspFragmentOutput) {
457: /* render any JavaScript needed to support framework features */
458: if (_imageState.id != null) {
459: HttpServletRequest request = JspUtil
460: .getRequest(getJspContext());
461: String script = renderNameAndId(request, _imageState, null);
462: _imageCellModel.setJavascript(script);
463: }
464:
465: DECORATOR.decorate(getJspContext(), appender, _imageCellModel);
466: }
467:
468: /**
469: * Implementation of {@link AbstractHtmlTableCell#internalGetCellModel()} that exposes the
470: * {@link org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.ImageCellModel}
471: * which is storing state for this tag.
472: * @return this tag's image cell model
473: */
474: protected CellModel internalGetCellModel() {
475: return _imageCellModel;
476: }
477: }
|