[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: background color of sorted column in swt table
|
Are you using an old eclipse/swt? This claims to be fixed as of 3.3, see:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=143707
https://bugs.eclipse.org/bugs/show_bug.cgi?id=156817
Grant
"Steffen" <steffen_home_92@xxxxxxxxxxx> wrote in message
news:fsicu7$gc5$1@xxxxxxxxxxxxxxxxxxxx
> I have the same problem. A call to Table.setSortColumn marks the whole
> column grey to show that this column is sorted for. You may use the
> Viewer.setComparator method to sort your items but not the
> Table.setSortColumn to show sorting column. Unfortunately the sorting
> direction will not be shown in the header, i think.
>
> Hope that helps,
> Steffen
>
>
> Chad Showalter schrieb:
> > 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
> >