Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Issue with default Sorting on Virtual Table & ViewerComparator(Issue with default Sorting on Virtual Table & ViewerComparator)
Issue with default Sorting on Virtual Table & ViewerComparator [message #829783] Mon, 26 March 2012 19:32
Santhosh Missing name is currently offline Santhosh Missing nameFriend
Messages: 12
Registered: July 2009
Junior Member
We have a Virtual Table in our Eclipse RCP application. We make a call to the backend to retrieve the data to be populated in the virtual table.

We want default sorting on the table on a single column. We use ViewerComparator to achieve sorting functionality. My problem is, I am not able to get this sorting working when the table loads with the data for the 1st time. But when I click on the column, everything works fine as expected.

This is how, I set the Comparator to the column

TableViewerColumn tvc = viewer.addColumn(100, SWT.LEFT, "Name");
new Comparator<Person>() {
public int compare(Person o1,Person o2) {
double firstValue = Double.parseDouble(o1
double secondValue = Double.parseDouble(o2
return firstValue > secondValue ? 1 : -1;


setColumnComparator method in custom viewer

public void setColumnComparator(TableViewerColumn tvc, Comparator<T> cmp){
final MyViewerComparator c = new MyViewerComparator(cmp);
final TableColumn tc = tvc.getColumn();


tc.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
<same code as above>


class MyViewerComparator extends ViewerComparator{
Comparator<T> cmp;
boolean desc = true;
MyViewerComparator(Comparator<T> cmp){
this.cmp = cmp;
int getDirection(){
return desc?SWT.UP:SWT.DOWN;

void flipDirection(){
desc = !desc;

public int compare(Viewer viewer, Object e1, Object e2) {

if(e1 == null || e2==null){
return 0;
int rc =, (T)e2);
return -rc;
return rc;
When the table loads the data for the 1st time, it goes inside the Bolded condition in the above code as one of the object is ALWAYS NULL

Note: This functionality works totally fine if I use a Standard table rather than VIRTUAL TABLE. I am not sure whether I can change it to use Standard table as we want the lazy load functionality as well..

ContentProvider used is: ObservableListContentProvider

Could you please advise on this issue and provide a solution for the same?

Thanks in Advance
Previous Topic:Cell vertical block selection in Table/Tree Viewer
Next Topic:[Databinding] Is this a good Master-Details-Binding pattern for my use case?
Goto Forum:

Current Time: Thu May 24 17:51:21 GMT 2018

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

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

Back to the top