The Meta-Environment API

nl.cwi.sen1.visplugin.table.model
Class SortableTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by javax.swing.table.DefaultTableModel
          extended by nl.cwi.sen1.visplugin.table.model.SortableTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class SortableTableModel
extends javax.swing.table.DefaultTableModel

Table model supporting column sortings. This model is able to work directly with RTuples and its data should be set using the setRTupleData() function. The original RElems can then be retrieved for every table row using the getRElemForRow() function.

Author:
Anton Gerdessen
See Also:
Serialized Form

Field Summary
private  nl.cwi.sen1.relationstores.types.RTuple m_data
           
private  int[] m_indexes
           
private  nl.cwi.sen1.relationstores.types.RType m_rTupleRType
           
private  nl.cwi.sen1.relationstores.types.IdCon m_rTupleVariable
           
private  TableSorter m_sorter
           
private static long serialVersionUID
           
 
Fields inherited from class javax.swing.table.DefaultTableModel
columnIdentifiers, dataVector
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
SortableTableModel()
           
 
Method Summary
private static java.lang.String[] convertColumnTypesToStrings(nl.cwi.sen1.relationstores.types.RTypeColumnTypes columnTypes)
          Converts RTypeColumnTypes to an array of Strings
 java.lang.Class getColumnClass(int column)
          Return the type which is displayed in the given column.
 int[] getIndexes()
          Returns the index mapping on which the current sort is based.
 nl.cwi.sen1.relationstores.types.RElem getRElemForRow(int rowIndex)
          Returns an RElem containing the data for a row.
 nl.cwi.sen1.relationstores.types.RType getRTupleRType()
          Returns the RType of the set RTuple data.
 nl.cwi.sen1.relationstores.types.IdCon getRTupleVariable()
          Returns the variable of the set RTuple data.
 java.lang.Object getValueAt(int row, int col)
          Retrieve the value for a given postion (row,col).
private static java.lang.Object getValueFromRElem(nl.cwi.sen1.relationstores.types.RElem element)
          Converts RElem value to an object.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns
 void setRTupleData(nl.cwi.sen1.relationstores.types.RTuple data)
          Sets the data of the table model to the data contained in the RTuple.
 void setValueAt(java.lang.Object value, int row, int col)
          Set the value for a given postion (row,col).
 void sortByColumn(int column, boolean isAscent)
          Retrieve the value for a given postion (row,col).
 
Methods inherited from class javax.swing.table.DefaultTableModel
addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getColumnCount, getColumnName, getDataVector, getRowCount, insertRow, insertRow, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount
 
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

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

m_indexes

private int[] m_indexes

m_sorter

private TableSorter m_sorter

m_data

private nl.cwi.sen1.relationstores.types.RTuple m_data

m_rTupleVariable

private nl.cwi.sen1.relationstores.types.IdCon m_rTupleVariable

m_rTupleRType

private nl.cwi.sen1.relationstores.types.RType m_rTupleRType
Constructor Detail

SortableTableModel

public SortableTableModel()
Method Detail

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)
Retrieve the value for a given postion (row,col).

Specified by:
getValueAt in interface javax.swing.table.TableModel
Overrides:
getValueAt in class javax.swing.table.DefaultTableModel
Parameters:
row - The (row,col) combination
col - The (row,col) combination

setValueAt

public void setValueAt(java.lang.Object value,
                       int row,
                       int col)
Set the value for a given postion (row,col).

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.DefaultTableModel
Parameters:
value - The value to set at the (row,col) combination
row - The (row,col) combination
col - The (row,col) combination

sortByColumn

public void sortByColumn(int column,
                         boolean isAscent)
Retrieve the value for a given postion (row,col).

Parameters:
column - the column to base the sort on
isAscent - ascending (true) or or decending (false) order

getIndexes

public int[] getIndexes()
Returns the index mapping on which the current sort is based.

Returns:
The index mapping as an array.

getColumnClass

public java.lang.Class getColumnClass(int column)
Return the type which is displayed in the given column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
column - The column to retrieve the type from

setRTupleData

public void setRTupleData(nl.cwi.sen1.relationstores.types.RTuple data)
Sets the data of the table model to the data contained in the RTuple.

Parameters:
data - The RTuple data to put in the table.

getRTupleVariable

public nl.cwi.sen1.relationstores.types.IdCon getRTupleVariable()
Returns the variable of the set RTuple data.

Returns:
The RTuple variable.

getRTupleRType

public nl.cwi.sen1.relationstores.types.RType getRTupleRType()
Returns the RType of the set RTuple data.

Returns:
The RTuple RType.

getRElemForRow

public nl.cwi.sen1.relationstores.types.RElem getRElemForRow(int rowIndex)
Returns an RElem containing the data for a row.

Parameters:
rowIndex - Index of the row. If sorting is enabled, the index will automatically adjusted.
Returns:
An RElem from the RTuple data.

getValueFromRElem

private static java.lang.Object getValueFromRElem(nl.cwi.sen1.relationstores.types.RElem element)
                                           throws java.lang.Exception
Converts RElem value to an object. It supports only four types (str, int, bool, loc ) now.

Parameters:
element -
Returns:
Object
Throws:
java.lang.Exception - Throws and unknown RElem exception when the element is of an unknown type.

convertColumnTypesToStrings

private static java.lang.String[] convertColumnTypesToStrings(nl.cwi.sen1.relationstores.types.RTypeColumnTypes columnTypes)
Converts RTypeColumnTypes to an array of Strings

Parameters:
columnTypes -
Returns:

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.DefaultTableModel
Parameters:
rowIndex - Row index of the cell, ignored.
columnIndex - Column index of the cell, ignored.
Returns:

The Meta-Environment API