Class DefaultSortController<M>
- java.lang.Object
-
- javax.swing.RowSorter<M>
-
- javax.swing.DefaultRowSorter<M,java.lang.Integer>
-
- org.jdesktop.swingx.sort.DefaultSortController<M>
-
- All Implemented Interfaces:
SortController<M>
- Direct Known Subclasses:
ListSortController
,TableSortController
public abstract class DefaultSortController<M> extends javax.swing.DefaultRowSorter<M,java.lang.Integer> implements SortController<M>
A default SortController implementation used as parent class for concrete SortControllers in SwingX.Additionally, this implementation contains a fix for core Issue 6894632. It guarantees to only touch the underlying model during sort/filter and during processing the notification methods. This implies that the conversion and size query methods are valid at all times outside the internal updates, including the critical period (in core with undefined behaviour) after the underlying model has changed and before this sorter has been notified.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DefaultSortController.ComparableComparator
-
Field Summary
Fields Modifier and Type Field Description protected int
cachedModelRowCount
static java.util.Comparator
COMPARABLE_COMPARATOR
Comparator that uses compareTo on the contents.private static javax.swing.SortOrder[]
DEFAULT_CYCLE
private static StringValueProvider
DEFAULT_PROVIDER
private boolean
sortable
private java.util.List<javax.swing.SortOrder>
sortCycle
private StringValueProvider
stringValueProvider
-
Constructor Summary
Constructors Constructor Description DefaultSortController()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
allRowsChanged()
private void
checkColumn(int column)
int
convertRowIndexToModel(int viewIndex)
int
convertRowIndexToView(int modelIndex)
static javax.swing.SortOrder[]
getDefaultSortOrderCycle()
Returns the default cycle.private javax.swing.SortOrder
getFirstInCycle()
Returns the first SortOrder in the sort order cycle, or null if empty.int
getModelRowCount()
private javax.swing.SortOrder
getNextInCycle(javax.swing.SortOrder current)
Returns the next SortOrder relative to the current, or null if the sort order cycle is empty.javax.swing.SortOrder
getSortOrder(int column)
Returns the sort order of the specified column.javax.swing.SortOrder[]
getSortOrderCycle()
Returns the cycle of sort orders to cycle through.StringValueProvider
getStringValueProvider()
Returns the registry of string values.int
getViewRowCount()
private boolean
hasRowFilter()
boolean
isSortable()
Returns true if this controller is sortable; otherwise, false.boolean
isSortable(int column)
Returns true if the specified column is sortable.void
modelStructureChanged()
void
resetSortOrders()
Resets all interactive sorting.void
rowsDeleted(int firstRow, int endRow)
void
rowsInserted(int firstRow, int endRow)
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, javax.swing.SortOrder sortOrder)
Sets the sort order of the specified column.void
setSortOrderCycle(javax.swing.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 of the specified column.-
Methods inherited from class javax.swing.DefaultRowSorter
getComparator, getMaxSortKeys, getModel, getModelWrapper, getRowFilter, getSortKeys, getSortsOnUpdates, 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 java.util.Comparator COMPARABLE_COMPARATOR
Comparator that uses compareTo on the contents.
-
DEFAULT_CYCLE
private static final javax.swing.SortOrder[] DEFAULT_CYCLE
-
sortCycle
private java.util.List<javax.swing.SortOrder> sortCycle
-
sortable
private boolean sortable
-
stringValueProvider
private StringValueProvider stringValueProvider
-
cachedModelRowCount
protected int cachedModelRowCount
-
DEFAULT_PROVIDER
private static final StringValueProvider DEFAULT_PROVIDER
-
-
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 interfaceSortController<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 interfaceSortController<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 default is true.
PENDING JW: define behaviour if sortable is disabled while has sortOrders. In this case JXTable removes the sort of the column.
PENDING JW: decide whether or not this method should trigger a resort DefaultRowSorter explicitly doesn't, JXTable does.
- Specified by:
setSortable
in interfaceSortController<M>
- Overrides:
setSortable
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
- Parameters:
column
- the column to enable or disable sorting on, in terms of the underlying modelsortable
- whether or not the specified column is sortable- See Also:
SortController.isSortable(int)
,SortController.toggleSortOrder(int)
,SortController.setSortOrder(int, SortOrder)
-
isSortable
public boolean isSortable(int column)
Returns true if the specified column is sortable.This returns true if both the controller's sortable property and the column's sortable property is true. Returns false if any of them is false.
- Specified by:
isSortable
in interfaceSortController<M>
- Overrides:
isSortable
in classjavax.swing.DefaultRowSorter<M,java.lang.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 of the specified column. The exact behaviour is up to implementations.Implementations must respect the per-controller and per-column-sortable property.
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 interfaceSortController<M>
- Overrides:
toggleSortOrder
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
- Parameters:
column
- the model index of the column to toggle- See Also:
SortController.isSortable(int)
,SortController.isSortable()
-
getNextInCycle
private javax.swing.SortOrder getNextInCycle(javax.swing.SortOrder current)
Returns the next SortOrder relative to the current, or null if the sort order cycle is empty.- Parameters:
current
- the current SortOrder- Returns:
- the next SortOrder to use, may be null if the cycle is empty.
-
getFirstInCycle
private javax.swing.SortOrder getFirstInCycle()
Returns the first SortOrder in the sort order cycle, or null if empty.- Returns:
- the first SortOrder in the sort order cycle or null if empty.
-
checkColumn
private void checkColumn(int column)
-
setSortOrder
public void setSortOrder(int column, javax.swing.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 interfaceSortController<M>
- Parameters:
column
- the model index of the column to setsortOrder
- the SortOrder to set for the column- See Also:
SortController.isSortable(int)
,SortController.isSortable()
-
getSortOrder
public javax.swing.SortOrder getSortOrder(int column)
Returns the sort order of the specified column.- Specified by:
getSortOrder
in interfaceSortController<M>
- Returns:
- one of
SortOrder.ASCENDING
,SortOrder.DESCENDING
orSortOrder.UNSORTED
.
-
resetSortOrders
public void resetSortOrders()
Resets all interactive sorting.Implementations must respect the per-controller and per-column-sortable property.
- Specified by:
resetSortOrders
in interfaceSortController<M>
-
getSortOrderCycle
public javax.swing.SortOrder[] getSortOrderCycle()
Returns the cycle of sort orders to cycle through.- Specified by:
getSortOrderCycle
in interfaceSortController<M>
- Returns:
-
setSortOrderCycle
public void setSortOrderCycle(javax.swing.SortOrder... cycle)
Sets the cycle of sort ordes to toggle through. Zero or more SortOrders which must not be null.- Specified by:
setSortOrderCycle
in interfaceSortController<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 interfaceSortController<M>
- Parameters:
registry
- the registry to get StringValues for conversion.
-
getStringValueProvider
public StringValueProvider getStringValueProvider()
Returns the registry of string values.- Specified by:
getStringValueProvider
in interfaceSortController<M>
- Returns:
- the registry of string converters, guaranteed to never be null.
-
getDefaultSortOrderCycle
public static javax.swing.SortOrder[] getDefaultSortOrderCycle()
Returns the default cycle.- Returns:
- default sort order cycle.
-
convertRowIndexToModel
public int convertRowIndexToModel(int viewIndex)
Overridden to use check against
getViewRowCount
for validity.- Overrides:
convertRowIndexToModel
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
- See Also:
getViewRowCount()
-
convertRowIndexToView
public int convertRowIndexToView(int modelIndex)
Overridden to use check against
getModelRowCount
for validity.- Overrides:
convertRowIndexToView
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
- See Also:
getModelRowCount()
-
getModelRowCount
public int getModelRowCount()
Overridden to return the model row count which corresponds to the currently mapped model instead of accessing the model directly (as super does). This may differ from the "real" current model row count if the model has changed but this sorter not yet notified.
- Overrides:
getModelRowCount
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
-
getViewRowCount
public int getViewRowCount()
Overridden to return the model row count if no filters installed, otherwise return super.
- Overrides:
getViewRowCount
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
- See Also:
getModelRowCount()
-
hasRowFilter
private boolean hasRowFilter()
- Returns:
-
allRowsChanged
public void allRowsChanged()
- Overrides:
allRowsChanged
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
-
modelStructureChanged
public void modelStructureChanged()
- Overrides:
modelStructureChanged
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
-
rowsDeleted
public void rowsDeleted(int firstRow, int endRow)
- Overrides:
rowsDeleted
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
-
rowsInserted
public void rowsInserted(int firstRow, int endRow)
- Overrides:
rowsInserted
in classjavax.swing.DefaultRowSorter<M,java.lang.Integer>
-
-