KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > AxisBuilderSupport


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;
14
15 import java.beans.PropertyChangeEvent JavaDoc;
16 import java.beans.PropertyChangeListener JavaDoc;
17
18 import javax.servlet.http.HttpSession JavaDoc;
19
20 import org.apache.log4j.Logger;
21 import org.w3c.dom.Element JavaDoc;
22
23 import com.tonbeller.jpivot.olap.model.Axis;
24 import com.tonbeller.jpivot.olap.model.Displayable;
25 import com.tonbeller.jpivot.olap.model.Member;
26 import com.tonbeller.jpivot.olap.navi.MemberTree;
27 import com.tonbeller.jpivot.table.span.HierarchyHeaderFactory;
28 import com.tonbeller.jpivot.table.span.LevelHeaderFactory;
29 import com.tonbeller.jpivot.table.span.PropertyConfig;
30 import com.tonbeller.jpivot.table.span.PropertySpanBuilder;
31 import com.tonbeller.jpivot.table.span.Span;
32 import com.tonbeller.jpivot.table.span.SpanCalc;
33 import com.tonbeller.jpivot.table.span.SpanConfigSupport;
34 import com.tonbeller.wcf.controller.RequestContext;
35
36 /**
37  * Created on 24.10.2002
38  *
39  * @author av
40  */

