1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.model;
25
26 import java.text.SimpleDateFormat;
27 import java.util.*;
28
29 import javax.swing.table.AbstractTableModel;
30
31 import com.mindtree.techworks.insight.InsightConstants;
32 import com.mindtree.techworks.insight.spi.LogEvent;
33
34
35
36
37
38
39
40
41
42
43
44
45 public class LogEventTableModel extends AbstractTableModel {
46
47
48
49
50 private static final long serialVersionUID = -6989331565976765303L;
51
52
53
54
55 private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
56
57
58
59
60 public static final HashMap COL_NAMES = new HashMap();
61
62
63
64
65 public static final int FIRST_INDEX = 0;
66 public static final int TIME_INDEX = 0;
67 public static final int THREAD_INDEX = 1;
68 public static final int PRIORITY_INDEX = 2;
69 public static final int CATEGORY_INDEX = 3;
70 public static final int MESSAGE_INDEX = 4;
71 public static final int EXCEPTION_NAME_INDEX = 5;
72 public static final int METHOD_INDEX = 6;
73 public static final int LINE_INDEX = 7;
74 public static final int FILE_INDEX = 8;
75 public static final int CLASS_INDEX = 9;
76 public static final int RELATIVETIME_INDEX = 10;
77 public static final int LAST_INDEX = 10;
78
79
80
81
82 static{
83 COL_NAMES.put(new Integer(TIME_INDEX),InsightConstants.getLiteral("TIME_LABEL"));
84 COL_NAMES.put(new Integer(THREAD_INDEX),InsightConstants.getLiteral("THREAD_NAME_LABEL"));
85 COL_NAMES.put(new Integer(PRIORITY_INDEX),InsightConstants.getLiteral("PRIORITY_LABEL"));
86 COL_NAMES.put(new Integer(CATEGORY_INDEX),InsightConstants.getLiteral("LOGGER_NAME"));
87 COL_NAMES.put(new Integer(MESSAGE_INDEX),InsightConstants.getLiteral("MESSAGE_LABEL"));
88 COL_NAMES.put(new Integer(EXCEPTION_NAME_INDEX),InsightConstants.getLiteral("EXCEPTION_LABEL"));
89 COL_NAMES.put(new Integer(METHOD_INDEX),InsightConstants.getLiteral("METHOD_LABEL"));
90 COL_NAMES.put(new Integer(LINE_INDEX),InsightConstants.getLiteral("LINE_LABEL"));
91 COL_NAMES.put(new Integer(FILE_INDEX),InsightConstants.getLiteral("FILE_LABEL"));
92 COL_NAMES.put(new Integer(CLASS_INDEX),InsightConstants.getLiteral("CLASS_LABEL"));
93 COL_NAMES.put(new Integer(RELATIVETIME_INDEX),InsightConstants.getLiteral("RELATIVETIME_LABEL"));
94 };
95
96
97
98
99
100 private List eventList = new ArrayList();
101
102
103
104
105 private ModelDataSorter modelDataSorter;
106
107
108
109
110 private int[] columnList;
111
112
113
114
115
116 public LogEventTableModel(int[] columnList) {
117 this.columnList = columnList;
118 modelDataSorter = new ModelDataSorter();
119 }
120
121
122
123
124
125
126 public void changeDisplayColumns(int[] columnList) {
127 this.columnList = columnList;
128 modelDataSorter.resetSortParams();
129 super.fireTableStructureChanged();
130 }
131
132
133
134
135
136 public int getRowCount() {
137 return eventList.size();
138 }
139
140
141
142
143
144 public int getColumnCount() {
145 return columnList.length;
146 }
147
148
149
150
151
152 public String getColumnName(int col) {
153 return (String)COL_NAMES.get(new Integer(columnList[col]));
154 }
155
156
157
158
159
160
161 public void addLogEvent(LogEvent event) {
162 eventList.add(event);
163 int startIndex = eventList.size() - 2;
164 int endIndex = eventList.size() - 1;
165 fireTableRowsInserted(startIndex < 0 ? 0 : startIndex, endIndex < 0 ? 0 : endIndex);
166 }
167
168
169
170
171
172
173 public LogEvent getLoggingEvent(int index) {
174
175 if (index >= eventList.size()) {
176 return null;
177 }
178 return (LogEvent)eventList.get(index);
179 }
180
181
182
183
184
185 public Object getValueAt(int rowIndex, int columnIndex) {
186 if (rowIndex < eventList.size()) {
187 LogEvent event = (LogEvent)eventList.get(rowIndex);
188 switch(columnList[columnIndex]) {
189 case TIME_INDEX:
190 return DATE_FORMAT.format(new Date(event.getTimeStamp()));
191 case THREAD_INDEX:
192 return event.getThreadName();
193 case PRIORITY_INDEX:
194 return event.getLevel();
195 case CATEGORY_INDEX:
196 return event.getLoggerName();
197 case MESSAGE_INDEX:
198 return event.getMessage();
199 case EXCEPTION_NAME_INDEX:
200 return event.getExceptionName();
201 case METHOD_INDEX:
202 return event.getLocationInformation().getMethodName();
203 case LINE_INDEX:
204 return event.getLocationInformation().getLineNumber();
205 case FILE_INDEX:
206 return event.getLocationInformation().getFileName();
207 case CLASS_INDEX:
208 return event.getLocationInformation().getClassName();
209 case RELATIVETIME_INDEX:
210 return String.valueOf(event.getRelativeTime());
211 }
212 }
213 return null;
214 }
215
216
217
218
219
220 public void sortColumn(int columnIndex) {
221 modelDataSorter.sortData(columnIndex, this.eventList);
222 super.fireTableDataChanged();
223 }
224
225
226
227
228
229
230 public int getSortOrder(int columnIndex) {
231 return modelDataSorter.getSortOrder(this.columnList[columnIndex]);
232 }
233
234
235
236
237
238 public void clearModel() {
239 eventList.clear();
240 super.fireTableDataChanged();
241 modelDataSorter.resetSortParams();
242 }
243
244
245
246
247
248
249
250 public void updateDataModel(List logEventList) {
251 eventList.clear();
252 modelDataSorter.resetSortParams();
253
254
255 for (int i = 0; i < logEventList.size(); i++) {
256 this.eventList.add(logEventList.get(i));
257 }
258
259
260
261
262
263
264 }
265
266
267
268
269
270
271
272 public void updateDataModelAndDisplay(List logEventList) {
273 this.updateDataModel(logEventList);
274 super.fireTableDataChanged();
275 }
276
277
278
279
280 public int[] getColumnList() {
281 return columnList;
282 }
283
284
285
286 public void setColumnList(int[] columnList) {
287 this.columnList = columnList;
288 }
289 }