Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » ViewSorter
ViewSorter [message #313432] Wed, 14 March 2007 17:47 Go to next message
Eclipse UserFriend
I'm attempting to create a table with a ViewSorter. Nothing out of the
ordinary. In my attempts I've created a table with a TableViewer
attached. Then added a TableEditor which does a ton of stuff. Then I
attempted to add a custom ViewerSorter. It never gets called.

I also tried ViewerComparator (Since I'm using Eclipse 3.2). I'm also
using the up/down capabilites on the table.

Anyway The code below is the Selection service I attached to the table
column. Clicking on the column label works and the up/down arrow appears
and changes. Just setting the sorter never seems to call my sorters
compare. Here is the code.

Listener on the column:
TableColumn tableColumnName = new TableColumn( tableHours, SWT.NONE );
tableColumnName.setWidth( 120 ); // Generated
tableColumnName.setText( "Name" ); // Generated
tableColumnName.addSelectionListener( new SelectionAdapter( )
{
public void widgetSelected( SelectionEvent e )
{
int direction = tableViewer.getTable( ).getSortDirection( );
TableColumn sortColumn = tableViewer.getTable( ).getSortColumn( );
TableColumn currentColumn = (TableColumn)e.widget;
if( sortColumn == currentColumn )
{
direction = direction == SWT.UP ? SWT.DOWN : direction == SWT.DOWN ?
SWT.NONE : SWT.UP;
if( direction == SWT.NONE )
{
tableViewer.getTable( ).setSortColumn( null );
}
}
else
{
tableViewer.getTable( ).setSortColumn( currentColumn );
direction = SWT.UP;
}

tableViewer.getTable( ).setSortDirection( direction );
tableViewer.setComparator( new TableViewerComparator( direction ) );
);
}
} );

The Comparator:
public class TableViewerComparator extends ViewerComparator
{
int direction = SWT.DOWN;

/**
* @param direction
*/
public TableViewerComparator( int direction )
{
this.direction = direction;
}

@Override
public int compare( Viewer viewer, Object e1, Object e2 )
{
System.out.println( e1.getClass( ) );
System.out.println( e2.getClass( ) );

return super.compare( viewer, e1, e2 );
}
}

Any help would be appriciated.
steve

PS I'm using eclipse 3.2 and Java 1.6 Any help would be appriciated
Re: ViewSorter [message #313464 is a reply to message #313432] Thu, 15 March 2007 06:21 Go to previous messageGo to next message
Eclipse UserFriend
Well I finally got an answer. The problem in my code was the table was
created with the SWT.Virtual flag. In the java doc is states:

* As of 3.1 the TableViewer now supports the SWT.VIRTUAL flag. If the
* underlying table is SWT.VIRTUAL, the content provider may implement
* {@link ILazyContentProvider} instead of {@link
IStructuredContentProvider}.
* Note that in this case, the viewer does not support sorting or
filtering.
* Also note that in this case, the Widget based APIs may return null if
the
* element is not specified or not created yet.

Hopefully this will help someone else.

steve
Re: ViewSorter [message #313466 is a reply to message #313464] Thu, 15 March 2007 06:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

do you use a ILazyContentProvider if that's not the case maybe the
following bug might interest you. We can fix it in 3.3
https://bugs.eclipse.org/bugs/show_bug.cgi?id=177475

Tom

Paulin schrieb:
> Well I finally got an answer. The problem in my code was the table was
> created with the SWT.Virtual flag. In the java doc is states:
>
> * As of 3.1 the TableViewer now supports the SWT.VIRTUAL flag. If the
> * underlying table is SWT.VIRTUAL, the content provider may implement
> * {@link ILazyContentProvider} instead of {@link
> IStructuredContentProvider}.
> * Note that in this case, the viewer does not support sorting or filtering.
> * Also note that in this case, the Widget based APIs may return null if the
> * element is not specified or not created yet.
>
> Hopefully this will help someone else.
>
> steve
>
>


--
B e s t S o l u t i o n . a t EDV Systemhaus GmbH
----------------------------------------------------
tom schindl Eclipse JFace Committer
Re: ViewSorter [message #313485 is a reply to message #313466] Thu, 15 March 2007 09:27 Go to previous messageGo to next message
Eclipse UserFriend
I used the IStructuredContentProvider.

steve
Re: ViewSorter [message #313487 is a reply to message #313485] Thu, 15 March 2007 09:36 Go to previous message
Eclipse UserFriend
Already commented on the bug. Wait for the bug to be resolved and
everything should work as long you are *not* using an
ILazyContentProvider I think where we can't sort, filter, ... .

Tom

Paulin schrieb:
> I used the IStructuredContentProvider.
> steve
>


--
B e s t S o l u t i o n . a t EDV Systemhaus GmbH
----------------------------------------------------
tom schindl Eclipse JFace Committer
Previous Topic:Get resource from Path
Next Topic:WizardPage does not display page name event when set
Goto Forum:
  


Current Time: Thu Jul 17 21:41:15 EDT 2025

Powered by FUDForum. Page generated in 0.05075 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top