org.springframework.richclient.table
Class ShuttleSortableTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.springframework.richclient.table.AbstractTableModelFilter
          extended by org.springframework.richclient.table.ShuttleSortableTableModel
All Implemented Interfaces:
Serializable, EventListener, TableModelListener, TableModel, SortableTableModel

public class ShuttleSortableTableModel
extends AbstractTableModelFilter
implements SortableTableModel

A sorter for TableModels. The sorter has a model (conforming to TableModel) and itself implements TableModel. TableSorter does not store or copy the model in the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model. 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 around rows when its comparison function returns 0 to denote that they are equivalent.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.springframework.richclient.table.AbstractTableModelFilter
filteredModel, logger
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ShuttleSortableTableModel(TableModel model)
           
 
Method Summary
 int compare(int row1, int row2)
           
 int[] convertDataIndexesToSortedIndexes(int[] indexes)
           
 int convertModelToRowIndex(int index)
           
 int[] convertSortedIndexesToDataIndexes(int[] indexes)
           
 int convertSortedIndexToDataIndex(int index)
           
 Comparator getComparator(int columnIndex)
           
 Object getValueAt(int row, int column)
           
 boolean isAutoSortEnabled()
           
 boolean isCellEditable(int row, int column)
           
protected  void notifyTableChanged()
           
 void resetComparators()
           
 void resetComparators(Map comparators)
          Reset the columnComparartos.
Useful when the columns of the model were changed, and by consequence their comparators.
 void setAutoSortEnabled(boolean autoSortEnabled)
           
 void setComparator(int columnIndex, Comparator comparator)
           
 void setValueAt(Object value, int row, int column)
           
 void sortByColumn(ColumnToSort columnToSort)
           
 void sortByColumns(ColumnToSort[] columnsToSort)
           
 int[] sortByColumns(ColumnToSort[] columnsToSort, int[] preSortSelectedRows)
           
 void tableChanged(TableModelEvent e)
           
 
Methods inherited from class org.springframework.richclient.table.AbstractTableModelFilter
getColumnClass, getColumnCount, getColumnName, getFilteredModel, getRowCount
 
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 org.springframework.richclient.table.SortableTableModel
getFilteredModel
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, removeTableModelListener
 

Constructor Detail

ShuttleSortableTableModel

public ShuttleSortableTableModel(TableModel model)
Method Detail

resetComparators

public void resetComparators()

resetComparators

public void resetComparators(Map comparators)
Reset the columnComparartos.
Useful when the columns of the model were changed, and by consequence their comparators.

Parameters:
comparators - - map with comparators where the key is the column of the comparator.

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModelFilter

isAutoSortEnabled

public boolean isAutoSortEnabled()

setAutoSortEnabled

public void setAutoSortEnabled(boolean autoSortEnabled)

getComparator

public Comparator getComparator(int columnIndex)

setComparator

public void setComparator(int columnIndex,
                          Comparator comparator)
Specified by:
setComparator in interface SortableTableModel

getValueAt

public Object getValueAt(int row,
                         int column)
Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class AbstractTableModelFilter

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModelFilter

sortByColumn

public void sortByColumn(ColumnToSort columnToSort)
Specified by:
sortByColumn in interface SortableTableModel

sortByColumns

public void sortByColumns(ColumnToSort[] columnsToSort)
Specified by:
sortByColumns in interface SortableTableModel

sortByColumns

public int[] sortByColumns(ColumnToSort[] columnsToSort,
                           int[] preSortSelectedRows)
Specified by:
sortByColumns in interface SortableTableModel

notifyTableChanged

protected void notifyTableChanged()

convertSortedIndexToDataIndex

public int convertSortedIndexToDataIndex(int index)
Specified by:
convertSortedIndexToDataIndex in interface SortableTableModel

convertSortedIndexesToDataIndexes

public int[] convertSortedIndexesToDataIndexes(int[] indexes)
Specified by:
convertSortedIndexesToDataIndexes in interface SortableTableModel

convertModelToRowIndex

public int convertModelToRowIndex(int index)

convertDataIndexesToSortedIndexes

public int[] convertDataIndexesToSortedIndexes(int[] indexes)
Specified by:
convertDataIndexesToSortedIndexes in interface SortableTableModel

compare

public int compare(int row1,
                   int row2)

tableChanged

public void tableChanged(TableModelEvent e)
Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class AbstractTableModelFilter


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.