public abstract class DefaultSortController<M> extends DefaultRowSorter<M,Integer> implements SortController<M>
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.
Modifier and Type | Class and Description |
---|---|
private static class |
DefaultSortController.ComparableComparator |
DefaultRowSorter.ModelWrapper<M,I>
RowSorter.SortKey
Modifier and Type | Field and Description |
---|---|
protected int |
cachedModelRowCount |
static Comparator |
COMPARABLE_COMPARATOR
Comparator that uses compareTo on the contents.
|
private static SortOrder[] |
DEFAULT_CYCLE |
private static StringValueProvider |
DEFAULT_PROVIDER |
private boolean |
sortable |
private List<SortOrder> |
sortCycle |
private StringValueProvider |
stringValueProvider |
Constructor and Description |
---|
DefaultSortController() |
Modifier and Type | Method and Description |
---|---|
void |
allRowsChanged() |
private void |
checkColumn(int column) |
int |
convertRowIndexToModel(int viewIndex)
Overridden to use check against
getViewRowCount for validity. |
int |
convertRowIndexToView(int modelIndex)
Overridden to use check against
getModelRowCount for validity. |
static SortOrder[] |
getDefaultSortOrderCycle()
Returns the default cycle.
|
private SortOrder |
getFirstInCycle()
Returns the first SortOrder in the sort order cycle, or null if empty.
|
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).
|
private SortOrder |
getNextInCycle(SortOrder current)
Returns the next SortOrder relative to the current, or null
if the sort order cycle is empty.
|
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.
|
int |
getViewRowCount()
Overridden to return the model row count if no filters installed, otherwise
return super.
|
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,
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 of the specified column.
|
getComparator, getMaxSortKeys, getModel, getModelWrapper, getRowFilter, getSortKeys, getSortsOnUpdates, rowsUpdated, rowsUpdated, setComparator, setMaxSortKeys, setModelWrapper, setRowFilter, setSortKeys, setSortsOnUpdates, sort, useToString
addRowSorterListener, fireRowSorterChanged, fireSortOrderChanged, removeRowSorterListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getComparator, getRowFilter, getSortsOnUpdates, setComparator, setRowFilter, setSortsOnUpdates
public static final Comparator COMPARABLE_COMPARATOR
private static final SortOrder[] DEFAULT_CYCLE
private boolean sortable
private StringValueProvider stringValueProvider
protected int cachedModelRowCount
private static final StringValueProvider DEFAULT_PROVIDER
public DefaultSortController()
public void setSortable(boolean sortable)
The default is true.
PENDING JW: define behaviour if sortable is disabled while has sortOrders. In this case JXTable resets all sorts.
setSortable
in interface SortController<M>
sortable
- whether or not this controller is sortableSortController.isSortable()
public boolean isSortable()
isSortable
in interface SortController<M>
SortController.isSortable()
public void setSortable(int column, boolean 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.
setSortable
in interface SortController<M>
setSortable
in class DefaultRowSorter<M,Integer>
column
- the column to enable or disable sorting on, in terms
of the underlying modelsortable
- whether or not the specified column is sortableSortController.isSortable(int)
,
SortController.toggleSortOrder(int)
,
SortController.setSortOrder(int, SortOrder)
public boolean isSortable(int column)
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.
isSortable
in interface SortController<M>
isSortable
in class DefaultRowSorter<M,Integer>
column
- the column to check sorting for, in terms of the
underlying modelSortController.isSortable(int)
public void toggleSortOrder(int column)
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.
toggleSortOrder
in interface SortController<M>
toggleSortOrder
in class DefaultRowSorter<M,Integer>
column
- the model index of the column to toggleSortController.isSortable(int)
,
SortController.isSortable()
private SortOrder getNextInCycle(SortOrder current)
current
- the current SortOrderprivate SortOrder getFirstInCycle()
private void checkColumn(int column)
public void setSortOrder(int column, SortOrder sortOrder)
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?
setSortOrder
in interface SortController<M>
column
- the model index of the column to setsortOrder
- the SortOrder to set for the columnSortController.isSortable(int)
,
SortController.isSortable()
public SortOrder getSortOrder(int column)
getSortOrder
in interface SortController<M>
SortOrder.ASCENDING
,
SortOrder.DESCENDING
or SortOrder.UNSORTED
.public void resetSortOrders()
Implementations must respect the per-controller and per-column-sortable property.
resetSortOrders
in interface SortController<M>
public SortOrder[] getSortOrderCycle()
getSortOrderCycle
in interface SortController<M>
public void setSortOrderCycle(SortOrder... cycle)
setSortOrderCycle
in interface SortController<M>
cycle
- the SortOrders to cycle through, may be emptypublic void setStringValueProvider(StringValueProvider registry)
setStringValueProvider
in interface SortController<M>
registry
- the registry to get StringValues for conversion.public StringValueProvider getStringValueProvider()
getStringValueProvider
in interface SortController<M>
public static SortOrder[] getDefaultSortOrderCycle()
public int convertRowIndexToModel(int viewIndex)
Overridden to use check against getViewRowCount
for validity.
convertRowIndexToModel
in class DefaultRowSorter<M,Integer>
getViewRowCount()
public int convertRowIndexToView(int modelIndex)
Overridden to use check against getModelRowCount
for validity.
convertRowIndexToView
in class DefaultRowSorter<M,Integer>
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.
getModelRowCount
in class DefaultRowSorter<M,Integer>
public int getViewRowCount()
Overridden to return the model row count if no filters installed, otherwise return super.
getViewRowCount
in class DefaultRowSorter<M,Integer>
getModelRowCount()
private boolean hasRowFilter()
public void allRowsChanged()
allRowsChanged
in class DefaultRowSorter<M,Integer>
public void modelStructureChanged()
modelStructureChanged
in class DefaultRowSorter<M,Integer>
public void rowsDeleted(int firstRow, int endRow)
rowsDeleted
in class DefaultRowSorter<M,Integer>
public void rowsInserted(int firstRow, int endRow)
rowsInserted
in class DefaultRowSorter<M,Integer>
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses