KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > common > ReportTableModel


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 JavaDoc;
8 import javax.swing.table.DefaultTableModel JavaDoc;
9
10 import com.calipso.reportgenerator.common.QueryMetric;
11 import com.calipso.reportgenerator.common.QueryDimension;
12
13 import java.util.Vector JavaDoc;
14
15 /**
16  *
17  * User: soliveri
18  * Date: Dec 16, 2003
19  * Time: 2:59:52 PM
20  *
21  */

22
23 public abstract class ReportTableModel implements JRDataSource {
24
25   private TableModel JavaDoc reportTableModel;
26   private Vector JavaDoc tableColumnNames;
27   private Vector JavaDoc 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 JavaDoc 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 JavaDoc getFieldValue(JRField jrField) throws JRException {
44     Object JavaDoc value = null;
45     int col = 0;
46         String JavaDoc 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 JavaDoc tableColumnNames) {
57     this.tableColumnNames = tableColumnNames;
58   }
59
60   protected void setTableData(Vector JavaDoc tableData) {
61     this.tableData = tableData;
62   }
63
64   /**
65    * Devuelve un vector que contiene los nombres de las columnas para el modelo
66    * @param groupingDimensions dimensiones que agrupan
67    * @param nonGroupingDimensions dimensiones que no agrupan
68    * @param metricsArray metricas
69    * @return nombres de las columnas para el modelo
70    */

71   protected Vector JavaDoc getTableModelColumns(Object JavaDoc[] groupingDimensions, Object JavaDoc[] nonGroupingDimensions, Object JavaDoc[] metricsArray) {
72     Vector JavaDoc columnNames = new Vector JavaDoc();
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 JavaDoc(tableData, tableColumnNames);
90   }
91
92   protected void newNonDataTableModel() {
93     reportTableModel = new DefaultTableModel JavaDoc(new Vector JavaDoc(), tableColumnNames);
94   }
95
96   public TableModel JavaDoc 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 JavaDoc getOccurrences() {
133     return occurrences;
134   }
135 }
136
Popular Tags