| 1 13 package com.tonbeller.wcf.toolbar; 14 15 import java.text.MessageFormat ; 16 17 import org.w3c.dom.Element ; 18 19 import com.tonbeller.wcf.controller.RequestContext; 20 import com.tonbeller.wcf.utils.DomUtils; 21 22 public class ImgButton extends ToolBarComponentSupport { 23 24 private ToolBar tbar; 25 28 public ImgButton(ToolBar tbar) { 29 this.tbar = tbar; 30 } 31 32 private String tooltip; 33 private String href; 35 private String target; 37 private String img; 39 40 43 public void render(RequestContext context, Element parent) throws Exception { 44 Element btn = DomUtils.appendElement(parent, "img-button"); 45 btn.setAttribute("img", img +"-up"); 46 btn.setAttribute("id", getId()); 47 btn.setAttribute("href", makeHref(context)); 48 if(target!=null && target.length()!=0) 49 btn.setAttribute("target", target); 50 btn.setAttribute("title", tbar.getTooltip(tooltip)); 51 } 52 53 String makeHref(RequestContext context) { 54 Object [] args = {context.getRequest().getContextPath(), DomUtils.randomId()}; 55 return MessageFormat.format(href, args); 56 } 57 58 public void initialize(RequestContext context, ToolBar owner) { 59 } 60 61 public String getHref() { 62 return href; 63 } 64 65 public String getImg() { 66 return img; 67 } 68 69 public String getTarget() { 70 return target; 71 } 72 73 public void setHref(String href) { 74 this.href = href; 75 } 76 77 public void setImg(String img) { 78 this.img = img; 79 } 80 81 public void setTarget(String target) { 82 this.target = target; 83 } 84 85 public void setTooltip(String tooltip) { 86 this.tooltip = tooltip; 87 } 88 89 public boolean isSeparator() { 90 return false; 91 } 92 93 } 94 | Popular Tags |