|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.table.AbstractTableModel
de.tkuhn.swing.table.RowSortingTableModel
public class RowSortingTableModel
This Class is a decorator wrapper for TableColumnModel
s that
enhances them wiht the ability of sorting the rows according to the values of
a column in ascending or descending order. In addition it provides a means
for storing and resetting the state of the sort order.
If you use JUserFriendlyTable
you should not need to use this
class.
JUserFriendlyTable
,
TableColumnModel
,
Serialized FormField Summary | |
---|---|
static boolean |
ASCENDING
Value for sort() in which order data should be sorted |
static boolean |
DESCENDING
Value for sort() in which order data should be sorted |
static int |
NO_COLUMN
Value for sort() if data should not be sorted |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Constructor Summary | |
---|---|
RowSortingTableModel()
Creates a new instance of RowSortingTableModel |
|
RowSortingTableModel(javax.swing.table.TableModel model)
Creates a new instance of RowSortingTableModel that wrapps the given model |
Method Summary | |
---|---|
static javax.swing.JTable |
enableRowSorting(javax.swing.JTable table)
Convenience method for enabling row sorting for a given table. |
java.lang.Class<?> |
getColumnClass(int columnIndex)
Implements getColumnClass(col) in the interface
TableModel . |
int |
getColumnCount()
Implements getColumnCount() in the interface
TableModel . |
java.lang.String |
getColumnName(int columnIndex)
Implements getColumnName(col) in the interface
TableModel . |
javax.swing.table.TableModel |
getModel()
Get the TableModel decorated by this wrapper. |
int |
getModelRow(int row)
Return the row number of the original model for the sorted row number. |
int |
getRowCount()
Implements getRowCount() in the interface
TableModel . |
java.lang.Object |
getState()
Creates a Memento of the state of this wrapper. |
java.lang.Object |
getValueAt(int rowIndex,
int columnIndex)
Implements getValueAt(row,col) in the interface
TableModel . |
void |
installHeaderExtension(javax.swing.JTable aTable)
Install the header extension for event listening at the given table. |
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Implements isCellEditable(row,col) in the interface
TableModel . |
void |
setModel(javax.swing.table.TableModel aModel)
Set a new TableModel in this decorator and notify all
TableModelListeners . |
static void |
setNewTableModel(javax.swing.JTable table,
javax.swing.table.TableModel model)
Set a new TableModel |
boolean |
setState(java.lang.Object aState)
Resets this wrapper to the given state if the column structure is similar to the one present while getState() was called. |
void |
setupTableForRowSorting(javax.swing.JTable aTable)
Registers this RowSortingTableModel at the given table by
setting itself as its new model and wrapping the table's old model. |
void |
setValueAt(java.lang.Object aValue,
int rowIndex,
int columnIndex)
Implements getColumnCount() in the interface
TableModel . |
void |
sort(int columnIndex,
boolean order)
Have the decorator sort the rows by values of given column in given order. |
void |
tearDownTableFromRowSorting(javax.swing.JTable aTable)
Remove row sorting from a table at which it was previously installed using setupTableForRowSorting(table) by setting the table's
model to its old model again and removing the header extension for event
listening |
void |
uninstallHeaderExtension(javax.swing.JTable aTable)
Remove the header extension for event listening from the given table. |
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.swing.table.TableModel |
---|
addTableModelListener, removeTableModelListener |
Field Detail |
---|
public static final int NO_COLUMN
public static final boolean ASCENDING
public static final boolean DESCENDING
Constructor Detail |
---|
public RowSortingTableModel()
public RowSortingTableModel(javax.swing.table.TableModel model)
model
- the model that will be decoratedMethod Detail |
---|
public static javax.swing.JTable enableRowSorting(javax.swing.JTable table)
TableModel
at the
table directly if you don't want to lose the sorting capability. Use
setNewTableModel(..)
instead. Also getModel()
on the table will not return the original model of the table but an
instance of RowSortingTableModel
.
table
- the table to enable row sorting for
setNewTableModel(javax.swing.JTable, javax.swing.table.TableModel)
public static void setNewTableModel(javax.swing.JTable table, javax.swing.table.TableModel model)
TableModel at a table you have enabled row sorting
before using enableRowSorting(table)
. This will keep the
sorting state if the new model is similar to the old one.
- Parameters:
table
- the table to set the new model formodel
- the new model to be set- See Also:
enableRowSorting(javax.swing.JTable)
public void setupTableForRowSorting(javax.swing.JTable aTable)
RowSortingTableModel
at the given table by
setting itself as its new model and wrapping the table's old model. Also
installs the header extension for event listening at the table header.
aTable
- the table to enable row sorting forpublic void tearDownTableFromRowSorting(javax.swing.JTable aTable)
setupTableForRowSorting(table)
by setting the table's
model to its old model again and removing the header extension for event
listening
aTable
- the table to remove row sorting fromsetupTableForRowSorting(javax.swing.JTable)
public void installHeaderExtension(javax.swing.JTable aTable)
setupTableForRowSorting(table)
to install row sorting.
aTable
- the table to install the extensionsetupTableForRowSorting(javax.swing.JTable)
public void uninstallHeaderExtension(javax.swing.JTable aTable)
tearDownTableFromRowSorting(table)
to uninstall row sorting.
aTable
- the table to uninstall the extension fromtearDownTableFromRowSorting(javax.swing.JTable)
public void setModel(javax.swing.table.TableModel aModel)
TableModel
in this decorator and notify all
TableModelListeners
. This will keep the sorting state if the
new model is similar to the old one.
aModel
- the new model to be installedpublic javax.swing.table.TableModel getModel()
TableModel
decorated by this wrapper.
TableModel
public void sort(int columnIndex, boolean order)
columnIndex
- index of column to sort by. Could be an int >= 0 or NO_COLUMNorder
- can be ASCENDING or DESCENDINGNO_COLUMN
,
ASCENDING
,
DESCENDING
public java.lang.Object getState()
public boolean setState(java.lang.Object aState)
getState()
was called. This method
must be called with a state object obtained by getState()
.
aState
- the state to set.
getState()
public int getColumnCount()
getColumnCount()
in the interface
TableModel
.
getColumnCount
in interface javax.swing.table.TableModel
TableModel
public int getRowCount()
getRowCount()
in the interface
TableModel
.
getRowCount
in interface javax.swing.table.TableModel
TableModel
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
getValueAt(row,col)
in the interface
TableModel
. Recalculate row by sort order.
getValueAt
in interface javax.swing.table.TableModel
TableModel
public java.lang.Class<?> getColumnClass(int columnIndex)
getColumnClass(col)
in the interface
TableModel
.
getColumnClass
in interface javax.swing.table.TableModel
getColumnClass
in class javax.swing.table.AbstractTableModel
TableModel
public java.lang.String getColumnName(int columnIndex)
getColumnName(col)
in the interface
TableModel
.
getColumnName
in interface javax.swing.table.TableModel
getColumnName
in class javax.swing.table.AbstractTableModel
TableModel
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable(row,col)
in the interface
TableModel
. Recalculate row by sort order.
isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.AbstractTableModel
TableModel
public void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
getColumnCount()
in the interface
TableModel
. Recalculate row by sort order.
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.AbstractTableModel
TableModel
public int getModelRow(int row)
row
- the sorted row number
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |