org.jdesktop.swingx.sort
Class DefaultSortController<M>

java.lang.Object
  extended by javax.swing.RowSorter<M>
      extended by javax.swing.DefaultRowSorter<M,Integer>
          extended by org.jdesktop.swingx.sort.DefaultSortController<M>
All Implemented Interfaces:
SortController<M>
Direct Known Subclasses:
ListSortController, TableSortController

public abstract class DefaultSortController<M>
extends DefaultRowSorter<M,Integer>
implements SortController<M>

A SortController to use for a JXTable.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.DefaultRowSorter
DefaultRowSorter.ModelWrapper<M,I>
 
Nested classes/interfaces inherited from class javax.swing.RowSorter
RowSorter.SortKey
 
Field Summary
static Comparator COMPARABLE_COMPARATOR
          Comparator that uses compareTo on the contents.
 
Constructor Summary
DefaultSortController()
           
 
Method Summary
static SortOrder[] getDefaultSortOrderCycle()
          Returns the default cycle.
 SortOrder getSortOrder(int column)
          Returns the sort order of the specified column.
 SortOrder[] getSortOrderCycle()
          Returns the cycle of sort orders to cycle through.
 StringValueProvider getStringValueProvider()
          Returns the registry of string values.
 boolean isSortable()
          Returns true if this controller is sortable; otherwise, false.
 boolean isSortable(int column)
          Returns true if the specified column is sortable; otherwise, false.
 void resetSortOrders()
          Resets all interactive sorting.
 void setSortable(boolean sortable)
          Sets whether or not this controller is sortable.
 void setSortable(int column, boolean sortable)
          Sets whether or not the specified column is sortable.
 void setSortOrder(int column, SortOrder sortOrder)
          Sets the sort order of the specified column.
 void setSortOrderCycle(SortOrder... cycle)
          Sets the cycle of sort ordes to toggle through.
 void setStringValueProvider(StringValueProvider registry)
          Sets the registry of string values.
 void toggleSortOrder(int column)
          Reverses the sort order from ascending to descending (or descending to ascending) if the specified column is already the primary sorted column; otherwise, makes the specified column the primary sorted column, with an ascending sort order.
 
Methods inherited from class javax.swing.DefaultRowSorter
allRowsChanged, convertRowIndexToModel, convertRowIndexToView, getComparator, getMaxSortKeys, getModel, getModelRowCount, getModelWrapper, getRowFilter, getSortKeys, getSortsOnUpdates, getViewRowCount, modelStructureChanged, rowsDeleted, rowsInserted, rowsUpdated, rowsUpdated, setComparator, setMaxSortKeys, setModelWrapper, setRowFilter, setSortKeys, setSortsOnUpdates, sort, useToString
 
Methods inherited from class javax.swing.RowSorter
addRowSorterListener, fireRowSorterChanged, fireSortOrderChanged, removeRowSorterListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jdesktop.swingx.sort.SortController
getComparator, getRowFilter, getSortsOnUpdates, setComparator, setRowFilter, setSortsOnUpdates
 

Field Detail

COMPARABLE_COMPARATOR

public static final Comparator COMPARABLE_COMPARATOR
Comparator that uses compareTo on the contents.

Constructor Detail

DefaultSortController

public DefaultSortController()
Method Detail

setSortable

public void setSortable(boolean sortable)
Sets whether or not this controller is sortable.

The default is true.

PENDING JW: define behaviour if sortable is disabled while has sortOrders. In this case JXTable resets all sorts.

Specified by:
setSortable in interface SortController<M>
Parameters:
sortable - whether or not this controller is sortable
See Also:
SortController.isSortable()

isSortable

public boolean isSortable()
Returns true if this controller is sortable; otherwise, false.

Specified by:
isSortable in interface SortController<M>
Returns:
true if this controller is sortable
See Also:
SortController.isSortable()

setSortable

public void setSortable(int column,
                        boolean sortable)
Sets whether or not the specified column is sortable. The specified value is only checked when toggleSortOrder is invoked. It is still possible to sort on a column that has been marked as unsortable by directly setting the sort keys. The default is true.

Specified by:
setSortable in interface SortController<M>
Overrides:
setSortable in class DefaultRowSorter<M,Integer>
Parameters:
column - the column to enable or disable sorting on, in terms of the underlying model
sortable - whether or not the specified column is sortable
See Also:
DefaultRowSorter.toggleSortOrder(int), DefaultRowSorter.setSortKeys(java.util.List)

isSortable

public boolean isSortable(int column)
Returns true if the specified column is sortable; otherwise, false.

Specified by:
isSortable in interface SortController<M>
Overrides:
isSortable in class DefaultRowSorter<M,Integer>
Parameters:
column - the column to check sorting for, in terms of the underlying model
Returns:
true if the column is sortable
See Also:
SortController.isSortable(int)

toggleSortOrder

public void toggleSortOrder(int column)
Reverses the sort order from ascending to descending (or descending to ascending) if the specified column is already the primary sorted column; otherwise, makes the specified column the primary sorted column, with an ascending sort order. If the specified column is not sortable, this method has no effect.

Overridden - that is completely new implementation - to get first/next SortOrder from sort order cycle. Does nothing if the cycle is empty.

Specified by:
toggleSortOrder in interface SortController<M>
Overrides:
toggleSortOrder in class DefaultRowSorter<M,Integer>
Parameters:
column - index of the column to make the primary sorted column, in terms of the underlying model
See Also:
DefaultRowSorter.setSortable(int,boolean), DefaultRowSorter.setMaxSortKeys(int)

setSortOrder

public void setSortOrder(int column,
                         SortOrder sortOrder)
Sets the sort order of the specified column.

Implementations must respect the per-controller and per-column-sortable property.

PENDING JW: toggle has two effects: makes the column the primary sort column, and cycle through. So here we something similar. Should we?

Specified by:
setSortOrder in interface SortController<M>
Parameters:
column - the model index of the column to set
sortOrder - the SortOrder to set for the column
See Also:
SortController.isSortable(int), SortController.isSortable()

getSortOrder

public SortOrder getSortOrder(int column)
Returns the sort order of the specified column.

Specified by:
getSortOrder in interface SortController<M>
Returns:
one of SortOrder.ASCENDING, SortOrder.DESCENDING or SortOrder.UNSORTED.

resetSortOrders

public void resetSortOrders()
Resets all interactive sorting.

Implementations must respect the per-controller and per-column-sortable property.

Specified by:
resetSortOrders in interface SortController<M>

getSortOrderCycle

public SortOrder[] getSortOrderCycle()
Returns the cycle of sort orders to cycle through.

Specified by:
getSortOrderCycle in interface SortController<M>
Returns:

setSortOrderCycle

public void setSortOrderCycle(SortOrder... cycle)
Sets the cycle of sort ordes to toggle through. Zero or more SortOrders which must not be null.

Specified by:
setSortOrderCycle in interface SortController<M>
Parameters:
cycle - the SortOrders to cycle through, may be empty

setStringValueProvider

public void setStringValueProvider(StringValueProvider registry)
Sets the registry of string values. If null, the default provider is used.

Specified by:
setStringValueProvider in interface SortController<M>
Parameters:
registry - the registry to get StringValues for conversion.

getStringValueProvider

public StringValueProvider getStringValueProvider()
Returns the registry of string values.

Specified by:
getStringValueProvider in interface SortController<M>
Returns:
the registry of string converters, guaranteed to never be null.

getDefaultSortOrderCycle

public static SortOrder[] getDefaultSortOrderCycle()
Returns the default cycle.

Returns:
default sort order cycle.