EventTableModel<Color> tableModel = new EventTableModel<Color>(colors, greenBlueTableFormat);
// prepare the table for sorting and rendering its header
JTable table = new JTable(tableModel);
TableComparatorChooser<Color> tableComparatorChooser = TableComparatorChooser.install(table, sortedColors, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();
// sort by each column in sequence
clickColumnHeader(table, 0);
assertEquals(rbg, sortedColors);
clickColumnHeader(table, 1);
assertEquals(rgb, sortedColors);
// make sure we can still paint the header cells
headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 0);
// make sure we can handle negative indexes
final Component rendered = headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, -1, -1);
// no sort icon expected
if (rendered instanceof JLabel) {
assertNull(((JLabel) rendered).getIcon());
}
// uninstall the table comparator chooser and make sure no ill effects are left behind
tableComparatorChooser.dispose();
headerRenderer = table.getTableHeader().getDefaultRenderer();
// clicking column headers shouldn't change anything after the comparator
// chooser is disposed
clickColumnHeader(table, 0);
assertEquals(rgb, sortedColors);
clickColumnHeader(table, 1);
assertEquals(rgb, sortedColors);
// make sure we can still paint the header cells
headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 0);
headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 1);
// now create a three column table
TableFormat<Color> redGreenBlueTableFormat = GlazedLists.tableFormat(new String[] { "red", "green", "blue" }, new String[] { "Red", "Green", "Blue" });
tableModel.setTableFormat(redGreenBlueTableFormat);
// make sure we can paint all three header cells
headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 0);
headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 1);
headerRenderer.getTableCellRendererComponent(table, tableModel.getColumnName(0), false, false, 0, 2);
// try out the new table for sorting
TableComparatorChooser.install(table, sortedColors, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
sortedColors.setComparator(null);
assertEquals(rgb, sortedColors);