public abstract class AbstractTableComparatorChooser<E>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.Object |
MULTIPLE_COLUMN_KEYBOARD
Emulate the sorting behaviour of SUN's TableSorter, by Philip Milne et.
|
static java.lang.Object |
MULTIPLE_COLUMN_MOUSE
Sort multiple columns without use of the keyboard.
|
static java.lang.Object |
MULTIPLE_COLUMN_MOUSE_WITH_UNDO
Sort multiple columns without use of the keyboard.
|
static java.lang.Object |
SINGLE_COLUMN
Emulate the sorting behaviour of Windows Explorer and Mac OS X Finder.
|
protected SortedList<E> |
sortedList
the sorted list to choose the comparators for
|
protected java.util.Comparator<? super E> |
sortedListComparator
the potentially foreign comparator associated with the sorted list
|
protected ca.odell.glazedlists.impl.gui.SortingState |
sortingState
manage which columns are sorted and in which order
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractTableComparatorChooser(SortedList<E> sortedList,
TableFormat<? super E> tableFormat)
Create a
AbstractTableComparatorChooser that sorts the specified
SortedList over the specified columns. |
Modifier and Type | Method and Description |
---|---|
void |
appendComparator(int column,
int comparatorIndex,
boolean reverse)
Append the comparator specified by the column, comparator index and reverse
parameters to the end of the sequence of comparators this
AbstractTableComparatorChooser is sorting the SortedList
by. |
void |
clearComparator()
Clear all sorting state and set the
SortedList to use its
natural order. |
java.util.Comparator |
createComparatorForElement(java.util.Comparator<E> comparatorForColumn,
int column)
Creates a
Comparator that can compare list elements
given a Comparator that can compare column values for the specified
column. |
protected ca.odell.glazedlists.impl.gui.SortingState |
createSortingState()
Returns the object which models the current sorting state of all columns
in the table.
|
void |
dispose() |
void |
fromString(java.lang.String stringEncoded)
This class is capable of representing its own state with a String, to
persist sorting state externally.
|
int |
getColumnComparatorIndex(int column)
Gets the index comparator in use for the specified column.
|
java.util.List<java.util.Comparator> |
getComparatorsForColumn(int column)
Gets the list of comparators for the specified column.
|
java.util.List<java.lang.Integer> |
getSortingColumns()
Get the columns that the TableComparatorChooser is sorting by.
|
protected int |
getSortingStyle(int column)
Gets the sorting style currently applied to the specified column.
|
boolean |
isColumnReverse(int column)
Gets whether the comparator in use for the specified column is reverse.
|
protected void |
rebuildComparator()
Updates the comparator in use and applies it to the table.
|
protected void |
redetectComparator(java.util.Comparator<? super E> currentComparator)
Examines the current
Comparator of the SortedList and
adds icons to the table header renderers in response. |
protected void |
setTableFormat(TableFormat<? super E> tableFormat)
Adjusts the TableFormat this comparator chooser uses when selecting
comparators.
|
java.lang.String |
toString()
Encode the current sorting state as a
String . |
public static final java.lang.Object SINGLE_COLUMN
Single clicks toggles between forward and reverse. If multiple comparators are available for a particular column, they will be cycled in order.
At most one column can be sorted at a time.
public static final java.lang.Object MULTIPLE_COLUMN_MOUSE
This is the original sorting strategy provided by Glazed Lists, with a limitation that it is impossible to clear a sort order that is already in place. It's designed to be used with multiple columns and multiple comparators per column.
The overall behaviour is as follows:
public static final java.lang.Object MULTIPLE_COLUMN_MOUSE_WITH_UNDO
This is an improvement over the original sorting strategy provided by Glazed Lists, since it gives a reasonable mechanism for clearing a sort order that is already in place. It's designed to be used with multiple columns and multiple comparators per column.
The overall behaviour is as follows:
public static final java.lang.Object MULTIPLE_COLUMN_KEYBOARD
This is not a direct adaptation since we choose to support potentially many Comparators per column, whereas TableSorter is limited to one.
For reference, this is TableSorter's behaviour, copied shamelessly from that project's source file:
protected SortedList<E> sortedList
protected java.util.Comparator<? super E> sortedListComparator
protected ca.odell.glazedlists.impl.gui.SortingState sortingState
protected AbstractTableComparatorChooser(SortedList<E> sortedList, TableFormat<? super E> tableFormat)
AbstractTableComparatorChooser
that sorts the specified
SortedList
over the specified columns.protected ca.odell.glazedlists.impl.gui.SortingState createSortingState()
protected void rebuildComparator()
protected void setTableFormat(TableFormat<? super E> tableFormat)
public java.util.List<java.util.Comparator> getComparatorsForColumn(int column)
public java.util.List<java.lang.Integer> getSortingColumns()
public int getColumnComparatorIndex(int column)
getComparatorsForColumn(int)
.public boolean isColumnReverse(int column)
public void appendComparator(int column, int comparatorIndex, boolean reverse)
AbstractTableComparatorChooser
is sorting the SortedList
by.
Append implies that if this AbstractTableComparatorChooser
is already sorting that list by another column, this comparator will only
be used to break ties from that Comparator
. If the table is already
sorting by the specified column, it will be silently discarded.
Suppose we're currently not sorting the table, this method will cause the table to be sorted by the column specified. If we are sorting the table by some column c, this will sort by that column first and the column specified here second.
If this AbstractTableComparatorChooser
doesn't support multiple
column sort, this will replace the current Comparator
rather than
appending to it.
column
- the column to sort bycomparatorIndex
- the comparator to use, specify 0
for the
default comparator.reverse
- whether to reverse the specified comparator.public void clearComparator()
SortedList
to use its
natural order.protected void redetectComparator(java.util.Comparator<? super E> currentComparator)
Comparator
of the SortedList and
adds icons to the table header renderers in response.
To do this, clicks are injected into each of the
corresponding ColumnClickTracker
s.
protected int getSortingStyle(int column)
public java.util.Comparator createComparatorForElement(java.util.Comparator<E> comparatorForColumn, int column)
Comparator
that can compare list elements
given a Comparator
that can compare column values for the specified
column. This returns a Comparator
that extracts the table values for
the specified column and then delegates the actual comparison to the specified
comparator.public java.lang.String toString()
String
. This specially formatted
String
is ideal for persistence using any preferences API. The
state of this AbstractTableComparatorChooser
can be restored
by passing the return value of this method to fromString(String)
.toString
in class java.lang.Object
public void fromString(java.lang.String stringEncoded)
This class is capable of representing its own state with a String, to persist sorting state externally. The format uses zero or more column specifications, separated by commas. Here are some valid examples:
String Representation | Description |
---|---|
"column 3" | Sort using the column at index 3, using that column's first comparator, in forward order |
"column 3 reversed" | Sort using the column at index 3, using that column's first comparator, in reverse order |
"column 3, column 1" | Sort using the column at index 3, using that column's first comparator, in forward order then by the column at index 1, using that column's first comparator, in forward order. |
"column 3 comparator 2" | Sort using the column at index 3, using that column's comparator at index 2, in forward order |
"column 3 comparator 2 reversed" | Sort using the column at index 3, using that column's comparator at index 2, in reverse order |
"column 3 reversed, column 1 comparator 2, column 5 comparator 1 reversed, column 0" | Sort using the column at index 3, using that column's first comparator, in reverse order then by the column at index 1, using that column's comparator at index 2, in forward order then by the column at index 5, using that column's comparator at index 1, in reverse order then by the column at index 0, using that column's first comparator, in forward order. |
More formally, the grammar for this String representation is as follows:
<COLUMN> = column <COLUMN INDEX> (comparator <COMPARATOR INDEX>)? (reversed)?
<COMPARATOR SPEC> = ( <COLUMN> (, <COLUMN>)* )?
public void dispose()
Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by debian at 2016-11-28 3:17