org.fopps.ui
Class EnhancedTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--org.fopps.ui.EnhancedTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel
Direct Known Subclasses:
AttachmentTableModel, ConfigurationTableModel, FeatureConstraintTableModel, ProductAssetTableModel, ProjectTableModel

public abstract class EnhancedTableModel
extends javax.swing.table.AbstractTableModel

EnhancedTableModel enables table sorting and supplies proper selection of table rows. To enable sorting you have to do the following steps

That's it. Your table should be sortable by clicking with the mouse on it. For descend ordering use the shift key.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
EnhancedTableModel()
           
 
Method Summary
protected  void checkModel()
          Checks consistency of model.
 int compare(int row1, int row2)
           
abstract  int compareRowsByColumn(int row1, int row2, int column)
          All subclasses have to overwrite this method in order to fetch the values from the unsorted array.
 int compareRowsByColumn(java.lang.Object o1, java.lang.Object o2, int column)
           
 void fireTableDataChanged()
          Notifies all listeners that all cell values in the table's rows may have changed.
 java.lang.Class getCellClass(int row, int col)
          Returns the class of the current cell.
 int getObjectColumn()
          Returns the column index, which contains the representing row object.
abstract  java.lang.Object getRowObject(int pRow)
          Returns the objects that represents the data of the whole row.
abstract  java.lang.Object getValueAt(int aRow, int aColumn)
           
 void n2sort()
           
protected  void reallocateIndexes()
           
abstract  void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
           
 void shuttlesort(int[] from, int[] to, int low, int high)
           
 void sort(java.lang.Object sender)
           
 void sortByColumn(int column)
           
 void sortByColumn(int column, boolean ascending)
           
 void swap(int i, int j)
           
 int translateRow(int pOriginalRow)
          Translates a given row into a corresponding row which complies to the current sorting mode
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, isCellEditable, 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
getColumnCount, getRowCount
 

Constructor Detail

EnhancedTableModel

public EnhancedTableModel()
Method Detail

compareRowsByColumn

public abstract int compareRowsByColumn(int row1,
                                        int row2,
                                        int column)
All subclasses have to overwrite this method in order to fetch the values from the unsorted array. Both values may be passed to compareRowsByColumn.

Parameters:
row1 - Row of the first item for comparison
row2 - Row of the second item for comparison
column - to sort by
Returns:
-1, if value of row1 is less than value of row2 or 1, if vice versa. If both values are equal regarding sort, return 0 instead.
See Also:
compareRowsByColumn(int, int, int)

compareRowsByColumn

public int compareRowsByColumn(java.lang.Object o1,
                               java.lang.Object o2,
                               int column)

compare

public int compare(int row1,
                   int row2)

translateRow

public int translateRow(int pOriginalRow)
Translates a given row into a corresponding row which complies to the current sorting mode


reallocateIndexes

protected void reallocateIndexes()

fireTableDataChanged

public void fireTableDataChanged()
Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same.

Overrides:
fireTableDataChanged in class javax.swing.table.AbstractTableModel
See Also:
TableModelEvent, EventListenerList

checkModel

protected void checkModel()
Checks consistency of model.


sort

public void sort(java.lang.Object sender)

n2sort

public void n2sort()

shuttlesort

public void shuttlesort(int[] from,
                        int[] to,
                        int low,
                        int high)

swap

public void swap(int i,
                 int j)

sortByColumn

public void sortByColumn(int column)

sortByColumn

public void sortByColumn(int column,
                         boolean ascending)

getValueAt

public abstract java.lang.Object getValueAt(int aRow,
                                            int aColumn)

setValueAt

public abstract void setValueAt(java.lang.Object aValue,
                                int aRow,
                                int aColumn)
Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel

getRowObject

public abstract java.lang.Object getRowObject(int pRow)
Returns the objects that represents the data of the whole row.


getCellClass

public java.lang.Class getCellClass(int row,
                                    int col)
Returns the class of the current cell. This allow a more finegrained selection of a renderer or editor. By default this method ignores the row parameter and returns the value of the given column.

Returns:
Class for given cell
See Also:
AbstractTableModel.getColumnClass(int)

getObjectColumn

public int getObjectColumn()
Returns the column index, which contains the representing row object. If the object is not represented by a column, this mwethod shold return -1. In this case the controller fetches the object via @see EnhancedTableModel#getRowObject(int)



Fopps 0.19 - Copyright © 2002 Oliver Wieland. All Rights Reserved.