JIDE 3.5.15

com.jidesoft.grid
Class DefaultTableModelWrapper

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.grid.TableModelWrapperImpl
          extended by com.jidesoft.grid.DefaultTableModelWrapper
All Implemented Interfaces:
ColumnIdentifierTableModel, ContextSensitiveTableModel, EditorStyleTableModel, IndexChangeEventGenerator, IndexedRowTableModelWrapper, MultiTableModel, NavigableModel, RowTableModelWrapper, SpanModel, StyleModel, TableModelWrapper, Serializable, EventListener, TableModelListener, TableModel
Direct Known Subclasses:
FilterableTableModel, SortableTableModel

public class DefaultTableModelWrapper
extends TableModelWrapperImpl
implements IndexedRowTableModelWrapper

The default implementation of RowTableModelWrapper.

See Also:
Serialized Form

Field Summary
protected  int[] _indexes
           
 
Fields inherited from class com.jidesoft.grid.TableModelWrapperImpl
_model
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Fields inherited from interface com.jidesoft.grid.MultiTableModel
FOOTER_COLUMN, HEADER_COLUMN, REGULAR_COLUMN
 
Fields inherited from interface com.jidesoft.grid.EditorStyleTableModel
EDITOR_STYLE_EDITABLE, EDITOR_STYLE_NORMAL, EDITOR_STYLE_READ_ONLY, EDITOR_STYLE_SELECT_ONLY
 
Constructor Summary
DefaultTableModelWrapper(TableModel model)
          Creates a DefaultTableModelWrapper from any table model.
 
Method Summary
protected  void fireIndexChanged(int eventSerialNumber)
          Tells the TableModeWrapper that indexes is changed.
protected  int fireIndexChanging()
          Tells the TableModeWrapper that indexes is going to be changed.
 int getActualRowAt(int row)
          Gets the actual row.
 Class<?> getCellClassAt(int row, int column)
          Gets the cell class of the underlying table model.
 CellSpan getCellSpanAt(int rowIndex, int columnIndex)
          Gets cell span of the underlying table model.
 ConverterContext getConverterContextAt(int row, int column)
          Gets the converter context of the underlying table model.
 EditorContext getEditorContextAt(int row, int column)
          Gets the editor context of the underlying table model.
 int getEditorStyleAt(int rowIndex, int columnIndex)
          Gets editor style at the cell.
 int[] getIndexes()
          Gets the indexes that maps from the visual row index to the actual row index.
 int getRowCount()
           
 Object getValueAt(int row, int column)
           
 int getVisualRowAt(int actualRow)
          Gets the visual row.
 boolean isCacheEnabled()
          Checks if cache is enabled.
 boolean isCellEditable(int row, int column)
           
 boolean isRowCountChanged()
          Checks if underlying table model row count changed.
protected  void reallocateIndexes()
          Resets the index mapping.
 void setCacheEnabled(boolean cacheEnabled)
          Enables or disables the cache.
 void setIndexes(int[] indexes)
          Sets the indexes of the row mapping.
 void setValueAt(Object value, int row, int column)
           
protected  void tableCellsUpdated(int column, int firstRow, int lastRow)
          Called each time the cells in column in the range [firstRow, lastRow] are updated.
