org.mailster.gui.prefs.widgets
Class TableViewerSorter

java.lang.Object
  extended by org.eclipse.jface.viewers.ViewerComparator
      extended by org.eclipse.jface.viewers.ViewerSorter
          extended by org.mailster.gui.prefs.widgets.TableViewerSorter

public class TableViewerSorter
extends org.eclipse.jface.viewers.ViewerSorter

Generic ViewerSorter extension for Viewer instances using ITableContentProvider implementations.

Author:
Sebastian Machhausen, Edouard De Oliveira

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  org.eclipse.jface.viewers.Viewer viewer
          The Viewer that the sorting is done for
 
Fields inherited from class org.eclipse.jface.viewers.ViewerSorter
collator
 
Constructor Summary
TableViewerSorter(org.eclipse.jface.viewers.Viewer viewer, ITableContentProvider contentProvider)
          Creates a new TableViewerSorter instance linked to the specified Viewer.
 
Method Summary
 int compare(org.eclipse.jface.viewers.Viewer viewer, java.lang.Object e1, java.lang.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
 
Methods inherited from class org.eclipse.jface.viewers.ViewerComparator
category, getComparator, 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 org.eclipse.jface.viewers.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(org.eclipse.jface.viewers.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(org.eclipse.jface.viewers.Viewer viewer,
                   java.lang.Object e1,
                   java.lang.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.

Overrides:
compare in class org.eclipse.jface.viewers.ViewerComparator
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