Class DefaultSortController<M>
- All Implemented Interfaces:
SortController<M>
- Direct Known Subclasses:
ListSortController, TableSortController
Additionally, this implementation contains a fix for core invalid input: '<'a href=http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6894632>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 ClassesNested classes/interfaces inherited from class DefaultRowSorter
DefaultRowSorter.ModelWrapper<M,I> Nested classes/interfaces inherited from class RowSorter
RowSorter.SortKey -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intstatic final ComparatorComparator that uses compareTo on the contents.private static final SortOrder[]private static final StringValueProviderprivate booleanprivate StringValueProvider -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate voidcheckColumn(int column) intconvertRowIndexToModel(int viewIndex) intconvertRowIndexToView(int modelIndex) static SortOrder[]Returns the default cycle.private SortOrderReturns the first SortOrder in the sort order cycle, or null if empty.intprivate SortOrdergetNextInCycle(SortOrder current) Returns the next SortOrder relative to the current, or null if the sort order cycle is empty.getSortOrder(int column) Returns the sort order of the specified column.Returns the cycle of sort orders to cycle through.Returns the registry of string values.intprivate booleanbooleanReturns true if this controller is sortable; otherwise, false.booleanisSortable(int column) Returns true if the specified column is sortable.voidvoidResets all interactive sorting.voidrowsDeleted(int firstRow, int endRow) voidrowsInserted(int firstRow, int endRow) voidsetSortable(boolean sortable) Sets whether or not this controller is sortable.voidsetSortable(int column, boolean sortable) Sets whether or not the specified column is sortable.voidsetSortOrder(int column, SortOrder sortOrder) Sets the sort order of the specified column.voidsetSortOrderCycle(SortOrder... cycle) Sets the cycle of sort ordes to toggle through.voidsetStringValueProvider(StringValueProvider registry) Sets the registry of string values.voidtoggleSortOrder(int column) Reverses the sort order of the specified column.Methods inherited from class DefaultRowSorter
getComparator, getMaxSortKeys, getModel, getModelWrapper, getRowFilter, getSortKeys, getSortsOnUpdates, rowsUpdated, rowsUpdated, setComparator, setMaxSortKeys, setModelWrapper, setRowFilter, setSortKeys, setSortsOnUpdates, sort, useToStringMethods inherited from class RowSorter
addRowSorterListener, fireRowSorterChanged, fireSortOrderChanged, removeRowSorterListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SortController
getComparator, getRowFilter, getSortsOnUpdates, setComparator, setRowFilter, setSortsOnUpdates
-
Field Details
-
COMPARABLE_COMPARATOR
Comparator that uses compareTo on the contents. -
DEFAULT_CYCLE
-
sortCycle
-
sortable
private boolean sortable -
stringValueProvider
-
cachedModelRowCount
protected int cachedModelRowCount -
DEFAULT_PROVIDER
-
-
Constructor Details
-
DefaultSortController
public DefaultSortController()
-
-
Method Details
-
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:
setSortablein interfaceSortController<M>- Parameters:
sortable- whether or not this controller is sortable- See Also:
-
isSortable
public boolean isSortable()Returns true if this controller is sortable; otherwise, false.- Specified by:
isSortablein interfaceSortController<M>- Returns:
- true if this controller is sortable
- See Also:
-
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:
setSortablein interfaceSortController<M>- Overrides:
setSortablein classDefaultRowSorter<M,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:
-
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:
isSortablein interfaceSortController<M>- Overrides:
isSortablein classDefaultRowSorter<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:
-
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:
toggleSortOrderin interfaceSortController<M>- Overrides:
toggleSortOrderin classDefaultRowSorter<M,Integer> - Parameters:
column- the model index of the column to toggle- See Also:
-
getNextInCycle
-
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
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:
setSortOrderin interfaceSortController<M>- Parameters:
column- the model index of the column to setsortOrder- the SortOrder to set for the column- See Also:
-
getSortOrder
Returns the sort order of the specified column.- Specified by:
getSortOrderin interfaceSortController<M>- Returns:
- one of
SortOrder.ASCENDING,SortOrder.DESCENDINGorSortOrder.UNSORTED.
-
resetSortOrders
public void resetSortOrders()Resets all interactive sorting.Implementations must respect the per-controller and per-column-sortable property.
- Specified by:
resetSortOrdersin interfaceSortController<M>
-
getSortOrderCycle
Returns the cycle of sort orders to cycle through.- Specified by:
getSortOrderCyclein interfaceSortController<M>- Returns:
-
setSortOrderCycle
Sets the cycle of sort ordes to toggle through. Zero or more SortOrders which must not be null.- Specified by:
setSortOrderCyclein interfaceSortController<M>- Parameters:
cycle- the SortOrders to cycle through, may be empty
-
setStringValueProvider
Sets the registry of string values. If null, the default provider is used.- Specified by:
setStringValueProviderin interfaceSortController<M>- Parameters:
registry- the registry to get StringValues for conversion.
-
getStringValueProvider
Returns the registry of string values.- Specified by:
getStringValueProviderin interfaceSortController<M>- Returns:
- the registry of string converters, guaranteed to never be null.
-
getDefaultSortOrderCycle
Returns the default cycle.- Returns:
- default sort order cycle.
-
convertRowIndexToModel
public int convertRowIndexToModel(int viewIndex) Overridden to use check against
getViewRowCountfor validity.- Overrides:
convertRowIndexToModelin classDefaultRowSorter<M,Integer> - See Also:
-
convertRowIndexToView
public int convertRowIndexToView(int modelIndex) Overridden to use check against
getModelRowCountfor validity.- Overrides:
convertRowIndexToViewin classDefaultRowSorter<M,Integer> - See Also:
-
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:
getModelRowCountin classDefaultRowSorter<M,Integer>
-
getViewRowCount
public int getViewRowCount()Overridden to return the model row count if no filters installed, otherwise return super.
- Overrides:
getViewRowCountin classDefaultRowSorter<M,Integer> - See Also:
-
hasRowFilter
private boolean hasRowFilter()- Returns:
-
allRowsChanged
public void allRowsChanged()- Overrides:
allRowsChangedin classDefaultRowSorter<M,Integer>
-
modelStructureChanged
public void modelStructureChanged()- Overrides:
modelStructureChangedin classDefaultRowSorter<M,Integer>
-
rowsDeleted
public void rowsDeleted(int firstRow, int endRow) - Overrides:
rowsDeletedin classDefaultRowSorter<M,Integer>
-
rowsInserted
public void rowsInserted(int firstRow, int endRow) - Overrides:
rowsInsertedin classDefaultRowSorter<M,Integer>
-