JIDE 3.5.15

com.jidesoft.grid
Class CalculatedTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.grid.DefaultColumnTableModelWrapper
          extended by com.jidesoft.grid.CalculatedTableModel
All Implemented Interfaces:
ColumnIdentifierTableModel, ColumnTableModelWrapper, ContextSensitiveTableModel, ITreeTableModel, MultiTableModel, SpanModel, StyleModel, TableModelWrapper, Serializable, EventListener, TableModelListener, TableModel

public class CalculatedTableModel
extends DefaultColumnTableModelWrapper

CalculatedTableModel allows user to create a new table model based on an existing table model using column based conversion. For example, you can only expose some columns in the existing table model to the new table model by using addColumn(CalculatedColumn) with SingleColumn.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.jidesoft.grid.DefaultColumnTableModelWrapper
_indexes, _model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.jidesoft.grid.MultiTableModel
FOOTER_COLUMN, HEADER_COLUMN, REGULAR_COLUMN
 
Constructor Summary
CalculatedTableModel(TableModel model)
          The constructor.
 
Method Summary
 void addAllColumns()
          Adds all columns from the original table model.
 void addColumn(CalculatedColumn column)
          Adds a new CalculatedColumn.
 void addColumns(Collection<CalculatedColumn> columns)
          Adds a set of new CalculatedColumns.
protected  Row createWrappedRow(ExpandableRow originalRow)
          Creates wrapped row in the wrapped ITreeTableModel.
 int getActualColumnAt(int column)
          Gets the actual column.
 CalculatedColumn getCalculatedColumnAt(int columnIndex)
          Gets the CalculatedColumn instance at the column.
 Class<?> getCellClassAt(int row, int column)
          Gets the cell class of the underlying table model.
 Class<?> getColumnClass(int column)
           
 int getColumnCount()
           
 Object getColumnIdentifier(int column)
          Returns the identifier of the column in the model.
 String getColumnName(int column)
           
 ConverterContext getConverterContextAt(int row, int column)
          Gets the converter context of the underlying table model.
protected  int[] getDependingColumnsOf(int column)
          Gets the depending columns of the column.
 EditorContext getEditorContextAt(int row, int column)
          Gets the editor context of the underlying table model.
 int[] getIndexes()
          Gets the indexes that maps from the visual column index to the actual column index.
 Object getValueAt(int row, int column)
           
 int getVisualColumnAt(int actualColumn)
          Gets the visual column.
 boolean isCellEditable(int row, int column)
           
 void removeColumn(CalculatedColumn column)
          Removes an existing CalculatedColumn.
 void removeColumns(Collection<CalculatedColumn> columns)
          Removes a set of existing CalculatedColumns.
 void setIndexes(int[] indexes)
          Sets the indexes of the column mapping.
 void setValueAt(Object value, int row, int column)
           
 void tableCellsUpdated(int columnIndex, int firstRow, int lastRow)
          Called each time the cells in column in the range [firstRow, lastRow] are updated.
protected  void tableDataChanged(CompoundTableModelEvent event)
           
 
Methods inherited from class com.jidesoft.grid.DefaultColumnTableModelWrapper
createCompoundTableModelEvent, fireTableCellsUpdated, fireTableChanged, getActualModel, getCellSpanAt, getCellStyleAt, getColumnType, getRoot, getRowAt, getRowCount, getRowIndex, getTableIndex, isCellSpanOn, isCellStyleOn, reallocateIndexes, tableChanged, tableDataChanged, tableRowsDeleted, tableRowsInserted, tableRowsUpdated, tableStructureChanged
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, 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 javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Constructor Detail

CalculatedTableModel

public CalculatedTableModel(TableModel model)
The constructor.

Parameters:
model - the original table model.
Method Detail

getCalculatedColumnAt

public CalculatedColumn getCalculatedColumnAt(int columnIndex)
Gets the CalculatedColumn instance at the column.

Parameters:
columnIndex - the column index
Returns:
the CalculatedColumn instance.

getActualColumnAt

public int getActualColumnAt(int column)
Description copied from class: DefaultColumnTableModelWrapper
Gets the actual column.

Specified by:
getActualColumnAt in interface ColumnTableModelWrapper
Overrides:
getActualColumnAt in class DefaultColumnTableModelWrapper
Parameters:
column - the column on the UI.
Returns:
the actual column in the actual model. It will throw IllegalArgumentException if the column is out of range.

getVisualColumnAt

public final int getVisualColumnAt(int actualColumn)
Description copied from class: DefaultColumnTableModelWrapper
Gets the visual column.

Specified by:
getVisualColumnAt in interface ColumnTableModelWrapper
Overrides:
getVisualColumnAt in class DefaultColumnTableModelWrapper
Parameters:
actualColumn - the actual column in actual model.
Returns:
the column on UI. -1 if cannot find the column.

getValueAt

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

setValueAt

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

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel
Overrides:
getColumnCount in class DefaultColumnTableModelWrapper

getColumnName

