1 18 package org.apache.beehive.netui.tags.databinding.datagrid; 19 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.http.HttpServletRequest ; 22 23 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender; 24 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState; 25 import org.apache.beehive.netui.tags.rendering.ImageTag; 26 import org.apache.beehive.netui.tags.rendering.AnchorTag; 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.html.IUrlParams; 30 import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel; 31 import org.apache.beehive.netui.databinding.datagrid.runtime.model.cell.ImageAnchorCellModel; 32 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.ImageAnchorCellDecorator; 33 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil; 34 import org.apache.beehive.netui.util.ParamHelper; 35 36 85 public class ImageAnchorCell 86 extends AbstractHtmlTableCell 87 implements IFormattable, IUrlParams { 88 89 92 93 private static final ImageAnchorCellDecorator DECORATOR = new ImageAnchorCellDecorator(); 94 private static final String IMAGE_FACET_NAME = "image"; 95 private static final String ANCHOR_FACET_NAME = "anchor"; 96 97 private ImageAnchorCellModel _imageAnchorCellModel = new ImageAnchorCellModel(); 98 private AnchorTag.State _anchorState = _imageAnchorCellModel.getAnchorState(); 99 private ImageTag.State _imageState = _imageAnchorCellModel.getImageState(); 100 101 105 public String getTagName() { 106 return "ImageAnchorCell"; 107 } 108 109 117 public void setOnClick(String onClick) { 118 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONCLICK, onClick); 119 } 120 121 129 public void setOnDblClick(String onDblClick) { 130 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONDBLCLICK, onDblClick); 131 } 132 133 141 public void setOnKeyDown(String onKeyDown) { 142 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYDOWN, onKeyDown); 143 } 144 145 153 public void setOnKeyUp(String onKeyUp) { 154 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYUP, onKeyUp); 155 } 156 157 165 public void setOnKeyPress(String onKeyPress) { 166 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYPRESS, onKeyPress); 167 } 168 169 177 public void setOnMouseDown(String onMouseDown) { 178 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEDOWN, onMouseDown); 179 } 180 181 189 public void setOnMouseUp(String onMouseUp) { 190 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEUP, onMouseUp); 191 } 192 193 201 public void setOnMouseMove(String onMouseMove) { 202 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEMOVE, onMouseMove); 203 } 204 205 213 public void setOnMouseOut(String onMouseOut) { 214 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOUT, onMouseOut); 215 } 216 217 225 public void setOnMouseOver(String onMouseOver) { 226 _anchorState.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOVER, onMouseOver); 227 } 228 229 237 public void setStyle(String style) { 238 if("".equals(style)) return; 239 240 _anchorState.style = style; 241 } 242 243 251 public void setStyleClass(String styleClass) { 252 if("".equals(styleClass)) return; 253 254 _anchorState.styleClass = styleClass; 255 } 256 257 265 public void setTitle(String title) { 266 _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TITLE, title); 267 } 268 269 270 275 276 285 public void setCharSet(String charSet) { 286 _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.CHARSET, charSet); 287 } 288 289 298 public void setType(String type) { 299 _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TYPE, type); 300 } 301 302 311 public void setHrefLang(String hreflang) { 312 _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.HREFLANG, hreflang); 313 } 314 315 324 public void setRel(String rel) { 325 _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.REL, rel); 326 } 327 328 337 public void setRev(String rev) { 338 _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.REV, rev); 339 } 340 341 342 351 public void setTarget(String target) { 352 _anchorState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TARGET, target); 353 } 354 355 364 public void setHref(String href) { 365 _imageAnchorCellModel.setHref(href); 366 } 367 368 378 public void setTargetScope(String targetScope) { 379 _imageAnchorCellModel.setScopeId(targetScope); 380 } 381 382 393 public void setAction(String action) 394 throws JspException { 395 _imageAnchorCellModel.setAction(setRequiredValueAttribute(action, "action")); 396 } 397 398 403 404 413 public void setAlign(String align) { 414 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ALIGN, align); 415 } 416 417 426 public void setAlt(String alt) { 427 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ALT, alt); 428 } 429 430 439 public void setLongdesc(String longdesc) { 440 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LONGDESC, longdesc); 441 } 442 443 452 public void setBorder(String border) { 453 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.BORDER, border); 454 } 455 456 465 public void setHeight(String height) { 466 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.HEIGHT, height); 467 } 468 469 478 public void setHspace(String hspace) { 479 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.HSPACE, hspace); 480 } 481 482 491 public void setIsmap(String ismap) { 492 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ISMAP, ismap); 493 } 494 495 504 public void setSrc(String src) 505 throws JspException { 506 _imageState.src = src; 507 } 508 509 518 public void setUsemap(String usemap) { 519 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.USEMAP, usemap); 520 } 521 522 531 public void setVspace(String vspace) { 532 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.VSPACE, vspace); 533 } 534 535 547 public void setImageStyle(String imageStyle) { 548 _imageState.style = imageStyle; 549 } 550 551 563 public void setImageStyleClass(String imageClass) { 564 _imageState.styleClass = imageClass; 565 } 566 567 576 public void setWidth(String width) { 577 _imageState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.WIDTH, width); 578 } 579 580 589 public void setTagId(String tagId) 590 throws JspException { 591 applyIndexedTagId(_imageState, tagId); 592 } 593 594 603 public void setAnchorTagId(String tagId) 604 throws JspException { 605 applyIndexedTagId(_anchorState, tagId); 606 } 607 608 627 public void setAttribute(String name, String value, String facet) 628 throws JspException { 629 if(facet == null || facet.equals(ANCHOR_FACET_NAME)) 630 super.addStateAttribute(_anchorState, name, value); 631 else if(facet.equals(IMAGE_FACET_NAME)) 632 super.addStateAttribute(_imageState, name, value); 633 else 634 super.setAttribute(name, value, facet); 635 } 636 637 656 public void addParameter(String name, Object value, String facet) 657 throws JspException { 658 ParamHelper.addParam(_imageAnchorCellModel.getParams(), name, value); 659 } 660 661 668 protected void renderDataCellContents(AbstractRenderAppender appender, String jspFragmentOutput) { 669 assert DECORATOR != null; 670 assert appender != null; 671 assert _imageAnchorCellModel != null; 672 673 String script = null; 674 675 if (_imageState.id != null) { 676 HttpServletRequest request = JspUtil.getRequest(getJspContext()); 677 script = renderNameAndId(request, _imageState, null); 678 } 679 680 681 if (_anchorState.id != null) { 682 HttpServletRequest request = JspUtil.getRequest(getJspContext()); 683 String anchorScript = renderNameAndId(request, _anchorState, null); 684 if(anchorScript != null) 685 script = (script != null ? script += anchorScript : anchorScript); 686 } 687 688 _imageAnchorCellModel.setJavascript(script); 689 690 DECORATOR.decorate(getJspContext(), appender, _imageAnchorCellModel); 691 } 692 693 699 protected CellModel internalGetCellModel() { 700 return _imageAnchorCellModel; 701 } 702 } 703 | Popular Tags |