KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > report > core > ResultTableModel


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.report.core;
15
16 import java.util.*;
17 import javax.swing.event.*;
18 import javax.swing.table.*;
19
20 /**
21  * The TableModel for JTable to present RModel information
22  *
23  * @author Jorg Janke
24  * @version $Id: ResultTableModel.java,v 1.2 2002/02/06 05:59:52 jjanke Exp $
25  */

26 class ResultTableModel implements TableModel
27 {
28     /**
29      * Create a JTable Model from ReportModel
30      * @param reportModel
31      */

32     public ResultTableModel (RModel reportModel)
33     {
34         m_model = reportModel;
35     } // ResultTableModel
36

37     /** The Report Model */
38     private RModel m_model;
39
40     /**
41      * Get Row Count
42      * @return row count
43      */

44     public int getRowCount()
45     {
46         return m_model.getRowCount();
47     } // getRowCount
48

49     /**
50      * Get ColumnCount
51      * @return column count
52      */

53     public int getColumnCount()
54     {
55         return m_model.getColumnCount();
56     } // getColumnCount
57

58     /**
59      * Get Column Name
60      * @param columnIndex
61      * @return Column Name
62      */

63     public String JavaDoc getColumnName(int columnIndex)
64     {
65         return m_model.getColumnName(columnIndex);
66     } // getColumnIndex
67

68     /**
69      * Get Column Class
70      * @param columnIndex
71      * @return Column Class
72      */

73     public Class JavaDoc getColumnClass(int columnIndex)
74     {
75         return m_model.getColumnClass(columnIndex);
76     } // getColumnClass
77

78     /**
79      * Is Cell Editable
80      * @param rowIndex
81      * @param columnIndex
82      * @return true, if editable
83      */

84     public boolean isCellEditable(int rowIndex, int columnIndex)
85     {
86         return false;
87     } // isCellEditable
88

89     /**
90      * Get Value At
91      * @param row
92      * @param col
93      * @return value
94      */

95     public Object JavaDoc getValueAt(int row, int col)
96     {
97         return m_model.getValueAt(row, col);
98     } // getValueAt
99

100     /**
101      * Set Value At
102      * @param aValue
103      * @param row
104      * @param col
105      */

106     public void setValueAt(Object JavaDoc aValue, int row, int col)
107     {
108         m_model.setValueAt(aValue, row, col);
109         fireTableChanged(new TableModelEvent (this, row, row, col, TableModelEvent.UPDATE));
110     } // setValueAt
111

112     /**
113      * Move Row
114      * @param from index
115      * @param to index
116      */

117     public void moveRow (int from, int to)
118     {
119         m_model.moveRow (from, to);
120     } // moveRow
121

122     /*************************************************************************/
123
124     transient private Vector tableModelListeners;
125
126     public synchronized void removeTableModelListener(TableModelListener l)
127     {
128         if (tableModelListeners != null && tableModelListeners.contains(l))
129         {
130             Vector v = (Vector) tableModelListeners.clone();
131             v.removeElement(l);
132             tableModelListeners = v;
133         }
134     }
135     public synchronized void addTableModelListener(TableModelListener l)
136     {
137         Vector v = tableModelListeners == null ? new Vector(2) : (Vector) tableModelListeners.clone();
138         if (!v.contains(l))
139         {
140             v.addElement(l);
141             tableModelListeners = v;
142         }
143     }
144     protected void fireTableChanged(TableModelEvent e)
145     {
146         if (tableModelListeners != null)
147         {
148             Vector listeners = tableModelListeners;
149             int count = listeners.size();
150             for (int i = 0; i < count; i++)
151             {
152                 ((TableModelListener) listeners.elementAt(i)).tableChanged(e);
153             }
154         }
155     }
156
157 } // ResultTableModel
158
Popular Tags