gate.swing
Class XJTable.SortingModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by gate.swing.XJTable.SortingModel
All Implemented Interfaces:
Serializable, EventListener, TableModelListener, TableModel
Enclosing class:
XJTable

protected class XJTable.SortingModel
extends AbstractTableModel
implements TableModelListener

Handles translations between an indexed data source and a permutation of itself (like the translations between the rows in sorted table and the rows in the actual unsorted model).

See Also:
Serialized Form

Nested Class Summary
protected  class XJTable.SortingModel.ValueHolder
           
protected  class XJTable.SortingModel.ValueHolderComparator
           
 
Field Summary
protected  XJTable.SortingModel.ValueHolderComparator compWrapper
           
protected  TableModel sourceModel
           
protected  int[] sourceToTarget
          The direct index
protected  int[] targetToSource
          The reverse index.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
XJTable.SortingModel(TableModel sourceModel)
           
 
Method Summary
protected  void buildTargetToSourceIndex()
          Builds the reverse index based on the new sorting order.
 Class getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 String getColumnName(int columnIndex)
           
 int getRowCount()
           
 Object getValueAt(int row, int column)
           
protected  void init(TableModel sourceModel)
           
 boolean isCellEditable(int rowIndex, int columnIndex)
           
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
           
 void sort()
          Sorts the table using the values in the specified column and sorting order.
 int sourceToTarget(int index)
          Converts an index from the source coordinates to the target ones.
 void tableChanged(TableModelEvent e)
          This gets events from the source model and forwards them to the UI
 int targetToSource(int index)
          Converts an index from the target coordinates to the source ones.
 
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
 

Field Detail

sourceToTarget

protected int[] sourceToTarget
The direct index


targetToSource

protected int[] targetToSource
The reverse index.


sourceModel

protected TableModel sourceModel

compWrapper

protected XJTable.SortingModel.ValueHolderComparator compWrapper
Constructor Detail

XJTable.SortingModel

public XJTable.SortingModel(TableModel sourceModel)
Method Detail

init

protected void init(TableModel sourceModel)

tableChanged

public void tableChanged(TableModelEvent e)
This gets events from the source model and forwards them to the UI

Specified by:
tableChanged in interface TableModelListener

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getColumnName

public String getColumnName(int columnIndex)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

getValueAt

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

sort

public void sort()
Sorts the table using the values in the specified column and sorting order. sortedColumn is the column used for sorting the data. ascending is the sorting order.


sourceToTarget

public int sourceToTarget(int index)
Converts an index from the source coordinates to the target ones. Used to propagate events from the data source (table model) to the view.

Parameters:
index - the index in the source coordinates.
Returns:
the corresponding index in the target coordinates or -1 if the provided row is outside the permitted values.

targetToSource

public int targetToSource(int index)
Converts an index from the target coordinates to the source ones.

Parameters:
index - the index in the target coordinates. Used to propagate events from the view (e.g. editing) to the source data source (table model).
Returns:
the corresponding index in the source coordinates or -1 if the row provided is outside the allowed range.

buildTargetToSourceIndex

protected void buildTargetToSourceIndex()
Builds the reverse index based on the new sorting order.