echopoint.table
Class SortableTableModel

java.lang.Object
  extended by nextapp.echo.table.AbstractTableModel
      extended by echopoint.table.TableModelAdapter
          extended by echopoint.table.SortableTableModel
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, TableModelListener, TableModel
Direct Known Subclasses:
SortablePagedTableModel

public class SortableTableModel
extends TableModelAdapter

A sorter of TableModels.

The sorter has a model (conforming to TableModel) and itself implements TableModel. TableSorter does not store or copy the data in the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model.

This class uses a Comparator to sort the data. The DefaultSortableTableModel comparator is used by default, which can sort Java basisc types as well as some Echo Components.

When the model changes, it notifies the sorter that something has changed eg. "rowsAdded" so that its internal array of integers can be reallocated. As requests are made of the sorter (like getValueAt(row, col) it redirects them to its model via the mapping array. That way the TableSorter appears to hold another copy of the table with the rows in a different order.

The sorting algorthm used is stable which means that it does not move rows around when the Comparator returns 0 to denote that they are equivalent.

See Also:
Serialized Form

Field Summary
static int COMPARATOR_STYLE_BEAN
           
static int COMPARATOR_STYLE_PROPERTYCOMPONENT
           
static int COMPARATOR_STYLE_VALUE
           
static int DOWN
           
static int NONE
          allowable states for a column
static int UP
           
 
Fields inherited from class echopoint.table.TableModelAdapter
model
 
Fields inherited from class nextapp.echo.table.AbstractTableModel
listenerList
 
Constructor Summary
SortableTableModel()
          SortableTableModel constructor
SortableTableModel(TableModel model)
          SortableTableModel constructor that wraps the given TableModel.
 
Method Summary
 int getColumnSortingState(int col)
          This method returns the state of a given column and whether it is being sorted UP, DOWN or NONE.
 java.util.Comparator getComparator(ColumnSortCriterion columnSortCriterion)
          Returns the Comparator that will be used to sort the TableModel
 int getComparatorStyle()
           
 int getModelRowIndex(int row)
          This returns the "sorted" table model row index for a given "visual" table row index.
 int getSortableRowIndex(int modelIndex)
           
 java.lang.Object getValueAt(int col, int row)
          Returns the "sorted" value at the given column and row.
 boolean isRowEditable(int row)
           When a table model supports editing of data, this method will be called to query if a row is currently editable.
 void setComparator(java.util.Comparator newComparator)
          Sets the Comparator that will be used to sort the TableModel
 void setComparatorStyle(int comparatorStyle)
           
 void setModel(TableModel model)
          Sets the model wrapped by this SortableTableModel.
 void sortByColumn(int column)
          Sorts the model by the given column, in ascending order.
 void sortByColumn(int column, boolean ascending)
          Sorts the model by the given column, with the given ordering
 void sortByColumns(java.util.List columnSortCriteria)
          Sorts the model by the given columns, with the given ordering
 void tableChanged(TableModelEvent e)
          Implementation of TableModelListener
 
Methods inherited from class echopoint.table.TableModelAdapter
deleteRow, getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, insertRow
 
Methods inherited from class nextapp.echo.table.AbstractTableModel
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOWN

public static final int DOWN
See Also:
Constant Field Values

NONE

public static final int NONE
allowable states for a column

See Also:
Constant Field Values

UP

public static final int UP
See Also:
Constant Field Values

COMPARATOR_STYLE_PROPERTYCOMPONENT

public static final int COMPARATOR_STYLE_PROPERTYCOMPONENT
See Also:
Constant Field Values

COMPARATOR_STYLE_VALUE

public static final int COMPARATOR_STYLE_VALUE
See Also:
Constant Field Values

COMPARATOR_STYLE_BEAN

public static final int COMPARATOR_STYLE_BEAN
See Also:
Constant Field Values
Constructor Detail

SortableTableModel

public SortableTableModel()
SortableTableModel constructor


SortableTableModel

public SortableTableModel(TableModel model)
SortableTableModel constructor that wraps the given TableModel.

Method Detail

getColumnSortingState

public int getColumnSortingState(int col)
This method returns the state of a given column and whether it is being sorted UP, DOWN or NONE.


getComparator

public java.util.Comparator getComparator(ColumnSortCriterion columnSortCriterion)
Returns the Comparator that will be used to sort the TableModel

Returns:
java.util.Comparator

getModelRowIndex

public int getModelRowIndex(int row)
This returns the "sorted" table model row index for a given "visual" table row index.


getValueAt

public java.lang.Object getValueAt(int col,
                                   int row)
Returns the "sorted" value at the given column and row.

Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class TableModelAdapter
Parameters:
col - The column of the value to return.
row - The row of the value to return.
See Also:
TableModel

setComparator

public void setComparator(java.util.Comparator newComparator)
Sets the Comparator that will be used to sort the TableModel

Parameters:
newComparator - java.util.Comparator

setModel

public void setModel(TableModel model)
Sets the model wrapped by this SortableTableModel.

Overrides:
setModel in class TableModelAdapter
See Also:
TableModel

sortByColumn

public void sortByColumn(int column)
Sorts the model by the given column, in ascending order.


sortByColumn

public void sortByColumn(int column,
                         boolean ascending)
Sorts the model by the given column, with the given ordering


sortByColumns

public void sortByColumns(java.util.List columnSortCriteria)
Sorts the model by the given columns, with the given ordering


tableChanged

public void tableChanged(TableModelEvent e)
Implementation of TableModelListener

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class TableModelAdapter
Parameters:
e - The event describing the action.
See Also:
TableModel

isRowEditable

public boolean isRowEditable(int row)
Description copied from interface: TableModel

When a table model supports editing of data, this method will be called to query if a row is currently editable.

Specified by:
isRowEditable in interface TableModel
Overrides:
isRowEditable in class TableModelAdapter

getSortableRowIndex

public int getSortableRowIndex(int modelIndex)

getComparatorStyle

public int getComparatorStyle()

setComparatorStyle

public void setComparatorStyle(int comparatorStyle)