protected  void tableDataChanged()
          Called each time all of the data (i.e.
protected  void tableDataChanged(CompoundTableModelEvent event)
          Called if it receives a table data changed event however the event is an instance of CompoundTableModelEvent.
protected  void tableRowsDeleted(int firstRow, int lastRow)
          Called each time one or more contiguous rows are deleted from the underlying TableModel.
protected  void tableRowsInserted(int firstRow, int lastRow)
          Called each time one or more contiguous rows are inserted into the underlying TableModel.
protected  void tableRowsUpdated(int firstRow, int lastRow)
          Called each time one or more contiguous rows are updated in the underlying TableModel.
protected  void tableStructureChanged()
          Called each time the structure (TableColumns, etc) of the underlying TableModel changes.
 
Methods inherited from class com.jidesoft.grid.TableModelWrapperImpl
addIndexChangeListener, createCompoundTableModelEvent, fireTableCellsUpdated, fireTableChanged, getActualModel, getCellStyleAt, getColumnClass, getColumnCount, getColumnIdentifier, getColumnName, getColumnType, getIndexChangeListeners, getTableIndex, isCellSpanOn, isCellStyleOn, isNavigableAt, isNavigationOn, removeIndexChangeListener, tableChanged
 
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 com.jidesoft.grid.TableModelWrapper
getActualModel
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

_indexes

protected int[] _indexes
Constructor Detail

DefaultTableModelWrapper

public DefaultTableModelWrapper(TableModel model)
Creates a DefaultTableModelWrapper from any table model.

Parameters:
model - the actual table model.
Method Detail

getActualRowAt

public int getActualRowAt(int row)
Gets the actual row.

Specified by:
getActualRowAt in interface RowTableModelWrapper
Parameters:
row - the row on the UI.
Returns:
the actual row in the actual model. It will throw IllegalArgumentException if the row is out of range.

getVisualRowAt

public int getVisualRowAt(int actualRow)
Gets the visual row.

Specified by:
getVisualRowAt in interface RowTableModelWrapper
Parameters:
actualRow - the actual row in actual model.
Returns:
the row on UI. -1 if cannot find the row.

getValueAt

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

setValueAt

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

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel
Overrides:
getRowCount in class TableModelWrapperImpl

isCellEditable

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

getConverterContextAt

public ConverterContext getConverterContextAt(int row,
                                              int column)
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 TableModelWrapperImpl
Parameters:
row - the row index.
column - the column index.
Returns:
converter context of the underlying table model.

getEditorContextAt

public EditorContext getEditorContextAt(int row,
                                        int column)
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 TableModelWrapperImpl
Parameters:
row - the row index.
column - the column index.
Returns:
editor context of the underlying table model.

getCellClassAt

public Class<?> getCellClassAt(int row,
                               int column)
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 underlying model's getColumnClass(column).

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

isRowCountChanged

public boolean isRowCountChanged()
Checks if underlying table model row count changed.

Returns:
true if row count changed.

reallocateIndexes

protected void reallocateIndexes()
Resets the index mapping.


getIndexes

public int[] getIndexes()
Gets the indexes that maps from the visual row index to the actual row index. It will return a clone of the index array, not the actual array that is being used.

Specified by:
getIndexes in interface IndexedRowTableModelWrapper
Returns:
the indexes.

setIndexes

public void setIndexes(int[] indexes)
Sets the indexes of the row 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.

Specified by:
setIndexes in interface IndexedRowTableModelWrapper
Parameters:
indexes - the new index array.

isCacheEnabled

public boolean isCacheEnabled()
Checks if cache is enabled. If cache is enabled, it will create another int array to keep the reverse indexes. This will dramatically improve the speed of getRowAt().

Returns:
true if cache is enabled. Otherwise false.

setCacheEnabled

public void setCacheEnabled(boolean cacheEnabled)
Enables or disables the cache. If cache is enabled, it will create another int array to keep the reverse indexes. This will dramatically improve the speed of getRowAt(). However this performance only works when the values in the index array map exactly with the indices themselves. For example, {2, 0, 1} can be cached but {3, 0, 1} cannot because 3 is out of the index array's length. Because of this limitation, the only table model wrapper will benefit from this is the SortableTableModel. FilterableTableModel and most likely all other table model wrappers won't benefit from it. So we only turned this on for SortableTableModel.

By default, the cache is disabled as it only makes sense to cache in the case of the SortableTableModel.

Parameters:
cacheEnabled - true or false.

fireIndexChanging

protected int fireIndexChanging()
Tells the TableModeWrapper that indexes is going to be changed. It will basically fire an INDEX_CHANGING_EVENT event.

Overrides:
fireIndexChanging in class TableModelWrapperImpl
Returns:
the event serial number for this call, to be used in its partner fireIndexChanged

fireIndexChanged

protected void fireIndexChanged(int eventSerialNumber)
Tells the TableModeWrapper that indexes is changed. It will basically fire an INDEX_CHANGED_EVENT event.

Overrides:
fireIndexChanged in class TableModelWrapperImpl
Parameters:
eventSerialNumber - the serial number indicating where this method is invoked, to be pair with fireIndexChanging

getCellSpanAt

public CellSpan getCellSpanAt(int rowIndex,
                              int columnIndex)
Gets cell span of the underlying table model.

Specified by:
getCellSpanAt in interface SpanModel
Overrides:
getCellSpanAt in class TableModelWrapperImpl
Parameters:
rowIndex - the row index
columnIndex - the column index.
Returns:
cell span of the underlying table model.

tableRowsInserted

protected void tableRowsInserted(int firstRow,
                                 int lastRow)
Called each time one or more contiguous rows are inserted into the underlying TableModel. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableRowsInserted in class TableModelWrapperImpl
Parameters:
firstRow - the index of the first row that was inserted
lastRow - the index of the last row that was inserted

tableRowsDeleted

protected void tableRowsDeleted(int firstRow,
                                int lastRow)
Called each time one or more contiguous rows are deleted from the underlying TableModel. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableRowsDeleted in class TableModelWrapperImpl
Parameters:
firstRow - the index of the first row that was deleted
lastRow - the index of the last row that was deleted

tableRowsUpdated

protected void tableRowsUpdated(int firstRow,
                                int lastRow)
Called each time one or more contiguous rows are updated in the underlying TableModel. simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableRowsUpdated in class TableModelWrapperImpl
Parameters:
firstRow - the index of the first row that was updated
lastRow - the index of the last row that was updated

tableCellsUpdated

protected void tableCellsUpdated(int column,
                                 int firstRow,
                                 int lastRow)
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 TableModelWrapperImpl
Parameters:
column - 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

tableDataChanged

protected void tableDataChanged(CompoundTableModelEvent event)
Description copied from class: TableModelWrapperImpl
Called if it receives a table data changed event however the event is an instance of CompoundTableModelEvent.

Overrides:
tableDataChanged in class TableModelWrapperImpl
Parameters:
event - the received CompoundTableModelEvent

tableDataChanged

protected void tableDataChanged()
Called each time all of the data (i.e. all rows) is changed in the underlyingTableModel. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableDataChanged in class TableModelWrapperImpl

tableStructureChanged

protected void tableStructureChanged()
Called each time the structure (TableColumns, etc) of the underlying TableModel changes. This default implementation simply fires a corresponding TableModelEvent to the listeners on this model.

Overrides:
tableStructureChanged in class TableModelWrapperImpl

getEditorStyleAt

public int getEditorStyleAt(int rowIndex,
                            int columnIndex)
Description copied from interface: EditorStyleTableModel
Gets editor style at the cell.

Specified by:
getEditorStyleAt in interface EditorStyleTableModel
Overrides:
getEditorStyleAt in class TableModelWrapperImpl
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
the editor style.

JIDE 3.5.15