JIDE 3.5.15

com.jidesoft.grid
Class DefaultColumnTableModelWrapper

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

public class DefaultColumnTableModelWrapper
extends AbstractTableModel
implements ColumnTableModelWrapper, ContextSensitiveTableModel, StyleModel, SpanModel, MultiTableModel, TableModelListener, ColumnIdentifierTableModel, ITreeTableModel

The default implementation of ColumnTableModelWrapper.

See Also:
Serialized Form

Field Summary
protected  int[] _indexes
           
protected  TableModel _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
DefaultColumnTableModelWrapper(TableModel model)
          Creates a DefaultColumnTableModelWrapper from any table model.
 
Method Summary
protected  CompoundTableModelEvent createCompoundTableModelEvent()
          Creates a CompoundTableModelEvent instance.
protected  Row createWrappedRow(ExpandableRow originalRow)
          Creates wrapped row in the wrapped ITreeTableModel.
 void fireTableCellsUpdated(int firstRow, int lastRow, int column)
          Called each time the cells in column in the range [firstRow, lastRow] are updated.
 void fireTableChanged(TableModelEvent e)
           
 int getActualColumnAt(int column)
          Gets the actual column.
 TableModel getActualModel()
          Gets the actual table model.
 Class<?> getCellClassAt(int row, int column)
          Gets the cell class of the underlying table model.
 CellSpan getCellSpanAt(int rowIndex, int columnIndex)
          Gets the cell span at the specified row and column.
 CellStyle getCellStyleAt(int rowIndex, int columnIndex)
          Gets the cell style at the specified row and column.
 Class<?> getColumnClass(int column)
           
 int getColumnCount()
           
 Object getColumnIdentifier(int column)
          Returns the identifier of the column in the model.
 String getColumnName(int column)
           
 int getColumnType(int columnIndex)
          Checks if the column at the columnIndex is a header column or footer column or just regular column.
 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[] getIndexes()
          Gets the indexes that maps from the visual column index to the actual column index.
 Object getRoot()
          Gets the root expandable row which has the original rows as children.
 Row getRowAt(int rowIndex)
          Returns the row at row specified by row.
 int getRowCount()
           
 int getRowIndex(Row row)
          Gets the index of the row.
 int getTableIndex(int columnIndex)
          Gets the table index that this column belongs to.
 Object getValueAt(int row, int column)
           
 int getVisualColumnAt(int actualColumn)
          Gets the visual column.
 boolean isCellEditable(int row, int column)
           
 boolean isCellSpanOn()
          Checks if the span is on.
 boolean isCellStyleOn()
          Checks if the style is on.
protected  void reallocateIndexes()
          Resets the index mapping.
 void setIndexes(int[] indexes)
          Sets the indexes of the column 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.
 void tableChanged(TableModelEvent e)
          Implementation of the TableChangeListener interface.
