JIDE 3.5.15

com.jidesoft.grid
Class JoinTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.jidesoft.grid.JoinTableModel
All Implemented Interfaces:
ColumnIdentifierTableModel, ContextSensitiveTableModel, MultiTableModel, NavigableModel, SpanModel, StyleModel, TableModelsWrapper, Serializable, TableModel
Direct Known Subclasses:
AggregateTableModel

public class JoinTableModel
extends AbstractTableModel
implements ColumnIdentifierTableModel, ContextSensitiveTableModel, SpanModel, StyleModel, NavigableModel, MultiTableModel, TableModelsWrapper

JoinTableModel joints several table models horizontally. Although all the table models can have different row counts, it makes more sense if they have same row counts. JoinTableModel will take care of the table events fired from those models and translate them to the correct table model event for JoinTableModel. It supports SpanModel, StyleModel and ContextSensitiveTableModel as well. It supports MultiTableModel too. The first table model will be the header table model, the second model to be the main table model and the third table model will be the footer table model. All models after the first three models will be ignored in this case.

See Also:
Serialized Form

Field Summary
protected  List<TableModel> _models
           
 
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
JoinTableModel()
          Creates an empty JoinTableModel.
JoinTableModel(TableModel[] models)
          Creates an JoinTableModel that joins the table models in the array.
 
Method Summary
 void addTableModel(TableModel model)
          Adds a table model at the end of the JoinTableModel.
 void addTableModel(TableModel model, int index)
          Inserts a table model at the specified index of the JoinTableModel.
 TableModel getActualModel(int rowIndex, int columnIndex)
          Gets the table model which contains the specific column index.
 Class<?> getCellClassAt(int rowIndex, int columnIndex)
          Overrides to return the getCellClassAt from the underlying table models, of course, only when the underlying table model is ContextSensitiveTableModel.
 CellSpan getCellSpanAt(int rowIndex, int columnIndex)
          Overrides to return the CellSpan from the underlying table models, of course, only when the underlying table model is SpanModel and isCellSpanOn is true.
 CellStyle getCellStyleAt(int rowIndex, int columnIndex)
          Overrides to return the CellStyle from the underlying table models, of course, only when the underlying table model is StyleModel and isCellStyleOn is true.
 Class<?> getColumnClass(int columnIndex)
          Overrides to return the getColumnClass from the underlying table models.
 int getColumnCount()
          Gets the total number of column count.
 Object getColumnIdentifier(int columnIndex)
          Returns the identifier of the column in the model.
 String getColumnName(int columnIndex)
          Overrides to return the getColumnName from the underlying table models.
 int getColumnType(int columnIndex)
          Gets the column type in MultiTableModel.
 ConverterContext getConverterContextAt(int rowIndex, int columnIndex)
          Overrides to return the getConverterContextAt from the underlying table models, of course, only when the underlying table model is ContextSensitiveTableModel.
 EditorContext getEditorContextAt(int rowIndex, int columnIndex)
          Overrides to return the getEditorContextAt from the underlying table models, of course, only when the underlying table model is ContextSensitiveTableModel.
 int getRowCount()
          Gets the total number of row count.
 int getTableIndex(int columnIndex)
          Get the table index.
 TableModel getTableModel(int index)
          Gets the table model at the specific index.
 int getTableModelCount()
          Gets the number of table models in the JoinTableModel.
 Object getValueAt(int rowIndex, int columnIndex)
          Overrides to return the getValueAt from the underlying table models.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Overrides to return the isCellEditable from the underlying table models.
 boolean isCellSpanOn()
          Overrides to return true if any of the underlying table models is SpanModel and the isCellSpanOn is true.
 boolean isCellStyleOn()
          Overrides to return true if any of the underlying table models is StyleModel and the isCellStyleOn is true.
 boolean isNavigableAt(int rowIndex, int columnIndex)
          Overrides to return true or false depending on the child table models.
 boolean isNavigationOn()
          Overrides to return true if any of the underlying table models is StyleModel and the isNavigableOn is true.
 void removeAllTableModels()
          Removes all table models.
 void removeTableModel(TableModel model)
          Removes a table model from the JoinTableModel.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          Overrides to call setValueAt of the underlying table models to set the value.
 
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
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

_models

protected List<TableModel> _models
Constructor Detail

JoinTableModel

public JoinTableModel()
Creates an empty JoinTableModel.


JoinTableModel

public JoinTableModel(TableModel[] models)
Creates an JoinTableModel that joins the table models in the array.

Parameters:
models - an array of table models to be joined.
Method Detail

addTableModel

public void addTableModel(TableModel model)
Adds a table model at the end of the JoinTableModel.

Parameters:
model - the model to be added.

addTableModel

public void addTableModel(TableModel model,
                          int index)
Inserts a table model at the specified index of the JoinTableModel.

Parameters:
model - the model to be added.
index - the index where the model will be inserted.

removeTableModel

public void removeTableModel(TableModel model)
Removes a table model from the JoinTableModel.

Parameters:
model - the model to be removed.

removeAllTableModels

public void removeAllTableModels()
Removes all table models.


getTableModelCount

public int getTableModelCount()
Gets the number of table models in the JoinTableModel.

Returns:
the number of table models in the JoinTableModel.

getTableModel

public TableModel getTableModel(int index)
Gets the table model at the specific index. The index matches with the order when the table model is added. For example, the first added table model index is 0. getTableModel(0) will return that index. Of course, the order could change if addTableModel(javax.swing.table.TableModel,int) is used.

