KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > navi > ClickableMemberSupport


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

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 /**
30  * clickable that invokes a RequestListener instead of following an URL
31  * @see com.tonbeller.jpivot.table.navi.UrlClickableMember
32  *
33  * @author av
34  */

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 JavaDoc urlPattern;
42
43   /**
44    * label to show in popup menu
45    */

46   protected abstract String JavaDoc getMenuLabel();
47
48   /**
49    * specifies what should happen when the user clicks on the member.
50    */

51   protected abstract RequestListener createRequestListener(OlapModel model, Member m);
52
53   /**
54    * @param uniqueName name of level, hierarchy or dimension that shall be clickable.
55    * If null, all dimensions except Measures will be clickable.
56    *
57    * @param paramProvider creates the parameter from the member.
58    */

59   public ClickableMemberSupport(String JavaDoc 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 JavaDoc handlerUrl(String JavaDoc id) {
75     String JavaDoc 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 JavaDoc 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 JavaDoc {
102     dispatcher.request(context);
103   }
104
105   /**
106    * the url to generate into the hyprelink, in most cases the default null is ok
107    */

108   public void setUrlPattern(String JavaDoc urlPattern) {
109     this.urlPattern = urlPattern;
110   }
111
112   public String JavaDoc getUrlPattern() {
113     return urlPattern;
114   }
115 }
Popular Tags