protected  void tableDataChanged()
          Called each time all of the data (i.e.
protected  void tableDataChanged(CompoundTableModelEvent event)
           
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 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
 

Field Detail

_model

protected TableModel _model

_indexes

protected int[] _indexes
Constructor Detail

DefaultColumnTableModelWrapper

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

Parameters:
model - the table model
Method Detail

getActualModel

public TableModel getActualModel()
Gets the actual table model. Since ColumnTableModelWrapper is just a wrapper around another table model, this method will return you the actual table model.

Specified by:
getActualModel in interface TableModelWrapper
Returns:
the actual table model.

getActualColumnAt

public int getActualColumnAt(int column)
Gets the actual column.

Specified by:
getActualColumnAt in interface ColumnTableModelWrapper
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 int getVisualColumnAt(int actualColumn)
Gets the visual column.

Specified by:
getVisualColumnAt in interface ColumnTableModelWrapper
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

setValueAt

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

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 column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

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

isCellEditable

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

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
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
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 null.

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

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
Parameters:
column - the index of the column
Returns:
the unique identifier of the column.

reallocateIndexes

protected void reallocateIndexes()
Resets the index mapping.


getIndexes

public int[] getIndexes()
Gets the indexes that maps from the visual column index to the actual column index.

Returns:
the indexes.

setIndexes

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

Parameters:
indexes - the new index array.

getCellStyleAt

public CellStyle getCellStyleAt(int rowIndex,
                                int columnIndex)
Description copied from interface: StyleModel
Gets the cell style at the specified row and column.

Specified by:
getCellStyleAt in interface StyleModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
CellStyle object.

isCellStyleOn

public boolean isCellStyleOn()
Description copied from interface: StyleModel
Checks if the style is on. The CellStyleTable will ignore all the CellStyles defined in this model if this method returns false.

Specified by:
isCellStyleOn in interface StyleModel
Returns:
true if style is on. Otherwise false.

getCellSpanAt

public CellSpan getCellSpanAt(int rowIndex,
                              int columnIndex)
Description copied from interface: SpanModel
Gets the cell span at the specified row and column. To avoid creating many instances of CellSpan, you can return the same instance by changing its values only. For example, the code below is a good example.

 private final CellSpan span = new CellSpan(0,0,1,1);
 public CellSpan getCellSpanAt(int row, int col) {
     span.setRow(...);
     span.setColumn(...);
     span.setRowSpan(...);
     span.setColumnSpan(...);
     return span;
 }
 
For performance consideration, if the cell span has 1 row span and 1 column span, it is better to return null instead of new CellSpan(row, column, 1, 1).

Specified by:
getCellSpanAt in interface SpanModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
CellSpan object.

isCellSpanOn

public boolean isCellSpanOn()
Description copied from interface: SpanModel
Checks if the span is on. The CellSpanTable will ignore all the CellSpans defined in this model if this method returns false.

Since 3.5.12, please fire table data changed event if the returned value of this method is changed. Otherwise the CellSpanTable might still use the cached value to improve performance.

Specified by:
isCellSpanOn in interface SpanModel
Returns:
true if span is on. Otherwise false.

getColumnType

public int getColumnType(int columnIndex)
Description copied from interface: MultiTableModel
Checks if the column at the columnIndex is a header column or footer column or just regular column. Header columns will be displayed at the left side of the table. Footer columns will be on the right side. Regular columns will in the middle and will have horizontal scroll bar if there are a lot of columns.

Specified by:
getColumnType in interface MultiTableModel
Parameters:
columnIndex - the column index
Returns:
column type. The possible values are REGULAR_COLUMN, HEADER_COLUMN, or FOOTER_COLUMN.

getTableIndex

public int getTableIndex(int columnIndex)
Description copied from interface: MultiTableModel
Gets the table index that this column belongs to. As convention, the table index starts from 0. So all columns that return 0 in this method will be grouped into the first table. Those return 1 will be on the second table, and so on.

Specified by:
getTableIndex in interface MultiTableModel
Parameters:
columnIndex - the column index
Returns:
the table index.

tableChanged

public void tableChanged(TableModelEvent e)
Implementation of the TableChangeListener interface. Depending on the type of the TableModelEvent, this method delegates to one of the following methods based on the contract of the TableModelEvent object:

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.

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.

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.

Parameters:
firstRow - the index of the first row that was updated
lastRow - the index of the last row that was updated

fireTableCellsUpdated

public void fireTableCellsUpdated(int firstRow,
                                  int lastRow,
                                  int column)
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.

Parameters:
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
column - the index of the column 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.

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)

createCompoundTableModelEvent

protected CompoundTableModelEvent createCompoundTableModelEvent()
Creates a CompoundTableModelEvent instance.

Returns:
the CompoundTableModelEvent instance.

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.


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.


fireTableChanged

public void fireTableChanged(TableModelEvent e)
Overrides:
fireTableChanged in class AbstractTableModel

getRowAt

public Row getRowAt(int rowIndex)
Description copied from interface: ITreeTableModel
Returns the row at row specified by row.

Specified by:
getRowAt in interface ITreeTableModel
Parameters:
rowIndex - the row whose row is to be queried
Returns:
the row at the specified row index

createWrappedRow

protected Row createWrappedRow(ExpandableRow originalRow)
Creates wrapped row in the wrapped ITreeTableModel.

Parameters:
originalRow - the original row in the wrapped ITreeTableModel
Returns:
the wrapped row instance.
Since:
3.4.1

getRowIndex

public int getRowIndex(Row row)
Description copied from interface: ITreeTableModel
Gets the index of the row.

Specified by:
getRowIndex in interface ITreeTableModel
Parameters:
row - row
Returns:
the index of the row. If the row is displayed in the table, it will return the index. Otherwise, it will return -1. So -1 could mean two things - the row is not displayed or the row is not in the tree hierarchy at all.

getRoot

public Object getRoot()
Description copied from interface: ITreeTableModel
Gets the root expandable row which has the original rows as children.

Specified by:
getRoot in interface ITreeTableModel
Returns:
the root expandable row.

JIDE 3.5.15