Package org.jdesktop.swingx.decorator
Interface SortController
-
- All Known Implementing Classes:
FilterPipeline.SorterBasedSortController
public interface SortController
Defines the interactive sort control for a table. All sort gesture requests from aJXTable
will be routed through the SortController returned fromFilterPipeline
.To customize sorting behaviour, f.i. to define a toggle sort sequence different from the default, subclass
FilterPipeline
and implement a custom SortController.public class CustomToggleSortOrderFP extends FilterPipeline { public CustomToggleSortOrderFP() { super(); } public CustomToggleSortOrderFP(Filter[] inList) { super(inList); } //@Override protected SortController createDefaultSortController() { return new CustomSortController(); } protected class CustomSortController extends SorterBasedSortController { //@Override public void toggleSortOrder(int column, Comparator comparator) { Sorter currentSorter = getSorter(); if ((currentSorter != null) && (currentSorter.getColumnIndex() == column) && !currentSorter.isAscending()) { setSorter(null); } else { super.toggleSortOrder(column, comparator); } } } } // use it xTable.setFilters(new CustomToggleSortOrderFP());
The GlazedLists project (http://publicobject.com/glazedlists/) has an example about how to replace the SwingX' internal (view based) by an external (model-decoration based) sort/filter mechanism.
This interface is inspired by a Java 1.6 class RowSorter, extracting the sort control part - change notification and index mapping is left to the enclosing FilterPipeline.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.List<? extends SortKey>
getSortKeys()
List the sort order by column.SortOrder
getSortOrder(int column)
Get the sort order of the specified column.void
setSortKeys(java.util.List<? extends SortKey> keys)
Set the sort order by column.void
toggleSortOrder(int column)
Reverses the sort order of the specified column.void
toggleSortOrder(int column, java.util.Comparator comparator)
Reverses the sort order of the specified column.
-
-
-
Method Detail
-
toggleSortOrder
void toggleSortOrder(int column)
Reverses the sort order of the specified column. It is up to implementating classes to provide the exact behavior when invoked.- Parameters:
column
- the model index of the column to toggle
-
toggleSortOrder
void toggleSortOrder(int column, java.util.Comparator comparator)
Reverses the sort order of the specified column. It is up to implementating classes to provide the exact behavior when invoked.- Parameters:
column
- the model index of the column to togglecomparator
- the comparator to use
-
setSortKeys
void setSortKeys(java.util.List<? extends SortKey> keys)
Set the sort order by column.
-
getSortKeys
java.util.List<? extends SortKey> getSortKeys()
List the sort order by column.
-
getSortOrder
SortOrder getSortOrder(int column)
Get the sort order of the specified column. PENDING (JW) - remove? Looks like an "intermediate" convenience method. Not used in SwingX, only in test methods.- Returns:
- one of
SortOrder.ASCENDING
,SortOrder.DESCENDING
orSortOrder.UNSORTED
.
-
-