KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > StatTableModel


1 package sellwin.gui;
2
3 import sellwin.domain.*;
4 import sellwin.server.*;
5 import sellwin.utils.*;
6
7 import java.util.*;
8 import java.rmi.*;
9 import javax.swing.*;
10 import javax.swing.table.*;
11 import java.awt.*;
12 import java.awt.event.*;
13
14 // SellWin http://sourceforge.net/projects/sellwincrm
15
//Contact support@open-app.com for commercial help with SellWin
16
//This software is provided "AS IS", without a warranty of any kind.
17

18 /**
19  * This class implements a table model for the stats table
20  * see the java spec for swing tables for details on thich
21  * mechanism
22  */

23 public class StatTableModel extends AbstractTableModel {
24     private String JavaDoc[] columnNames = {
25         "Data Type", "Sync Status", "Local Inserts", "Local Updates" };
26
27     private ArrayList wholeList = null;
28     private Stat stat = new Stat();
29
30     /**
31      * construct a stat table model
32      * @param wholeList a list of stats to load this model
33      * with
34      */

35     public StatTableModel(ArrayList wholeList) {
36         this.wholeList = wholeList;
37         stat.dataType = "init";
38         stat.syncStatus = "Ready";
39         stat.localInserts = new Integer JavaDoc(0);
40         stat.localUpdates = new Integer JavaDoc(0);
41
42         setLang();
43     }
44
45     /**
46      * add a Stat to the list this table model uses
47      * @param f Stat to add to this model's list
48      */

49     public final void addStat(Stat f) {
50         wholeList.add(f);
51     }
52
53     /**
54      * get a Stat from this model's list
55      * @param index use this index to retreive a Stat
56      * from the list used by this model
57      * @return a Stat
58      */

59     public final Stat getStat(int index) {
60         return (Stat)(wholeList.get(index));
61     }
62
63     /**
64      * get the whole list of Stats used by this model
65      * @return the list of Stats
66      */

67     public final ArrayList getStats() {
68         return wholeList;
69     }
70
71     /**
72      * see the java spec
73      */

74     public final Object JavaDoc getValueAt(int row, int col) {
75         Stat stat = (Stat)wholeList.get(row);
76         switch (col) {
77             case 0: //Stat dataType
78
return stat.dataType;
79             case 1: //Stat syncStatus
80
return stat.syncStatus;
81             case 2: //local inserts
82
return stat.localInserts;
83             case 3: //local updates
84
return stat.localUpdates;
85             default:
86                 System.out.println("oops its dorked");
87             break;
88         }
89         return null;
90     }
91
92     /**
93      * see the java spec
94      */

95     public final int getRowCount() {
96         return wholeList.size();
97     }
98
99     /**
100      * see the java spec
101      */

102     public final int getColumnCount() {
103         return columnNames.length;
104     }
105
106     /**
107      * see the java spec
108      */

109     public final String JavaDoc getColumnName(int col) {
110         return columnNames[col];
111     }
112
113     /**
114      * see the java spec
115      */

116     public final Class JavaDoc getColumnClass(int col) {
117         switch (col) {
118             case 0: //dataType
119
return stat.dataType.getClass();
120             case 1: //syncStatus
121
return stat.syncStatus.getClass();
122             case 2: //local inserts
123
return stat.localInserts.getClass();
124             case 3: //local updates
125
return stat.localUpdates.getClass();
126             default:
127                 System.out.println("oops its dorked");
128             break;
129         }
130         return null;
131     }
132     
133     /**
134      * see the java spec
135      */

136     public final void setValueAt(Object JavaDoc value, int row, int col) {
137         Stat f = (Stat)wholeList.get(row);
138         switch (col) {
139             case 0: //dataType
140
stat.dataType = (String JavaDoc)value;
141                 break;
142             case 1: //syncStatus
143
stat.syncStatus = (String JavaDoc)value;
144                 break;
145             case 2: //localInserts
146
stat.localInserts = (Integer JavaDoc)value;
147                 break;
148             case 3: //localUpdates
149
stat.localUpdates= (Integer JavaDoc)value;
150                 break;
151             default:
152                 System.out.println("oops its dorked");
153             break;
154         }
155         fireTableCellUpdated(row, col);
156     }
157
158     /**
159      * see the java spec
160      */

161     public final boolean isCellEditable(int row, int col) {
162         return false;
163     }
164
165     public final void setLang() {
166         Whiteboard wb = MainWindow.getWhiteboard();
167         columnNames[0] = wb.getLang().getString("dataType");
168         columnNames[1] = wb.getLang().getString("syncStatus");
169         columnNames[2] = wb.getLang().getString("localInserts");
170         columnNames[3] = wb.getLang().getString("localUpdates");
171     }
172 }
173
Popular Tags