KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfClientComponents > gui > AlarmTableModel


1 package ist.coach.coachEmfClientComponents.gui;
2
3 import javax.swing.table.AbstractTableModel JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 class AlarmTableModel extends AbstractTableModel JavaDoc {
7
8         final String JavaDoc[] columnNames = {" Time ",
9                                     " Event Type ",
10                                     " Source Type ",
11                                     " Source ",
12                                     " Alarm Id ",
13                                     " Details "
14         };
15
16         Vector JavaDoc data;
17         protected static int NUM_COLUMNS = 6;
18         protected static int TIME_C = 0;
19         protected static int EVENT_C = 1;
20         protected static int SOURCE_T_C = 2;
21         protected static int SOURCE_C = 3;
22         protected static int ID_C = 4;
23         protected static int DETAILS_C = 5;
24     
25         private int nextEmptyRow = 0;
26         private static int START_NUM_ROWS = 20;
27         int numRows = 0;
28
29         AlarmTableModel() {
30
31             data = new Vector JavaDoc();
32         }
33
34         public int getColumnCount() {
35             return columnNames.length;
36         }
37
38         public int getRowCount() {
39
40             if (numRows < START_NUM_ROWS)
41                 return START_NUM_ROWS;
42             else
43                 return numRows;
44         }
45
46         public String JavaDoc getColumnName(int col) {
47
48             return columnNames[col];
49         }
50
51         public Object JavaDoc getValueAt(int row, int col) {
52
53             try {
54                 AlarmRecord alarmR = (AlarmRecord) data.elementAt(row);
55
56                 switch(col) {
57                 case 0:
58                     return alarmR.timeR;
59                 case 1:
60                     return alarmR.eventType;
61                 case 2:
62                     return alarmR.sourceClass;
63                 case 3:
64                     return alarmR.source;
65                 case 4:
66                     return alarmR.notifId;
67                 case 5:
68                     return alarmR.details;
69                 }
70             }
71             catch(Exception JavaDoc e) {}
72             
73             return new String JavaDoc();
74
75         }
76
77         /*
78          * JTable uses this method to determine the default renderer/
79          * editor for each cell. If we didn't implement this method,
80          * then the last column would contain text ("true"/"false"),
81          * rather than a check box.
82          */

83         public Class JavaDoc getColumnClass(int c) {
84             return getValueAt(0, c).getClass();
85         }
86
87         /*
88          * Don't need to implement this method unless your table's
89          * editable.
90          */

91         public boolean isCellEditable(int row, int col) {
92                 return false;
93         }
94
95         public void updateAlarmTable(String JavaDoc dateR, String JavaDoc eventType,
96                         String JavaDoc source, String JavaDoc sourceClass,
97                         String JavaDoc notifId, String JavaDoc details) {
98
99             AlarmRecord alarmR = new AlarmRecord(dateR, eventType, source,
100                                             sourceClass,notifId, details);
101
102             data.addElement(alarmR);
103             
104             numRows++;
105             fireTableRowsInserted(nextEmptyRow, nextEmptyRow);
106             nextEmptyRow++;
107         }
108
109         public synchronized void clear() {
110
111             int oldNumRows = numRows;
112
113             numRows = START_NUM_ROWS;
114             data.removeAllElements();
115             nextEmptyRow = 0;
116
117             if (oldNumRows > START_NUM_ROWS)
118                 fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1);
119
120             fireTableRowsUpdated(0, START_NUM_ROWS - 1);
121         }
122
123         public void printDebugData() {
124             int numRows = getRowCount();
125
126             AlarmRecord record ;
127             for (int i=0; i < numRows; i++) {
128                 System.err.println("------> AlarmRecord" + i + " <-----------");
129                 record = (AlarmRecord) data.get(i);
130                 record.print();
131             }
132         }
133
134     private class AlarmRecord {
135
136         String JavaDoc timeR = null;
137         String JavaDoc notifId = null;
138         String JavaDoc eventType = null;
139         String JavaDoc source = null;
140         String JavaDoc sourceClass = null;
141         String JavaDoc details = null;
142
143         AlarmRecord() {}
144         AlarmRecord(String JavaDoc timeR, String JavaDoc eventType, String JavaDoc source,
145                     String JavaDoc sourceClass, String JavaDoc notifId, String JavaDoc details) {
146
147
148             this.timeR = timeR;
149             this.notifId = notifId;
150             this.eventType = eventType;
151             this.source = source;
152             this.sourceClass = sourceClass;
153             this.details = details;
154         }
155
156         void print() {
157             System.err.println("Time =" + timeR +
158                                 "\tEvent Type =" + eventType +
159                                 "\tSource = " + source +
160                                 "\tSourceClass = " + sourceClass +
161                                 "\tId = " + notifId +
162                                 "\tDetails = " + details);
163         }
164         
165     }
166 }
167
168
Popular Tags