1 13 package com.tonbeller.jpivot.table.navi; 14 15 import org.apache.log4j.Logger; 16 17 import com.tonbeller.jpivot.core.ModelChangeEvent; 18 import com.tonbeller.jpivot.olap.model.Displayable; 19 import com.tonbeller.jpivot.olap.model.Member; 20 import com.tonbeller.jpivot.olap.model.OlapModel; 21 import com.tonbeller.jpivot.table.TableComponent; 22 import com.tonbeller.jpivot.table.SpanBuilder.SBContext; 23 import com.tonbeller.wcf.controller.Dispatcher; 24 import com.tonbeller.wcf.controller.DispatcherSupport; 25 import com.tonbeller.wcf.controller.RequestContext; 26 import com.tonbeller.wcf.controller.RequestListener; 27 import com.tonbeller.wcf.utils.DomUtils; 28 29 35 public abstract class ClickableMemberSupport extends AbstractClickableMember { 36 37 private static final Logger logger = Logger.getLogger(ClickableMemberSupport.class); 38 39 protected Dispatcher dispatcher = new DispatcherSupport(); 40 protected OlapModel model; 41 private String urlPattern; 42 43 46 protected abstract String getMenuLabel(); 47 48 51 protected abstract RequestListener createRequestListener(OlapModel model, Member m); 52 53 59 public ClickableMemberSupport(String uniqueName) { 60 super(uniqueName); 61 } 62 63 public void startRendering(RequestContext context, TableComponent table) { 64 this.model = table.getOlapModel(); 65 dispatcher.clear(); 66 super.startRendering(context, table); 67 } 68 69 public void stopRendering() { 70 super.stopRendering(); 71 model = null; 72 } 73 74 private String handlerUrl(String id) { 75 String pattern = urlPattern == null ? "" : urlPattern; 76 char sep = '?'; 77 if (pattern.indexOf('?') > 0) 78 sep = '&'; 79 return pattern + sep + id + "=x"; 80 } 81 82 public void decorate(SBContext sbctx, Displayable obj) { 83 if (!(obj instanceof Member)) 84 return; 85 Member m = (Member) obj; 86 if (match(m)) { 87 RequestListener r = createRequestListener(model, m); 88 String id = DomUtils.randomId(); 89 dispatcher.addRequestListener(id, null, r); 90 sbctx.addClickable(handlerUrl(id), getMenuLabel()); 91 } 92 } 93 94 public void modelChanged(ModelChangeEvent e) { 95 } 96 97 public void structureChanged(ModelChangeEvent e) { 98 dispatcher.clear(); 99 } 100 101 public void request(RequestContext context) throws Exception { 102 dispatcher.request(context); 103 } 104 105 108 public void setUrlPattern(String urlPattern) { 109 this.urlPattern = urlPattern; 110 } 111 112 public String getUrlPattern() { 113 return urlPattern; 114 } 115 } | Popular Tags |