net.sourceforge.java.util.gui.jface.viewers
Class TableViewerSorter

java.lang.Object
  extended byorg.eclipse.jface.viewers.ViewerComparator
      extended byorg.eclipse.jface.viewers.ViewerSorter
          extended bynet.sourceforge.java.util.gui.jface.viewers.TableViewerSorter
Direct Known Subclasses:
TableTreeViewerSorter

public class TableViewerSorter
extends ViewerSorter

Generic ViewerSorter extension for Viewer instances using ITableContentProvider implementations.

Author:
Sebastian Machhausen

Field Summary
private  boolean ascending
           true indicates ascending (default), false descending sort order
private  ITableContentProvider contentProvider
           The ITableContentProvider used to query the underlying model
private  int sortingColumn
           The column that the sorting is done by
private  Viewer viewer
           The Viewer that the sorting is done for
 
Fields inherited from class org.eclipse.jface.viewers.ViewerSorter
collator
 
Fields inherited from class org.eclipse.jface.viewers.ViewerComparator
 
Constructor Summary
TableViewerSorter(Viewer viewer, ITableContentProvider contentProvider)
           Creates a new TableViewerSorter instance linked to the specified Viewer.
 
Method Summary
 int compare(Viewer viewer, Object e1, Object e2)
           Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.
 int getSortingColumn()
           Gets the column index by which the sorting is done.
 boolean isAscending()
           Gets the sort order; true indicates ascending, false descending sort order.
 void setAscending(boolean ascending)
           Sets the sort order to be used; true indicates ascending, false descending sort order.
 void setSortingColumn(int columnIndex)
           Sets the column index by which the sorting is to be done.
 void sort()
           Sorts the underlying model data and refreshes the associated TableViewer to reflect the new sorting.
 
Methods inherited from class org.eclipse.jface.viewers.ViewerSorter
getCollator, getComparator
 
Methods inherited from class org.eclipse.jface.viewers.ViewerComparator
category, isSorterProperty, sort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sortingColumn

private int sortingColumn

The column that the sorting is done by


ascending

private boolean ascending

true indicates ascending (default), false descending sort order


viewer

private Viewer viewer

The Viewer that the sorting is done for


contentProvider

private ITableContentProvider contentProvider

The ITableContentProvider used to query the underlying model

Constructor Detail

TableViewerSorter

public TableViewerSorter(Viewer viewer,
                         ITableContentProvider contentProvider)

Creates a new TableViewerSorter instance linked to the specified Viewer.

Parameters:
viewer - the Viewer to link this TableViewerSorter to
Method Detail

getSortingColumn

public int getSortingColumn()

Gets the column index by which the sorting is done.

Returns:
the column index by which the sorting is done
See Also:
getSortingColumn()

setSortingColumn

public void setSortingColumn(int columnIndex)

Sets the column index by which the sorting is to be done.

Parameters:
columnIndex - the column index by which the sorting is to be done
See Also:
getSortingColumn()

isAscending

public boolean isAscending()

Gets the sort order; true indicates ascending, false descending sort order.

Returns:
true for ascending, false for descending sort order
See Also:
setAscending(boolean)

setAscending

public void setAscending(boolean ascending)

Sets the sort order to be used; true indicates ascending, false descending sort order.

Parameters:
ascending - true for ascending, false for descending sort order
See Also:
isAscending()

sort

public void sort()

Sorts the underlying model data and refreshes the associated TableViewer to reflect the new sorting.


compare

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

Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.

Parameters:
viewer - the viewer
e1 - the first element
e2 - the second element
Returns:
a negative number if the first element is less than the second element; the value 0 if the first element is equal to the second element; and a positive number if the first element is greater than the second element