net.sourceforge.java.feednread.frontend.components.newstable
Class NewsFeedTableViewerSorter

java.lang.Object
  extended byorg.eclipse.jface.viewers.ViewerComparator
      extended byorg.eclipse.jface.viewers.ViewerSorter
          extended bynet.sourceforge.java.feednread.frontend.components.newstable.NewsFeedTableViewerSorter

public class NewsFeedTableViewerSorter
extends ViewerSorter

Sorts NewsFeedEntries embedded in a JFace TableViewer upon an arbitrary TableColumn criterion.

Author:
Sebastian Machhausen

Field Summary
private  boolean ascending
           true indicates ascending (default), false descending sort order
private  NewsFeedTableContentProvider contentProvider
           The content provider to query the underlying model
private  int sortingColumn
           The column that the sorting is done by
private  TableViewer viewer
           The TableViewer 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
NewsFeedTableViewerSorter(TableViewer viewer)
           Creates a new NewsFeedTableViewerSorte instance linked to the specified TableViewer.
 
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 should 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 TableViewer viewer

The TableViewer that the sorting is done for


contentProvider

private NewsFeedTableContentProvider contentProvider

The content provider to query the underlying model

Constructor Detail

NewsFeedTableViewerSorter

public NewsFeedTableViewerSorter(TableViewer viewer)

Creates a new NewsFeedTableViewerSorte instance linked to the specified TableViewer.

Parameters:
viewer - the viewer to link this NewsFeedTableViewerSorte 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

setSortingColumn

public void setSortingColumn(int columnIndex)

Sets the column index by which the sorting should be done.

Parameters:
columnIndex - the column index by which the sorting should be done

isAscending

public boolean isAscending()

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

Returns:
true for ascending, false for descending sort order.

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.

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.

The default implementation of this method is based on comparing the elements' categories as computed by the category framework method. Elements within the same category are further subjected to a case insensitive compare of their label strings, either as computed by the content viewer's label provider, or their toString values in other cases. Subclasses may override.

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