Package jadex.commons.gui.jtable
Class VisibilityTableColumnModel
- java.lang.Object
-
- javax.swing.table.DefaultTableColumnModel
-
- jadex.commons.gui.jtable.VisibilityTableColumnModel
-
- All Implemented Interfaces:
IVisibilityTableColumnModel
,java.beans.PropertyChangeListener
,java.io.Serializable
,java.util.EventListener
,javax.swing.event.ListSelectionListener
,javax.swing.table.TableColumnModel
public class VisibilityTableColumnModel extends javax.swing.table.DefaultTableColumnModel implements IVisibilityTableColumnModel
VisibilityTableColumnModel
extends the DefaultTableColumnModel . It provides a comfortable way to hide/show columns. Columns keep their positions when hidden and shown again. In order to work with JTable it cannot add any events toTableColumnModelListener
. Therefore hiding a column will result incolumnRemoved
event and showing it again will notify listeners of acolumnAdded
, and possibly acolumnMoved
event. For the same reason the following methods still deal with visible columns only: getColumnCount(), getColumns(), getColumnIndex(), getColumn() If you want to take invisible column into account use: getAllColumnCount(), getAllColumns(), getAllColumnIndex(), getAllColumn()- See Also:
DefaultTableColumnModel
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Vector
allTableColumns
Array of TableColumn objects in this model.protected java.util.Vector
tableColumnsFixed
Array of TableColumn objects that cannot change the visibility.
-
Constructor Summary
Constructors Constructor Description VisibilityTableColumnModel()
Creates an extended table column model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColumn(javax.swing.table.TableColumn column)
AppendsaColumn
to the end of thetableColumns
array.void
addMouseListener(javax.swing.JTable table)
Helper method that adds a mouselistener to the header of a givenJTable
.javax.swing.table.TableColumn
getAllColumn(int columnIndex)
Returns theTableColumn
object for the column atcolumnIndex
.int
getAllColumnCount()
Returns the number of columns in the model.int
getAllColumnIndex(java.lang.Object identifier)
Returns the index of the first column in the table whose identifier is equal toidentifier
, when compared usingequals
.java.util.Enumeration
getAllColumns()
Returns anEnumeration
of all the columns in the model.boolean
isColumnChangeable(javax.swing.table.TableColumn column)
Checks whether the specified column can change visibility.boolean
isColumnVisible(javax.swing.table.TableColumn aColumn)
Checks whether the specified column is currently visible.void
moveColumn(int columnIndex, int newIndex)
Moves the column and its header atcolumnIndex
tonewIndex
.void
removeColumn(javax.swing.table.TableColumn column)
Deletes theTableColumn
column
from thetableColumns
array.void
setAllColumnsVisible()
Makes all columns in this model visiblevoid
setColumnChangeable(javax.swing.table.TableColumn column, boolean changeable)
Sets whether this column can change visibility.void
setColumnVisible(javax.swing.table.TableColumn column, boolean visible)
Sets the visibility of the specified TableColumn.-
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
-
-
-
-
Field Detail
-
allTableColumns
protected java.util.Vector allTableColumns
Array of TableColumn objects in this model. Holds all column objects, regardless of their visibility
-
tableColumnsFixed
protected java.util.Vector tableColumnsFixed
Array of TableColumn objects that cannot change the visibility. By default this array is empty
-
-
Method Detail
-
addColumn
public void addColumn(javax.swing.table.TableColumn column)
AppendsaColumn
to the end of thetableColumns
array. This method posts acolumnAdded
event to its listeners.- Specified by:
addColumn
in interfacejavax.swing.table.TableColumnModel
- Overrides:
addColumn
in classjavax.swing.table.DefaultTableColumnModel
- Parameters:
column
- theTableColumn
to be added- See Also:
DefaultTableColumnModel.addColumn(javax.swing.table.TableColumn)
-
removeColumn
public void removeColumn(javax.swing.table.TableColumn column)
Deletes theTableColumn
column
from thetableColumns
array. This method will do nothing ifcolumn
is not in the table's column list. This method posts acolumnRemoved
event to its listeners.- Specified by:
removeColumn
in interfacejavax.swing.table.TableColumnModel
- Overrides:
removeColumn
in classjavax.swing.table.DefaultTableColumnModel
- Parameters:
column
- theTableColumn
to be removed- See Also:
DefaultTableColumnModel.removeColumn(javax.swing.table.TableColumn)
-
moveColumn
public void moveColumn(int columnIndex, int newIndex)
Moves the column and its header atcolumnIndex
tonewIndex
. The old column atcolumnIndex
will now be found atnewIndex
. The column that used to be atnewIndex
is shifted left or right to make room. This will not move any columns ifcolumnIndex
equalsnewIndex
. This method posts acolumnMoved
event to its listeners.- Specified by:
moveColumn
in interfacejavax.swing.table.TableColumnModel
- Overrides:
moveColumn
in classjavax.swing.table.DefaultTableColumnModel
- Parameters:
columnIndex
- the index of column to be movednewIndex
- index of the column's new location- Throws:
java.lang.IllegalArgumentException
- ifcolumnIndex
ornewIndex
are not in the valid range- See Also:
DefaultTableColumnModel.moveColumn(int, int)
-
getAllColumnCount
public int getAllColumnCount()
Returns the number of columns in the model.
- Specified by:
getAllColumnCount
in interfaceIVisibilityTableColumnModel
- Returns:
- the number of columns in the model
-
getAllColumns
public java.util.Enumeration getAllColumns()
Returns anEnumeration
of all the columns in the model.
- Specified by:
getAllColumns
in interfaceIVisibilityTableColumnModel
- Returns:
- an
Enumeration
of all the columns in the model
-
getAllColumnIndex
public int getAllColumnIndex(java.lang.Object identifier)
Returns the index of the first column in the table whose identifier is equal toidentifier
, when compared usingequals
.
- Specified by:
getAllColumnIndex
in interfaceIVisibilityTableColumnModel
- Parameters:
identifier
- the identifier object- Returns:
- the index of the first table column
whose identifier is equal to
identifier
- Throws:
java.lang.IllegalArgumentException
- ifidentifier
isnull
, or noTableColumn
has thisidentifier
- See Also:
getAllColumn(int)
-
getAllColumn
public javax.swing.table.TableColumn getAllColumn(int columnIndex)
Returns theTableColumn
object for the column atcolumnIndex
.
- Specified by:
getAllColumn
in interfaceIVisibilityTableColumnModel
- Parameters:
columnIndex
- the index of the desired column- Returns:
- the
TableColumn
object for the column atcolumnIndex
-
setColumnVisible
public void setColumnVisible(javax.swing.table.TableColumn column, boolean visible)
Sets the visibility of the specified TableColumn. The call is ignored if the TableColumn is not found in this column model or its visibility status did not change. This method posts acolumnAdded
orcolumnRemoved
event to its listeners.- Specified by:
setColumnVisible
in interfaceIVisibilityTableColumnModel
- Parameters:
column
- theTableColumn
visible
- its new visibility status
-
setAllColumnsVisible
public void setAllColumnsVisible()
Makes all columns in this model visible- Specified by:
setAllColumnsVisible
in interfaceIVisibilityTableColumnModel
- See Also:
isColumnVisible(javax.swing.table.TableColumn)
,setColumnVisible(javax.swing.table.TableColumn, boolean)
-
isColumnVisible
public boolean isColumnVisible(javax.swing.table.TableColumn aColumn)
Checks whether the specified column is currently visible.- Specified by:
isColumnVisible
in interfaceIVisibilityTableColumnModel
- Parameters:
aColumn
- column to check- Returns:
- visibility of specified column. false if there is no such column at all.
- See Also:
setAllColumnsVisible()
,setColumnVisible(javax.swing.table.TableColumn, boolean)
-
setColumnChangeable
public void setColumnChangeable(javax.swing.table.TableColumn column, boolean changeable)
Sets whether this column can change visibility.- Specified by:
setColumnChangeable
in interfaceIVisibilityTableColumnModel
- Parameters:
column
- theTableColumn
changeable
- if true, changing visibility is allowed; otherwise false
-
isColumnChangeable
public boolean isColumnChangeable(javax.swing.table.TableColumn column)
Checks whether the specified column can change visibility.- Specified by:
isColumnChangeable
in interfaceIVisibilityTableColumnModel
- Parameters:
column
- column to check- Returns:
- true if the column can change visibility; otherwise false
-
addMouseListener
public void addMouseListener(javax.swing.JTable table)
Helper method that adds a mouselistener to the header of a givenJTable
. On right click a popup menu will appear to change the visibility of the columns in the jtable- Parameters:
table
- theJTable
to add the mouselistener to its header
-
-