org.tentackle.ui
Class FormTableColumnModel

java.lang.Object
  extended by javax.swing.table.DefaultTableColumnModel
      extended by org.tentackle.ui.FormTableColumnModel
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, ListSelectionListener, TableColumnModel

public class FormTableColumnModel
extends DefaultTableColumnModel

Extended table column model.
Adds the feature to display/hide a column by model index.

Author:
harald
See Also:
Serialized Form

Field Summary
protected  Vector<TableColumn> originalColumns
          all columns whether visible or not are stored here.
 
Fields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
 
Constructor Summary
FormTableColumnModel()
          Creates a formtable column model.
This is the standard constructor with no columns displayed.
 
Method Summary
 void addColumn(TableColumn aColumn)
          Appends aColumn to the end of the tableColumns array.
 TableColumn getColumnByModelIndex(int modelIndex)
          Gets the column for the given data-modelindex
 int[] getModelIndexes()
          Gets all model indexes sorted according to the current view.
The invisible columns come last.
 TableColumn getOriginalColumn(int originalIndex)
          Gets the original column at a given model index
 Enumeration getOriginalColumns()
          Gets all original columns.
 int getOriginalIndex(int visibleIndex)
          Maps between the visible and model indexes.
 int getOriginalIndex(TableColumn column)
          Returns the original index of a table column.
 boolean isModelColumnVisible(int modelIndex)
          Checks if a column is visible.
 boolean isOriginalColumnVisible(int originalIndex)
          Checks if a column is visible.
 void moveColumn(int columnIndex, int newIndex)
          Moves the column and heading at columnIndex to newIndex.
 void removeAllColumns()
          Removes all columns, original and visible.
 void removeColumn(TableColumn column)
          Deletes the column from the tableColumns array.
 void reorderColumns(int[] modelIndexes)
          Reorders columns according an array of ints.
The index in the array is the column index, whereas the value is the data-model index.
 void setModelColumnVisible(int modelIndex, boolean visible)
          Same as setOriginalColumn but index corresponds to the data-model (model-index).
 void setOriginalColumnVisible(int originalIndex, boolean visible)
          Sets a column invisible/visible.
Removes/adds the column from/to the underlying vector but keeps it in the original vector.
 
Methods inherited from class javax.swing.table.DefaultTableColumnModel
addColumnModelListener, createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, propertyChange, recalcWidthCache, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

originalColumns

protected Vector<TableColumn> originalColumns
all columns whether visible or not are stored here. The superclass holds the visible columns only.

Constructor Detail

FormTableColumnModel

public FormTableColumnModel()
Creates a formtable column model.
This is the standard constructor with no columns displayed. Columns must be added via addColumn(javax.swing.table.TableColumn).

Method Detail

getOriginalIndex

public int getOriginalIndex(TableColumn column)
Returns the original index of a table column.

Parameters:
column - the table column
Returns:
the original column index

getOriginalIndex

public int getOriginalIndex(int visibleIndex)
Maps between the visible and model indexes.

Parameters:
visibleIndex - the visible index
Returns:
the model index

getOriginalColumn

public TableColumn getOriginalColumn(int originalIndex)
Gets the original column at a given model index

Parameters:
originalIndex - the original model index
Returns:
the table column

getOriginalColumns

public Enumeration getOriginalColumns()
Gets all original columns.

Returns:
the columns

getColumnByModelIndex

public TableColumn getColumnByModelIndex(int modelIndex)
Gets the column for the given data-modelindex

Parameters:
modelIndex - the data model index
Returns:
the table column

addColumn

public void addColumn(TableColumn aColumn)
Description copied from class: javax.swing.table.DefaultTableColumnModel
Appends aColumn to the end of the tableColumns array. This method also posts the columnAdded event to its listeners.

Specified by:
addColumn in interface TableColumnModel
Overrides:
addColumn in class DefaultTableColumnModel
Parameters:
aColumn - the TableColumn to be added
See Also:
DefaultTableColumnModel.removeColumn(javax.swing.table.TableColumn)

removeColumn

public void removeColumn(TableColumn column)
Description copied from class: javax.swing.table.DefaultTableColumnModel
Deletes the column from the tableColumns array. This method will do nothing if column is not in the table's columns list. tile is called to resize both the header and table views. This method also posts a columnRemoved event to its listeners.

Specified by:
removeColumn in interface TableColumnModel
Overrides:
removeColumn in class DefaultTableColumnModel
Parameters:
column - the TableColumn to be removed
See Also:
DefaultTableColumnModel.addColumn(javax.swing.table.TableColumn)

removeAllColumns

public void removeAllColumns()
Removes all columns, original and visible.


moveColumn

public void moveColumn(int columnIndex,
                       int newIndex)
Moves the column and heading at columnIndex to newIndex. The old column at columnIndex will now be found at newIndex. The column that used to be at newIndex is shifted left or right to make room. This will not move any columns if columnIndex equals newIndex. This method also posts a columnMoved event to its listeners.

Overridden to move a column according to the visible index.
The columns in the "original"-space are moved accordingly.

Specified by:
moveColumn in interface TableColumnModel
Overrides:
moveColumn in class DefaultTableColumnModel
Parameters:
columnIndex - the index of column to be moved
newIndex - new index to move the column

isOriginalColumnVisible

public boolean isOriginalColumnVisible(int originalIndex)
Checks if a column is visible.

Parameters:
originalIndex - the original column index
Returns:
true if visible
See Also:
isModelColumnVisible(int)

isModelColumnVisible

public boolean isModelColumnVisible(int modelIndex)
Checks if a column is visible.

Parameters:
modelIndex - the model index
Returns:
true if visible
See Also:
isOriginalColumnVisible(int)

setOriginalColumnVisible

public void setOriginalColumnVisible(int originalIndex,
                                     boolean visible)
Sets a column invisible/visible.
Removes/adds the column from/to the underlying vector but keeps it in the original vector. The index used is the original index, i.e. the columns as if they were ALL visible.

Parameters:
originalIndex - the column index
visible - true to set visible, false to set invisible
See Also:
setModelColumnVisible(int, boolean)

setModelColumnVisible

public void setModelColumnVisible(int modelIndex,
                                  boolean visible)
Same as setOriginalColumn but index corresponds to the data-model (model-index).

Parameters:
modelIndex - the model column index
visible - true to set visible, false to set invisible
See Also:
setOriginalColumnVisible(int, boolean)

reorderColumns

public void reorderColumns(int[] modelIndexes)
Reorders columns according an array of ints.
The index in the array is the column index, whereas the value is the data-model index. All columns in modelIndexes[] are visible afterwards! Any columns in originalColumns not in modelIndexes[] will be removed!

Parameters:
modelIndexes - the column indexes

getModelIndexes

public int[] getModelIndexes()
Gets all model indexes sorted according to the current view.
The invisible columns come last.

Returns:
the column indexes (model index)


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de