Wednesday, January 21, 2009

Eclipse RCP : Sorting JFace Viewer contents

The JFace viewer contents can be sorted by assigning them a ViewerSorter.


viewer.setSorter(new MyViewerSorter());

public class MyViewerSorter extends ViewerSorter
{
@Override
public int compare(Viewer viewer, Object o1, Object o2)
{
return o1.toString().compareToIgnoreCase(o2.toString());
}
}


This will sort the elements in alphabetical order.

No comments: