1 package ist.coach.coachEmfClientComponents.gui; 2 3 import javax.swing.table.AbstractTableModel ; 4 import java.util.Vector ; 5 import ist.coach.coachEmfServices.EmfBasicLog.LogRecord; 6 import ist.coach.coachEmfServices.EmfBasicLog.LogSeverity; 7 import java.text.DateFormat ; 8 import org.omg.CORBA.Any ; 9 10 class LogTableModel extends AbstractTableModel { 11 12 final String [] columnNames = {" Time ", 13 " Log Type ", 14 " Source Type ", 15 " Source ", 16 " Log Id ", 17 " Details " 18 }; 19 20 Vector data; 21 protected static int NUM_COLUMNS = 6; 22 protected static int TIME_C = 0; 23 24 protected static int EVENT_C = 1; 25 protected static int SOURCE_T_C = 2; 26 protected static int SOURCE_C = 3; 27 protected static int ID_C = 4; 28 protected static int DETAILS_C = 5; 29 30 private int nextEmptyRow = 0; 31 private static int START_NUM_ROWS = 30; int numRows = 0; 33 34 LogTableModel() { 35 36 data = new Vector (); 37 } 38 39 public int getColumnCount() { 40 return columnNames.length; 41 } 42 43 public int getRowCount() { 44 45 if (numRows < START_NUM_ROWS) 46 return START_NUM_ROWS; 47 else 48 return numRows; 49 } 50 51 public String getColumnName(int col) { 52 53 return columnNames[col]; 54 } 55 56 public Object getValueAt(int row, int col) { 57 58 try { 59 LogDisplayRecord logR = (LogDisplayRecord) data.elementAt(row); 60 61 switch(col) { 62 case 0: 63 return logR.timeR; 64 case 1: 65 return logR.eventType; 66 case 2: 67 return logR.sourceClass; 68 case 3: 69 return logR.source; 70 case 4: 71 return logR.notifId; 72 case 5: 73 return logR.details; 74 } 75 } 76 catch(Exception e) {} 77 78 return new String (); 79 80 } 81 82 88 public Class getColumnClass(int c) { 89 return getValueAt(0, c).getClass(); 90 } 91 92 96 public boolean isCellEditable(int row, int col) { 97 return false; 98 } 99 100 public synchronized void updateLogTable(String dateR, String eventType, 101 String source, String sourceClass, 102 String notifId, String details) { 103 104 LogDisplayRecord logR = new LogDisplayRecord(dateR, eventType, source, 106 sourceClass,notifId, details); 107 108 data.addElement(logR); 109 if (data.size() == data.capacity()) 110 data.ensureCapacity(data.size() + 100); 111 112 numRows++; 113 fireTableRowsInserted(nextEmptyRow, nextEmptyRow); 114 nextEmptyRow++; 115 } 117 118 public synchronized void updateLogArchives(LogRecord[] records) { 119 120 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT); 121 122 java.util.Date log_record_date; 123 String log_record_date_str = new String (); 124 String log_record_id = new String (); 125 String log_record_source= new String (); 126 String log_record_class= new String (); 127 String log_record_type= new String (); 128 String log_record_details= new String (); 129 130 for (int i = 0; i < records.length; i++) { 131 log_record_date = new java.util.Date (records[i].time); 132 log_record_date_str = df.format(log_record_date); 133 log_record_id = String.valueOf(records[i].id); 134 log_record_details = records[i].info.extract_string(); 135 136 for(int j = 0; j < records[i].attr_list.length; j++) { 137 138 if (records[i].attr_list[j].name.equals("Source")) 139 log_record_source = records[i].attr_list[j].value.extract_string(); 140 else 141 if (records[i].attr_list[j].name.equals("SourceClass")) 142 log_record_class = records[i].attr_list[j].value.extract_string(); 143 else 144 if (records[i].attr_list[j].name.equals("EventType")) { 145 146 log_record_type = GuiMessages.info_log; 147 148 switch(records[i].attr_list[j].value.extract_short()) { 149 case LogSeverity._Error : 150 log_record_type = GuiMessages.error_log; 151 break; 152 case LogSeverity._FatalError : 153 log_record_type = GuiMessages.fatal_error_log; 154 break; 155 case LogSeverity._Warning : 156 log_record_type = GuiMessages.warning_log; 157 break; 158 }; 159 160 } 161 } 162 updateLogTable(log_record_date_str, log_record_type, 163 log_record_source, log_record_class, 164 log_record_id, log_record_details); 165 } 166 } 167 168 public synchronized void clear() { 169 170 int oldNumRows = numRows; 171 172 numRows = START_NUM_ROWS; 173 data.removeAllElements(); 174 nextEmptyRow = 0; 175 176 if (oldNumRows > START_NUM_ROWS) 177 fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1); 178 179 fireTableRowsUpdated(0, START_NUM_ROWS - 1); 180 } 181 182 public void printDebugData() { 183 int numRows = getRowCount(); 184 185 LogDisplayRecord record ; 186 for (int i=0; i < numRows; i++) { 187 System.err.println("------> LogDisplayRecord" + i + " <-----------"); 188 record = (LogDisplayRecord) data.get(i); 189 record.print(); 190 } 191 } 192 193 private class LogDisplayRecord { 194 195 String timeR = null; 196 String notifId = null; 197 String eventType = null; 198 String source = null; 199 String sourceClass = null; 200 String details = null; 201 202 LogDisplayRecord() {} 203 LogDisplayRecord(String timeR, String eventType, String source, 204 String sourceClass, String notifId, String details) { 205 206 207 this.timeR = timeR; 208 this.notifId = notifId; 209 this.eventType = eventType; 210 this.source = source; 211 this.sourceClass = sourceClass; 212 this.details = details; 213 } 214 215 void print() { 216 System.err.println("Time =" + timeR + 217 "\tEvent Type =" + eventType + 218 "\tSource = " + source + 219 "\tSourceClass = " + sourceClass + 220 "\tId = " + notifId + 221 "\tDetails = " + details); 222 } 223 224 } 225 } 226 227 | Popular Tags |