EchoPoint
1.0

echopoint.table
Class SortableTableModel

java.lang.Object
  extended bynextapp.echo.table.AbstractTableModel
      extended byechopoint.table.TableModelAdapter
          extended byechopoint.table.SortableTableModel
All Implemented Interfaces:
java.util.EventListener, java.io.Serializable, nextapp.echo.table.TableModel, nextapp.echo.event.TableModelListener
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 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(nextapp.echo.table.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()
          Returns the Comparator that will be used to sort the TableModel
 int getModelRowIndex(int row)
          This returns the "sorted" table model row index for a given "visual" table row index.
 java.lang.Object getValueAt(int col, int row)
          Returns the "sorted" value at the given column and row.
 void setComparator(java.util.Comparator newComparator)
          Sets the Comparator that will be used to sort the TableModel
 void setModel(nextapp.echo.table.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 tableChanged(nextapp.echo.event.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
Constructor Detail

SortableTableModel

public SortableTableModel()
SortableTableModel constructor


SortableTableModel

public SortableTableModel(nextapp.echo.table.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()
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 nextapp.echo.table.TableModel
Overrides:
getValueAt in class TableModelAdapter
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(nextapp.echo.table.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


tableChanged

public void tableChanged(nextapp.echo.event.TableModelEvent e)
Implementation of TableModelListener

Specified by:
tableChanged in interface nextapp.echo.event.TableModelListener
Overrides:
tableChanged in class TableModelAdapter
See Also:
TableModel

EchoPoint
1.0