1 package com.calipso.reportgenerator.common; 2 3 import net.sf.jasperreports.engine.JRDataSource; 4 import net.sf.jasperreports.engine.JRException; 5 import net.sf.jasperreports.engine.JRField; 6 7 import javax.swing.table.TableModel ; 8 import javax.swing.table.DefaultTableModel ; 9 10 import com.calipso.reportgenerator.common.QueryMetric; 11 import com.calipso.reportgenerator.common.QueryDimension; 12 13 import java.util.Vector ; 14 15 22 23 public abstract class ReportTableModel implements JRDataSource { 24 25 private TableModel reportTableModel; 26 private Vector tableColumnNames; 27 private Vector tableData; 28 private int groupingDimCount; 29 private int nonGroupingDimCount; 30 private int commonMetricsCount; 31 private int accMetricsCount; 32 private int index = -1; 33 protected Vector occurrences; 34 35 public ReportTableModel() { 36 } 37 38 public boolean next() throws JRException { 39 index++; 40 return (index < reportTableModel.getRowCount()); 41 } 42 43 public Object getFieldValue(JRField jrField) throws JRException { 44 Object value = null; 45 int col = 0; 46 String fieldName = jrField.getName(); 47 48 for(int i = 0 ; i < tableColumnNames.size() ; i++, col++) { 49 if (tableColumnNames.elementAt(i).toString().equals(fieldName)) { 50 value = reportTableModel.getValueAt(index, col); 51 } 52 } 53 return value; 54 } 55 56 protected void setTableColumnNames(Vector tableColumnNames) { 57 this.tableColumnNames = tableColumnNames; 58 } 59 60 protected void setTableData(Vector tableData) { 61 this.tableData = tableData; 62 } 63 64 71 protected Vector getTableModelColumns(Object [] groupingDimensions, Object [] nonGroupingDimensions, Object [] metricsArray) { 72 Vector columnNames = new Vector (); 73 for (int i = 0; i < groupingDimensions.length; i++) { 74 QueryDimension qd = (QueryDimension) groupingDimensions[i]; 75 columnNames.add(qd.getName()); 76 } 77 for (int i = 0; i < nonGroupingDimensions.length; i++) { 78 QueryDimension qd = (QueryDimension) nonGroupingDimensions[i]; 79 columnNames.add(qd.getName()); 80 } 81 for (int i = 0; i < metricsArray.length; i++) { 82 QueryMetric qm = (QueryMetric) metricsArray[i]; 83 columnNames.add(qm.getName()); 84 } 85 return columnNames; 86 } 87 88 protected void newDefaultTableModel() { 89 reportTableModel = new DefaultTableModel (tableData, tableColumnNames); 90 } 91 92 protected void newNonDataTableModel() { 93 reportTableModel = new DefaultTableModel (new Vector (), tableColumnNames); 94 } 95 96 public TableModel getModel() { 97 return reportTableModel; 98 } 99 100 public int getGroupingDimCount() { 101 return groupingDimCount; 102 } 103 104 protected void setGroupingDimCount(int groupingDimCount) { 105 this.groupingDimCount = groupingDimCount; 106 } 107 108 public int getNonGroupingDimCount() { 109 return nonGroupingDimCount; 110 } 111 112 protected void setNonGroupingDimCount(int nonGroupingDimCount) { 113 this.nonGroupingDimCount = nonGroupingDimCount; 114 } 115 116 public int getCommonMetricsCount() { 117 return commonMetricsCount; 118 } 119 120 protected void setCommonMetricsCount(int commonMetricsCount) { 121 this.commonMetricsCount = commonMetricsCount; 122 } 123 124 public int getAccMetricsCount() { 125 return accMetricsCount; 126 } 127 128 protected void setAccMetricsCount(int accMetricsCount) { 129 this.accMetricsCount = accMetricsCount; 130 } 131 132 public Vector getOccurrences() { 133 return occurrences; 134 } 135 } 136 | Popular Tags |