[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] background color of sorted column in swt table
|
I have a SWT Table that is sortable by clicking on column headers. To
implement the sort functionality, I add a sort listener:
(for all columns)
table.getColumn(i).addListener(SWT.Selection, sortListener);
The sort is then handled in the following procedure:
public void handleEvent( Event e )
{
// determine new sort column and direction
TableColumn sortColumn = table.getSortColumn();
TableColumn currentColumn = (TableColumn) e.widget;
int dir = table.getSortDirection();
if( sortColumn == currentColumn )
{
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
}
else
{
table.setSortColumn(currentColumn);
dir = SWT.UP;
}
for(int index = 0; index < table.getColumnCount(); index++)
{
if( currentColumn == table.getColumn(index) )
{
//get a comparator for sorting this column
Comparator comparator = labelProvider.getComparator(index);
if( dir != SWT.UP )
{
//this just inverts comparator's output
comparator = new InvertedComparator(comparator);
}
// do the sort -- this simply calls Collections.sort on the
// data in the table, using the given comparator
sortedContentProvider.sort(comparator);
// update data displayed in table
table.setSortDirection(dir);
table.deselectAll();
// this calls refresh on the TableViewer that contains
// the table
sortedContentProvider.refresh();
}
}
}
The sort works fine. The problem is that after the sort event occurs, the
background color of all cells in the sorted column is changed to light
grey. The rest of the table refreshes according to the LabelProvider's
constraints, which in my case implements ITableColorProvider to provide a
custom background color for rows in the table based on the data in each
row. I can't figure out how to make the background color of the sorted
column the same as the other columns after a sort. Can you help?
Thanks,
Chad