1 13 package com.tonbeller.jpivot.table; 14 15 import java.beans.PropertyChangeEvent ; 16 import java.beans.PropertyChangeListener ; 17 18 import javax.servlet.http.HttpSession ; 19 20 import org.apache.log4j.Logger; 21 import org.w3c.dom.Element ; 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 41 public abstract class AxisBuilderSupport extends PartBuilderSupport implements AxisBuilder, 42 AxisConfig, PropertyChangeListener { 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 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 { 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 session) throws Exception { 73 logger.info("destroy"); 74 propertySpanBuilder.destroy(session); 75 propertySpanBuilder = null; 76 super.destroy(session); 77 } 78 79 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 115 public boolean isShowParentMembers() { 116 return showParentMembers; 117 } 118 119 123 public void setShowParentMembers(boolean showParentMembers) { 124 this.showParentMembers = showParentMembers; 125 setDirty(true); 126 } 127 128 132 public SpanBuilder getSpanBuilder() { 133 return spanBuilder; 134 } 135 136 140 public void setSpanBuilder(SpanBuilder spanBuilder) { 141 this.spanBuilder = spanBuilder; 142 setDirty(true); 143 } 144 145 149 public boolean isMemberIndent() { 150 return memberIndent; 151 } 152 153 157 public void setMemberIndent(boolean memberIndent) { 158 this.memberIndent = memberIndent; 159 setDirty(true); 160 } 161 162 165 public AxisConfig getAxisConfig() { 166 return this; 167 } 168 169 173 public int getHeaderSpan() { 174 return headerSpan; 175 } 176 177 181 public int getHierarchyHeader() { 182 return hierarchyHeader; 183 } 184 185 189 public int getMemberSpan() { 190 return memberSpan; 191 } 192 193 197 public void setHeaderSpan(int headerSpan) { 198 this.headerSpan = headerSpan; 199 setDirty(true); 200 } 201 202 206 public void setHierarchyHeader(int hierarchyHeader) { 207 this.hierarchyHeader = hierarchyHeader; 208 setDirty(true); 209 } 210 211 215 public void setMemberSpan(int memberSpan) { 216 this.memberSpan = memberSpan; 217 setDirty(true); 218 } 219 220 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 spanCalc = null; 239 } 240 241 244 public SpanCalc getSpanCalc() { 245 return spanCalc; 246 } 247 248 252 protected void buildHeading(Element 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 evt) { 261 setDirty(true); 262 } 263 264 267 public Object getBookmarkState(int levelOfDetail) { 268 return getPropertyConfig().getBookmarkState(levelOfDetail); 269 } 270 271 274 public void setBookmarkState(Object 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 |