fixColumnWidths();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getTableHeader().setReorderingAllowed(false);
table.getTableHeader().addMouseListener(new MouseAdapter() {
private LogRecordComparator comp = new LogRecordComparator();
public void mouseClicked(MouseEvent e) {
if(e.getClickCount() < 2)
return;
int index = table.getTableHeader().columnAtPoint(e.getPoint());
String column = table.getColumnName(index);
int previousField = comp.getField();
if (column.equals(COL_ID)) {
comp.setField(LogRecordComparator.FIELD_ID);
} else if (column.equals(COL_DATE)) {
comp.setField(LogRecordComparator.FIELD_DATE);
} else if (column.equals(COL_LEVEL)) {
comp.setField(LogRecordComparator.FIELD_LEVEL);
} else if (column.equals(COL_USER_ID)) {
comp.setField(LogRecordComparator.FIELD_USER_ID);
} else if (column.equals(COL_TRANSACTION_ID)) {
comp.setField(LogRecordComparator.FIELD_TRANSACTION_ID);
} else if (column.equals(COL_EVENT_ID)) {
comp.setField(LogRecordComparator.FIELD_EVENT_ID);
} else if (column.equals(COL_EVENT_TYPE)) {
comp.setField(LogRecordComparator.FIELD_EVENT_TYPE);
} else if (column.equals(COL_MESSAGE)) {
comp.setField(LogRecordComparator.FIELD_MESSAGE);
}
if (previousField == comp.getField()) {
comp.setAsc(! comp.isAsc());
} else {
comp.setAsc(true);
}
tableModel.sort(comp);
fixColumnWidths();
}
});