41 public abstract class AxisBuilderSupport extends PartBuilderSupport implements AxisBuilder,
42     AxisConfig, PropertyChangeListener JavaDoc {
43
44   private static final Logger logger = Logger.getLogger(AxisBuilderSupport.class);
45   
46   protected SpanCalc spanCalc;
47   protected SpanBuilder spanBuilder;
48   protected PropertySpanBuilder propertySpanBuilder;
49   protected AxisHeaderBuilder axisHeaderBuilder;
50
51   // from AxisConfig
52
protected boolean showParentMembers = false;
53   protected boolean memberIndent = false;
54   protected int hierarchyHeader = NO_HEADER;
55   protected int memberSpan = HIERARCHY_THEN_POSITION_SPAN;
56   protected int headerSpan = HIERARCHY_THEN_POSITION_SPAN;
57
58   protected AxisBuilderSupport(SpanBuilder spanBuilder) {
59     this.spanBuilder = spanBuilder;
60   }
61
62   public void initialize(RequestContext context, TableComponent table) throws Exception JavaDoc {
63     logger.info("initialize");
64     super.initialize(context, table);
65     spanBuilder.initialize(context, table);
66     propertySpanBuilder = new PropertySpanBuilder(table.getOlapModel());
67     propertySpanBuilder.addPropertyChangeListener(this);
68     propertySpanBuilder.initialize(context);
69     axisHeaderBuilder = new AxisHeaderBuilderSupport(spanBuilder);
70   }
71
72   public void destroy(HttpSession JavaDoc session) throws Exception JavaDoc {
73     logger.info("destroy");
74     propertySpanBuilder.destroy(session);
75     propertySpanBuilder = null;
76     super.destroy(session);
77   }
78
79   /**
80    * called from startBuild()
81    */

82   protected void initialize(Axis axis) {
83     logger.info("initialize(Axis)");
84     if (showParentMembers) {
85       MemberTree tree = (MemberTree) table.getOlapModel().getExtension(MemberTree.ID);
86       if (tree != null) {
87         logger.info("adding LevelAxisDecorator");
88         axis = new LevelAxisDecorator(axis, tree);
89       }
90     }
91     logger.info("creating SpanCalc");
92     spanCalc = new SpanCalc(axis);
93
94     SpanConfigSupport scs = new SpanConfigSupport();
95     scs.setDirection(Member.class, memberSpan);
96     scs.setDirection(Displayable.class, headerSpan);
97     spanCalc.setConfig(scs);
98
99     propertySpanBuilder.addPropertySpans(spanCalc);
100
101     switch (hierarchyHeader) {
102     case HIERARCHY_HEADER:
103       spanCalc.addHierarchyHeader(new HierarchyHeaderFactory(), true);
104       break;
105     case LEVEL_HEADER:
106       spanCalc.addHierarchyHeader(new LevelHeaderFactory(), true);
107       break;
108     }
109   }
110
111   /**
112    * Returns the showParentMembers.
113    * @return boolean
114    */

115   public boolean isShowParentMembers() {
116     return showParentMembers;
117   }
118
119   /**
120    * Sets the showParentMembers.
121    * @param showParentMembers The showParentMembers to set
122    */

123   public void setShowParentMembers(boolean showParentMembers) {
124     this.showParentMembers = showParentMembers;
125     setDirty(true);
126   }
127
128   /**
129    * Returns the spanBuilder.
130    * @return SpanBuilder
131    */

132   public SpanBuilder getSpanBuilder() {
133     return spanBuilder;
134   }
135
136   /**
137    * Sets the spanBuilder.
138    * @param spanBuilder The spanBuilder to set
139    */

140   public void setSpanBuilder(SpanBuilder spanBuilder) {
141     this.spanBuilder = spanBuilder;
142     setDirty(true);
143   }
144
145   /**
146    * Returns the memberIndent.
147    * @return boolean
148    */

149   public boolean isMemberIndent() {
150     return memberIndent;
151   }
152
153   /**
154    * Sets the memberIndent.
155    * @param memberIndent The memberIndent to set
156    */

157   public void setMemberIndent(boolean memberIndent) {
158     this.memberIndent = memberIndent;
159     setDirty(true);
160   }
161
162   /**
163    * @see com.tonbeller.jpivot.ui.table.AxisBuilder#getAxisConfig()
164    */

165   public AxisConfig getAxisConfig() {
166     return this;
167   }
168
169   /**
170    * Returns the headerSpan.
171    * @return int
172    */

173   public int getHeaderSpan() {
174     return headerSpan;
175   }
176
177   /**
178    * Returns the hierarchyHeader.
179    * @return int
180    */

181   public int getHierarchyHeader() {
182     return hierarchyHeader;
183   }
184
185   /**
186    * Returns the memberSpan.
187    * @return int
188    */

189   public int getMemberSpan() {
190     return memberSpan;
191   }
192
193   /**
194    * Sets the headerSpan.
195    * @param headerSpan The headerSpan to set
196    */

197   public void setHeaderSpan(int headerSpan) {
198     this.headerSpan = headerSpan;
199     setDirty(true);
200   }
201
202   /**
203    * Sets the hierarchyHeader.
204    * @param hierarchyHeader The hierarchyHeader to set
205    */

206   public void setHierarchyHeader(int hierarchyHeader) {
207     this.hierarchyHeader = hierarchyHeader;
208     setDirty(true);
209   }
210
211   /**
212    * Sets the memberSpan.
213    * @param memberSpan The memberSpan to set
214    */

215   public void setMemberSpan(int memberSpan) {
216     this.memberSpan = memberSpan;
217     setDirty(true);
218   }
219
220   /**
221    * returns the row/column axis or null if result is
222    * 1- or 0-dimensional
223    */

224   protected abstract Axis getAxis();
225
226   public void startBuild(RequestContext context) {
227     Axis axis = getAxis();
228     if (axis != null)
229       initialize(axis);
230     super.startBuild(context);
231     spanBuilder.startBuild(context);
232   }
233
234   public void stopBuild() {
235     spanBuilder.stopBuild();
236     super.stopBuild();
237     // avoid memory leak
238
spanCalc = null;
239   }
240
241   /**
242    * only valid between startBuild() and stopBuild()
243    */

244   public SpanCalc getSpanCalc() {
245     return spanCalc;
246   }
247
248   /**
249    * builds a single cell of the axis.
250    * @param row
251    */

252   protected void buildHeading(Element JavaDoc row, Span span, int rowspan, int colspan, boolean even) {
253     axisHeaderBuilder.build(row, span, rowspan, colspan, even, isMemberIndent());
254   }
255
256   public PropertyConfig getPropertyConfig() {
257     return propertySpanBuilder;
258   }
259
260   public void propertyChange(PropertyChangeEvent JavaDoc evt) {
261     setDirty(true);
262   }
263
264   /**
265    * stores settings for Member Properties. The axis style is stored in the AxisStyleUI table extension
266    */

267   public Object JavaDoc getBookmarkState(int levelOfDetail) {
268     return getPropertyConfig().getBookmarkState(levelOfDetail);
269   }
270
271   /**
272    * restores settings for Member Properties. The axis style is stored in the AxisStyleUI table extension
273    */

274   public void setBookmarkState(Object JavaDoc state) {
275     getPropertyConfig().setBookmarkState(state);
276   }
277
278   public AxisHeaderBuilder getAxisHeaderBuilder() {
279     return axisHeaderBuilder;
280   }
281
282   public void setAxisHeaderBuilder(AxisHeaderBuilder axisHeaderBuilder) {
283     this.axisHeaderBuilder = axisHeaderBuilder;
284   }
285
286 }
287
Popular Tags