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 a JXTable will be routed through the SortController returned from FilterPipeline.

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
 List<? extends SortKey> getSortKeys()
          List the sort order by column.
 SortOrder getSortOrder(int column)
          Get the sort order of the specified column.
 void setSortKeys(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, 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,
                     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 toggle
comparator - the comparator to use

setSortKeys

void setSortKeys(List<? extends SortKey> keys)
Set the sort order by column.


getSortKeys

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 or SortOrder.UNSORTED.