KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 1971-2003 TONBELLER AG, Bensheim.
3  * All rights reserved.
4  */

5 package com.tonbeller.jpivot.table.navi;
6
7 import java.text.MessageFormat JavaDoc;
8
9 import com.tonbeller.jpivot.core.ModelChangeEvent;
10 import com.tonbeller.jpivot.olap.model.Displayable;
11 import com.tonbeller.jpivot.olap.model.Member;
12 import com.tonbeller.jpivot.table.SpanBuilder.SBContext;
13 import com.tonbeller.wcf.charset.CharsetFilter;
14 import com.tonbeller.wcf.controller.RequestContext;
15
16 /**
17  * creates a hyperlink in the table with a specified url. The URL may contain
18  * the unique name of the member that belongs to the hyperlink.
19  *
20  * @author av
21  * @since Mar 27, 2006
22  */

23 public class UrlClickableMember extends AbstractClickableMember {
24   /**
25    * urlPattern contains {0} which is replaced with the unique name
26    * of the member
27    */

28   private String JavaDoc urlPattern;
29   private String JavaDoc menuLabel;
30
31   /**
32    * @param uniqueName name of level, hierarchy, dimension that shall be clickable
33    *
34    * @param urlPattern any url. {0} will be replaced with the unique name of the
35    * selected member
36    */

37   
38   protected UrlClickableMember(String JavaDoc uniqueName, String JavaDoc menuLabel, String JavaDoc urlPattern) {
39     super(uniqueName);
40     this.menuLabel = menuLabel;
41     this.urlPattern = urlPattern;
42   }
43
44   /**
45    * unique name in url
46    */

47   private String JavaDoc getPatternUrl(Member member) {
48     String JavaDoc pattern = urlPattern == null ? "?param={0}" : urlPattern;
49     String JavaDoc uname = CharsetFilter.urlEncode(parser.unparse(member));
50     Object JavaDoc[] args = new Object JavaDoc[] { uname};
51     return MessageFormat.format(pattern, args);
52   }
53
54   public void decorate(SBContext sbctx, Displayable obj) {
55     if (!(obj instanceof Member))
56       return;
57
58     Member m = (Member) obj;
59     if (match(m)) {
60       sbctx.addClickable(getPatternUrl(m), menuLabel);
61     }
62   }
63
64   /**
65    * ignore
66    */

67   public void request(RequestContext context) throws Exception JavaDoc {
68   }
69
70   /**
71    * ignore
72    */

73   public void modelChanged(ModelChangeEvent e) {
74   }
75
76   /**
77    * ignore
78    */

79   public void structureChanged(ModelChangeEvent e) {
80   }
81
82 }
83
Popular Tags