KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.tonbeller.jpivot.table.navi;
2
3 import java.util.Collection JavaDoc;
4 import java.util.Iterator JavaDoc;
5
6 import com.tonbeller.jpivot.olap.model.Member;
7 import com.tonbeller.jpivot.olap.model.OlapModel;
8 import com.tonbeller.jpivot.olap.model.Property;
9 import com.tonbeller.jpivot.param.ParameterProvider;
10 import com.tonbeller.wcf.controller.Controller;
11 import com.tonbeller.wcf.controller.RequestContext;
12 import com.tonbeller.wcf.controller.RequestListener;
13 import com.tonbeller.wcf.param.SessionParam;
14 import com.tonbeller.wcf.param.SessionParamPool;
15
16 /**
17  * a clickable member with query scope. The DynamicClickableMember is attached to the
18  * Query - its lifecycle ends when the query is replaced.
19  *
20  * @author av
21  * @since 15.12.2004
22  */

23 public class DynamicClickableMember extends ClickableMemberSupport {
24   private String JavaDoc page;
25   private ParameterProvider paramProvider;
26   private String JavaDoc menuLabel;
27
28   /**
29    * @param uniqueName name of level, hierarchy or dimension that shall be clickable.
30    * If null, all dimensions except Measures will be clickable.
31    *
32    * @param page the page to display when the link is clicked, must start with "/".
33    * Set to null to stay on the same page
34    *
35    * @param paramProvider creates the parameter from the member.
36    */

37   public DynamicClickableMember(String JavaDoc uniqueName, String JavaDoc menuLabel, ParameterProvider paramProvider, String JavaDoc page) {
38     super(uniqueName);
39     this.menuLabel = menuLabel;
40     this.paramProvider = paramProvider;
41     this.page = page;
42   }
43
44   private class AddMemberToParameterPool implements RequestListener {
45     private Member member;
46     private OlapModel model;
47     /**
48      * name of the member property that contains the URI of the target JSP.
49      * If no JSP was specified elsewhere, the value of this member property
50      * should be the path of the JSP, e.g. "/my/drillthrough.jsp".
51      */

52     private static final String JavaDoc PAGE_PROPERTY = "$page";
53
54     AddMemberToParameterPool(OlapModel model, Member m) {
55       this.model = model;
56       this.member = m;
57     }
58
59     public void request(RequestContext context) throws Exception JavaDoc {
60       SessionParamPool pool = SessionParamPool.instance(context.getSession());
61       Collection JavaDoc c = paramProvider.createSessionParams(model, member);
62       for (Iterator JavaDoc it = c.iterator(); it.hasNext();)
63         pool.setParam((SessionParam) it.next());
64
65       // if no static page URI has been specified,
66
// there may be a runtime property for it
67
if (page == null) {
68         Property prop = member.getProperty(PAGE_PROPERTY);
69         if (prop != null)
70           page = prop.getValue();
71       }
72
73       if (page != null)
74         Controller.instance(context.getSession()).setNextView(page);
75     }
76   }
77
78   protected RequestListener createRequestListener(OlapModel model, Member m) {
79     return new AddMemberToParameterPool(model, m);
80   }
81
82   public String JavaDoc getMenuLabel() {
83     return menuLabel;
84   }
85 }
Popular Tags