public String getColumnName(int column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class DefaultColumnTableModelWrapper

getColumnIdentifier

public Object getColumnIdentifier(int column)
Description copied from interface: ColumnIdentifierTableModel
Returns the identifier of the column in the model. A JideTable uses this method to get the unique identifier of this column.

Specified by:
getColumnIdentifier in interface ColumnIdentifierTableModel
Overrides:
getColumnIdentifier in class DefaultColumnTableModelWrapper
Parameters:
column - the index of the column
Returns:
the unique identifier of the column.

getColumnClass

public Class<?> getColumnClass(int column)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class DefaultColumnTableModelWrapper

isCellEditable

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

getCellClassAt

public Class<?> getCellClassAt(int row,
                               int column)
Description copied from class: DefaultColumnTableModelWrapper
Gets the cell class of the underlying table model. This will return a valid value only if underlying table model is instance of ContextSensitiveTableModel. If not, it will return null.

Specified by:
getCellClassAt in interface ContextSensitiveTableModel
Overrides:
getCellClassAt in class DefaultColumnTableModelWrapper
Parameters:
row - the row index.
column - the column index.
Returns:
cell class of the underlying table model.

getEditorContextAt

public EditorContext getEditorContextAt(int row,
                                        int column)
Description copied from class: DefaultColumnTableModelWrapper
Gets the editor context of the underlying table model. This will return a valid value only if underlying table model is instance of ContextSensitiveTableModel. If not, it will return null.

Specified by:
getEditorContextAt in interface ContextSensitiveTableModel
Overrides:
getEditorContextAt in class DefaultColumnTableModelWrapper
Parameters:
row - the row index.
column - the column index.
Returns:
editor context of the underlying table model.

getConverterContextAt

public ConverterContext getConverterContextAt(int row,
                                              int column)
Description copied from class: DefaultColumnTableModelWrapper
Gets the converter context of the underlying table model. This will return a valid value only if underlying table model is instance of ContextSensitiveTableModel. If not, it will return null.

Specified by:
getConverterContextAt in interface ContextSensitiveTableModel
Overrides:
getConverterContextAt in class DefaultColumnTableModelWrapper
Parameters:
row - the row index.
column - the column index.
Returns:
converter context of the underlying table model.

getIndexes

public final int[] getIndexes()
Description copied from class: DefaultColumnTableModelWrapper
Gets the indexes that maps from the visual column index to the actual column index.

Overrides:
getIndexes in class DefaultColumnTableModelWrapper
Returns:
the indexes.

setIndexes

public final void setIndexes(int[] indexes)
Description copied from class: DefaultColumnTableModelWrapper
Sets the indexes of the column mapping. We exposed this method to allow quick access to the underlying indexes. The method won't fire any table events. So once you change the indexes, you need to fire corresponding table event so that table can update itself.

Overrides:
setIndexes in class DefaultColumnTableModelWrapper
Parameters:
indexes - the new index array.

getDependingColumnsOf

protected int[] getDependingColumnsOf(int column)
Gets the depending columns of the column.

Parameters:
column - the column index
Returns:
all columns directly depending on the column.

tableDataChanged

protected void tableDataChanged(CompoundTableModelEvent event)
Overrides:
tableDataChanged in class DefaultColumnTableModelWrapper

tableCellsUpdated

public void tableCellsUpdated(int columnIndex,
                              int firstRow,
                              int lastRow)
Description copied from class: DefaultColumnTableModelWrapper
Called each time the cells in column in the range [firstRow, lastRow] are updated. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableCellsUpdated in class DefaultColumnTableModelWrapper
Parameters:
columnIndex - the index of the column that was updated
firstRow - the index of the first row in the above column that was updated
lastRow - the index of the last row in the above column that was updated

addAllColumns

public void addAllColumns()
Adds all columns from the original table model.

Since you could select part of the columns in the original table model, JIDE don't invoke this method by default in the constructor. Please make sure you will invoke this method to include all existing columns in the original table model.


addColumn

public void addColumn(CalculatedColumn column)
Adds a new CalculatedColumn.

Parameters:
column - the new column
See Also:
addColumns(java.util.Collection)

addColumns

public void addColumns(Collection<CalculatedColumn> columns)
Adds a set of new CalculatedColumns.

Parameters:
columns - the new columns

removeColumn

public void removeColumn(CalculatedColumn column)
Removes an existing CalculatedColumn.

Parameters:
column - the column
See Also:
removeColumns(java.util.Collection)

removeColumns

public void removeColumns(Collection<CalculatedColumn> columns)
Removes a set of existing CalculatedColumns.

Parameters:
columns - the columns

createWrappedRow

protected Row createWrappedRow(ExpandableRow originalRow)
Description copied from class: DefaultColumnTableModelWrapper
Creates wrapped row in the wrapped ITreeTableModel.

Overrides:
createWrappedRow in class DefaultColumnTableModelWrapper
Parameters:
originalRow - the original row in the wrapped ITreeTableModel
Returns:
the wrapped row instance.

JIDE 3.5.15