1 13 package com.tonbeller.jpivot.table; 14 15 import org.apache.log4j.Logger; 16 import org.w3c.dom.Element ; 17 18 import com.tonbeller.jpivot.olap.model.Axis; 19 import com.tonbeller.jpivot.table.span.HierarchyHeaderFactory; 20 import com.tonbeller.jpivot.table.span.IgnorePropertiesHierarchyHeaderFactory; 21 import com.tonbeller.jpivot.table.span.LevelHeaderFactory; 22 import com.tonbeller.jpivot.table.span.Span; 23 import com.tonbeller.jpivot.table.span.SpanCalc; 24 25 29 public class RowAxisBuilderImpl extends AxisBuilderSupport implements RowAxisBuilder, RowAxisConfig { 30 int positionHeader; 31 SpanCalc headerSpans; 32 private static final Logger logger = Logger.getLogger(RowAxisBuilderImpl.class); 33 34 public RowAxisBuilderImpl() { 35 super(new SpanBuilderImpl("row-heading", "heading-heading")); 36 setMemberIndent(true); 37 setShowParentMembers(false); 38 setHierarchyHeader(NO_HEADER); 39 setMemberSpan(HIERARCHY_THEN_POSITION_SPAN); 40 setHeaderSpan(HIERARCHY_THEN_POSITION_SPAN); 41 setPositionHeader(HIERARCHY_HEADER); 42 } 43 44 public void buildRow(Element parent, int rowIndex) { 45 boolean even = (rowIndex % 2 == 0); 46 for (int i = 0; i < spanCalc.getHierarchyCount(); i++) { 47 Span span = spanCalc.getSpan(rowIndex, i); 48 if (span.isSignificant()) { 49 int rowspan = span.getPositionSpan(); 50 int colspan = span.getHierarchySpan(); 51 buildHeading(parent, span, rowspan, colspan, even); 52 } 53 } 54 } 55 56 59 public int getColumnCount() { 60 return spanCalc.getHierarchyCount(); 61 } 62 63 66 public int getRowCount() { 67 return spanCalc.getPositionCount(); 68 } 69 70 74 public int getPositionHeader() { 75 return positionHeader; 76 } 77 78 82 public void setPositionHeader(int positionHeader) { 83 this.positionHeader = positionHeader; 84 setDirty(true); 85 } 86 87 public void buildHeaderRow(Element parent, int rowIndex) { 88 boolean even = (rowIndex % 2 == 0); 89 for (int i = 0; i < headerSpans.getHierarchyCount(); i++) { 90 Span span = headerSpans.getSpan(rowIndex, i); 91 if (logger.isInfoEnabled()) 92 logger.info("building header row: " + span); 93 if (span.isSignificant()) { 94 int rowspan = span.getPositionSpan(); 95 int colspan = span.getHierarchySpan(); 96 buildHeading(parent, span, rowspan, colspan, even); 97 } 98 } 99 } 100 101 public int getHeaderRowCount() { 102 if (headerSpans == null) 103 return 0; 104 return headerSpans.getPositionCount(); 105 } 106 107 public SpanCalc getHeaderSpanCalc() { 108 return headerSpans; 109 } 110 111 114 public void initialize(Axis axis) { 115 super.initialize(axis); 116 117 switch (positionHeader) { 118 case HIERARCHY_LEVEL_HEADER: 119 logger.info("HIERARCHY_LEVEL_HEADER"); 120 SpanCalc sc1 = spanCalc.createPositionHeader(new IgnorePropertiesHierarchyHeaderFactory()); 121 SpanCalc sc2 = spanCalc.createPositionHeader(new LevelHeaderFactory()); 122 headerSpans = SpanCalc.appendBelow(sc1, sc2); 123 break; 124 case LEVEL_HEADER: 125 logger.info("LEVEL_HEADER"); 126 headerSpans = spanCalc.createPositionHeader(new LevelHeaderFactory()); 127 break; 128 case HIERARCHY_HEADER: 129 logger.info("HIERARCHY_HEADER"); 130 headerSpans = spanCalc.createPositionHeader(new HierarchyHeaderFactory()); 131 break; 132 default: 133 headerSpans = null; 134 break; 135 } 136 if (headerSpans != null) 137 headerSpans.setConfig(spanCalc.getConfig()); 138 } 139 140 public void stopBuild() { 141 super.stopBuild(); 142 headerSpans = null; 144 } 145 146 protected Axis getAxis() { 147 return table.getRowAxis(); 148 } 149 150 } 151 | Popular Tags |