public class NewTableSorter extends AbstractTableModel implements IndexConverter
IndexConverter
, so the ListTableMapperBase
ListTableMapperBase
has access to the modelIndex
of the sorted table for using them in the ListSelectionModel callback methods.
When the tableHeader property is set, either by using the
setTableHeader() method or the two argument constructor, the
table header may be used as a complete UI for NewTableSorter.
The default renderer of the tableHeader is decorated with a renderer
that indicates the sorting status of a column. In addition,
a mouse listener is installed with the following behavior:
Any sorting will clear the selection in the table because
the table reacts that way to the change event.
If the sorting is initiated by the user (see the private inner class MouseHandler),
we attempt to restore the selection for the new order afterwards.
If that behaviour causes problem, it can be switched off
by setRestoreSelectionAfterSort(false)
.
Modifier and Type | Field and Description |
---|---|
static int |
ASCENDING |
static Comparator |
COMPARABLE_COMAPRATOR
static Comparable-Comparator
|
static int |
DESCENDING
sorting-status of a column
|
static Comparator |
LEXICAL_COMPARATOR
Static Lexical-Comparator with a special handling of String[]'s.
|
protected TableModel |
mTableModel
original TableModel
|
static int |
NOT_SORTED |
listenerList
Constructor and Description |
---|
NewTableSorter(TableModel pTableModel) |
NewTableSorter(TableModel pTableModel,
JTableHeader pTableHeader) |
Modifier and Type | Method and Description |
---|---|
void |
clearSortingState() |
int |
convert2ModelIndex(int pViewIndex)
This method converts the given view index of a table row to
the corresponding model index of this row.
|
int |
convert2ViewIndex(int pModelIndex)
This method converts the given model index of a table row to
the corresponding view index of this row.
|
void |
forceInitialSorting(int pColumn)
Provides programmatic acces to our sorting.
|
Class |
getColumnClass(int pColumn) |
int |
getColumnCount() |
String |
getColumnName(int pColumn) |
protected Comparator |
getComparator(int pColumn) |
protected Icon |
getHeaderRendererIcon(int pColumn,
int pSize) |
int |
getRowCount() |
int |
getSortingStatus(int pColumn) |
JTableHeader |
getTableHeader() |
TableModel |
getTableModel() |
Object |
getValueAt(int pRow,
int pColumn) |
boolean |
isAttemptRestoreSelectionAfterSort() |
boolean |
isCellEditable(int pRow,
int pColumn) |
boolean |
isSorting() |
int |
modelIndex(int pViewIndex) |
void |
setAttemptRestoreSelectionAfterSort(boolean pAttemptRestoreSelectionAfterSort) |
void |
setColumnComparator(Class pType,
Comparator pComparator) |
void |
setSortingStatus(int pColumn,
int pStatus) |
void |
setTableHeader(JTableHeader pTableHeader) |
void |
setTableModel(TableModel pTableModel) |
void |
setValueAt(Object pValue,
int pRow,
int pColumn) |
int |
viewIndex(int pModelIndex) |
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
protected TableModel mTableModel
public static final int DESCENDING
public static final int NOT_SORTED
public static final int ASCENDING
public static final Comparator COMPARABLE_COMAPRATOR
public static final Comparator LEXICAL_COMPARATOR
public NewTableSorter(TableModel pTableModel)
public NewTableSorter(TableModel pTableModel, JTableHeader pTableHeader)
public boolean isAttemptRestoreSelectionAfterSort()
public void setAttemptRestoreSelectionAfterSort(boolean pAttemptRestoreSelectionAfterSort)
public void clearSortingState()
public TableModel getTableModel()
public void setTableModel(TableModel pTableModel)
public JTableHeader getTableHeader()
public void setTableHeader(JTableHeader pTableHeader)
public boolean isSorting()
public int getSortingStatus(int pColumn)
public void setSortingStatus(int pColumn, int pStatus)
protected Icon getHeaderRendererIcon(int pColumn, int pSize)
public void setColumnComparator(Class pType, Comparator pComparator)
protected Comparator getComparator(int pColumn)
public int modelIndex(int pViewIndex)
public int viewIndex(int pModelIndex)
public void forceInitialSorting(int pColumn)
pColumn
- the column that should be sortedpublic int convert2ModelIndex(int pViewIndex)
IndexConverter
convert2ModelIndex
in interface IndexConverter
pViewIndex
- the view indexpublic int convert2ViewIndex(int pModelIndex)
IndexConverter
convert2ViewIndex
in interface IndexConverter
pModelIndex
- the model indexpublic int getRowCount()
getRowCount
in interface TableModel
public int getColumnCount()
getColumnCount
in interface TableModel
public String getColumnName(int pColumn)
getColumnName
in interface TableModel
getColumnName
in class AbstractTableModel
public Class getColumnClass(int pColumn)
getColumnClass
in interface TableModel
getColumnClass
in class AbstractTableModel
public boolean isCellEditable(int pRow, int pColumn)
isCellEditable
in interface TableModel
isCellEditable
in class AbstractTableModel
public Object getValueAt(int pRow, int pColumn)
getValueAt
in interface TableModel
public void setValueAt(Object pValue, int pRow, int pColumn)
setValueAt
in interface TableModel
setValueAt
in class AbstractTableModel
Copyright © 2017 Jürgen Zeller (privat). All rights reserved.