Parameters:
index - the index.
Returns:
the table model at the index.

getColumnIdentifier

public Object getColumnIdentifier(int columnIndex)
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:
columnIndex - the index of the column
Returns:
the unique identifier of the column.

getColumnClass

public Class<?> getColumnClass(int columnIndex)
Overrides to return the getColumnClass from the underlying table models.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
columnIndex - the column index.
Returns:
the column class for the column.

getColumnName

public String getColumnName(int columnIndex)
Overrides to return the getColumnName from the underlying table models.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
columnIndex - the column index.
Returns:
the column name for the column.

isCellEditable

public final boolean isCellEditable(int rowIndex,
                                    int columnIndex)
Overrides to return the isCellEditable from the underlying table models.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
true or false.

getColumnCount

public int getColumnCount()
Gets the total number of column count. It is the sum of all table models' column count.

Specified by:
getColumnCount in interface TableModel
Returns:
the total number of column count.

getRowCount

public int getRowCount()
Gets the total number of row count. It is the max of all table models' row count.

Specified by:
getRowCount in interface TableModel
Returns:
the total number of row count.

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Overrides to return the getValueAt from the underlying table models.

Specified by:
getValueAt in interface TableModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
the value at the specified row and column index.

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Overrides to call setValueAt of the underlying table models to set the value.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
aValue - the new value at the specified row and column index.

getActualModel

public TableModel getActualModel(int rowIndex,
                                 int columnIndex)
Gets the table model which contains the specific column index. For example, if we have three table models that have 4, 3, 5 columns respectively. getTableModelForColumn(0 to 3) will return the first model. getTableModelForColumn(4 to 6) will return the second model. getTableModelForColumn(7 to 11) will return the second model. If the column index is less than 0 or greater than 11, null will be returned.

Specified by:
getActualModel in interface TableModelsWrapper
Parameters:
columnIndex - the column index
rowIndex - the row index.
Returns:
the table model which contains the specific column index.

getConverterContextAt

public ConverterContext getConverterContextAt(int rowIndex,
                                              int columnIndex)
Overrides to return the getConverterContextAt from the underlying table models, of course, only when the underlying table model is ContextSensitiveTableModel. Otherwise null will be returned.

Specified by:
getConverterContextAt in interface ContextSensitiveTableModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
the ConverterContext at the specified row and column index.

getEditorContextAt

public EditorContext getEditorContextAt(int rowIndex,
                                        int columnIndex)
Overrides to return the getEditorContextAt from the underlying table models, of course, only when the underlying table model is ContextSensitiveTableModel. Otherwise null will be returned.

Specified by:
getEditorContextAt in interface ContextSensitiveTableModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
the EditorContext at the specified row and column index.

getCellClassAt

public Class<?> getCellClassAt(int rowIndex,
                               int columnIndex)
Overrides to return the getCellClassAt from the underlying table models, of course, only when the underlying table model is ContextSensitiveTableModel. Otherwise null will be returned.

Specified by:
getCellClassAt in interface ContextSensitiveTableModel
Parameters:
rowIndex - the row index.
columnIndex - the column index.
Returns:
the CellClass at the specified row and column index.

getCellSpanAt

public CellSpan getCellSpanAt(int rowIndex,
                              int columnIndex)
Overrides to return the CellSpan from the underlying table models, of course, only when the underlying table model is SpanModel and isCellSpanOn is true. Otherwise null will be returned.

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

isCellSpanOn

public boolean isCellSpanOn()
Overrides to return true if any of the underlying table models is SpanModel and the isCellSpanOn is true.

Specified by:
isCellSpanOn in interface SpanModel
Returns:
return true if any of the underlying table models is SpanModel and the isCellSpanOn is true. Otherwise false.

getCellStyleAt

public CellStyle getCellStyleAt(int rowIndex,
                                int columnIndex)
Overrides to return the CellStyle from the underlying table models, of course, only when the underlying table model is StyleModel and isCellStyleOn is true. Otherwise null will be returned.

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

isCellStyleOn

public boolean isCellStyleOn()
Overrides to return true if any of the underlying table models is StyleModel and the isCellStyleOn is true.

Specified by:
isCellStyleOn in interface StyleModel
Returns:
return true if any of the underlying table models is StyleModel and the isCellStyleOn is true. Otherwise false.

isNavigableAt

public boolean isNavigableAt(int rowIndex,
                             int columnIndex)
Overrides to return true or false depending on the child table models.

Specified by:
isNavigableAt in interface NavigableModel
Parameters:
rowIndex - the row index
columnIndex - the column index
Returns:
if the cell is navigable.

isNavigationOn

public boolean isNavigationOn()
Overrides to return true if any of the underlying table models is StyleModel and the isNavigableOn is true.

Specified by:
isNavigationOn in interface NavigableModel
Returns:
return true if any of the underlying table models is StyleModel and the isNavigableOn is true. Otherwise false.

getColumnType

public int getColumnType(int columnIndex)
Gets the column type in MultiTableModel. The returned value is limited to the first three table model. If you need something different, you would need to override it to return something else.

Specified by:
getColumnType in interface MultiTableModel
Parameters:
columnIndex - the column index.
Returns:
HEADER_COLUMN if the column index is part of the first table model, REGULAR_COLUMN if the column index is part of the second table model and FOOTER_COLUMN if the column index is part of the third table model.

getTableIndex

public int getTableIndex(int columnIndex)
Get the table index. This is a method MultiTableModel index. It always return 0. If you need something different, you would need to override it to return something else.

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

JIDE 3.5.15