com.pcauto.gui.table
Interface EntityTableColumnModel

All Superinterfaces:
javax.swing.table.TableColumnModel
All Known Implementing Classes:
AbstractEntityTableColumnModel

public interface EntityTableColumnModel
extends javax.swing.table.TableColumnModel

The EntityTableColumnModel interface describes the model that defines the behaviour of columns in an EntityTable. If default behaviour is required, developers should subclass AbstractEntityTableColumnModel to quickly get an implementation of this EntityTableColumnModel interface.

The EntityTableColumnModel defines column properties including the datatypes, editors, and attributes associated with each column, such as sortability and column order. This EntityTableColumnModel defines the mapping between an entity and all columns. Once an EntityList which manages entities, and an EntityTableColumnModel have been provided, the data can be rendered in an EntityTable. To link the entity to this EntityTableColumnModel, the getCellValue(int,Object) and setCellValue(int,Object,Object) functions need to be implemented to work with the entity.

Some methods such as getCellValue(int,Object) require both a column index and an entity object. The index is used to identify the column for which the cell value is being requested. The first column is at index 0. The entity Object is required because it contains the data for the row.

Since the user is able to move columns and columns can be locked, the actual order of the columns in the table may be different from the order of the columns in this EntityTableColumnModel. The column index that must be used for methods in this EntityTableColumnModel is the logical index that represents the columns in the order they were added to this EntityTableColumnModel. For information about locking and other column attributes see EntityTableColumn.

Some examples of the functionality that this class provides include:


Method Summary
 void addColumn(EntityTableColumn c)
          Adds the given EntityTableColumn to the right-side of the table.
 EntityTableColumn getByName(java.lang.String name)
          Returns the column with the specified name.
 java.lang.Object getCellValue(int col, java.lang.Object entity)
          Returns an Object containing the cell value at the given column number for a specified entity.
 java.lang.Class getColumnClass(int col)
          Returns the column class specified by the col parameter.
 int getColumnCount()
          Returns the number of columns in this EntityTableColumnModel.
 java.lang.String getColumnName(int col)
          Returns the name for the specified column.
 int getRealColumnCount()
          Returns the number of visible columns.
 boolean hasEditableColumns()
          Returns true if the table has any editable columns, false otherwise.
 boolean isEditable(int col)
          Returns true if the specified column is editable, false otherwise.
 boolean isHidden(int col)
          Returns true if the specified column is hidden, false otherwise.
 boolean isLocked(int col)
          Returns true if the specified column is locked, false otherwise.
 boolean isRightAlignmentSortable(int col)
          Returns true if the specified column is right alignment sortable, false otherwise.
 boolean isSortable(int col)
          Returns true if the specified column is sortable, false otherwise.
 void removeColumn(int col)
          Removes the specified column from the table.
 void setCellValue(int col, java.lang.Object entity, java.lang.Object value)
          Changes the specified entity to store the specified value based on the column index.
 void setEditable(int col, boolean newValue)
          Sets the specified column to be editable or not.
 void setHidden(int col, boolean newValue)
          Sets a specified column to be hidden or visible.
 void setLocked(int col, boolean newValue)
          Locks or unlocks the specified column.
 void setRightAlignmentSortable(int col, boolean newValue)
          Sets right alignment sortability for the specified column.
 void setSortable(int col, boolean newValue)
          Enables or disables sorting on the specified colum.
 
Methods inherited from interface javax.swing.table.TableColumnModel
addColumn, addColumnModelListener, getColumn, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumns, getColumnSelectionAllowed, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, moveColumn, removeColumn, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel
 

Method Detail

getCellValue

public java.lang.Object getCellValue(int col,
                                     java.lang.Object entity)
Returns an Object containing the cell value at the given column number for a specified entity. The column index starts at 0. If there is no cell defined at the given column, null is returned. The column index is used to identify the value required from the entity. Entity objects can be created by the developer so we accept any Object here.

Parameters:
col - the column number
entity - the Object to retrieve the value from. This is typically a row entity.
Returns:
the value of the cell

setCellValue

public void setCellValue(int col,
                         java.lang.Object entity,
                         java.lang.Object value)
Changes the specified entity to store the specified value based on the column index. The index of the first column is 0.

Parameters:
col - the column where the cell is located
entity - the Object the cell is located in. This is represented as a row in the table.
value - the Object which is the new value

isLocked

public boolean isLocked(int col)
Returns true if the specified column is locked, false otherwise. If enabled, the column is displayed even if the user pans across the table. The first column is at index 0.

Parameters:
col - the column index
Returns:
true if locked, false otherwise

setLocked

public void setLocked(int col,
                      boolean newValue)
Locks or unlocks the specified column. If enabled, the column is displayed even if the user pans across the table. The first column is at index 0.

Parameters:
col - the column index
newValue - locked if true, unlocked if false

isSortable

public boolean isSortable(int col)
Returns true if the specified column is sortable, false otherwise. If enabled, then rows can be sorted according to this column, otherwise they can't be. The usual implementation for this is double clicking on the column header in the table once sorting has been enabled to sort the rows according to that column. The typical implementation also sorts in alternating ascending and descending order once the column has been double clicked once to perform the initial sort. What this means is the column can be double clicked repetedly and sorting will switch between ascending and descending order. The first column is at index 0.

Parameters:
col - the column index
Returns:
true if sortable, false otherwise

setSortable

public void setSortable(int col,
                        boolean newValue)
Enables or disables sorting on the specified colum. If enabled, then rows can be sorted according to this column, otherwise they can't be. The usual implementation for this is double clicking on the column header in the table once sorting has been enabled to sort the rows according to that column. The typical implementation also sorts in alternating ascending and descending order once the column has been double clicked once to perform the initial sort. What this means is the column can be double clicked repetedly and sorting will switch between ascending and descending order. The first column is at index 0.

Parameters:
col - the column index
newValue - sortable if true, not sortable if false

isHidden

public boolean isHidden(int col)
Returns true if the specified column is hidden, false otherwise. If it is hidden then it is invisible to the user. The first column is at index 0.

Parameters:
col - the column index
Returns:
true if hidden, false otherwise

setHidden

public void setHidden(int col,
                      boolean newValue)
Sets a specified column to be hidden or visible. If it is hidden, then it is invisible to the user. The first column is at index 0.

Parameters:
col - the column index
newValue - hidden if true, visible otherwise

isEditable

public boolean isEditable(int col)
Returns true if the specified column is editable, false otherwise. This allows editing of the column values or makes them read only. The first column is at index 0.

Parameters:
col - the column index
Returns:
true if editable, false otherwise

setEditable

public void setEditable(int col,
                        boolean newValue)
Sets the specified column to be editable or not. This allows editing of the column values or makes them read only. The first column is at index 0.

Parameters:
col - the column index
newValue - editable if true, not editable if false

isRightAlignmentSortable

public boolean isRightAlignmentSortable(int col)
Returns true if the specified column is right alignment sortable, false otherwise. Right alightment sortability allows for sorting of the column values after they have been right aligned. What this means is illustrated by the following examples:
The usual implementation for this is double clicking on the column header in the table once right alignment sorting has been enabled to sort the rows according to that column. The typical implementation also sorts in alternating ascending and descending order once the column has been double clicked once to perform the initial sort. What this means is the column can be double clicked repetedly and sorting will switch between ascending and descending order. For right alignment sorting to work, sorting must be enabled. This can be done by calling setSortable. The first column is at index 0.

Parameters:
col - the column index
Returns:
true if right alignment sortable, false otherwise

setRightAlignmentSortable

public void setRightAlignmentSortable(int col,
                                      boolean newValue)
Sets right alignment sortability for the specified column. Right alightment sortability allows for sorting of the column values after they have been right aligned. What this means is illustrated by the following examples:
The usual implementation for this is double clicking on the column header in the table once right alignment sorting has been enabled to sort the rows according to that column. The typical implementation also sorts in alternating ascending and descending order once the column has been double clicked once to perform the initial sort. What this means is the column can be double clicked repetedly and sorting will switch between ascending and descending order. For right alignment sorting to work, sorting must be enabled. This can be done by calling setSortable. The first column is at index 0.

Parameters:
col - the column index
newValue - enabled if true, disabled otherwise

getColumnClass

public java.lang.Class getColumnClass(int col)
Returns the column class specified by the col parameter. The first column is at index 0. This function will return the class that the column in question belongs to. For more information about column classes see EntityTableColumn. If the column index is out of bounds, null is returned.

Parameters:
col - the index of the column
Returns:
the Class of the specified column

getColumnName

public java.lang.String getColumnName(int col)
Returns the name for the specified column. The name is usually what is displayed on top of the column to the user. The first column index is at 0.

Parameters:
col - the column index
Returns:
the String column name

getColumnCount

public int getColumnCount()
Returns the number of columns in this EntityTableColumnModel.

Specified by:
getColumnCount in interface javax.swing.table.TableColumnModel
Returns:
the number of columns

getRealColumnCount

public int getRealColumnCount()
Returns the number of visible columns.

Returns:
the number of visible columns

addColumn

public void addColumn(EntityTableColumn c)
Adds the given EntityTableColumn to the right-side of the table. Although columns can be added after the table contains data without producing any errors, the column will have no impact on the row data unless the column's setCellValue and getCellValue methods are overridden in such a way as to perform the appropriate action when a cell value in the column is changed. To properly handle the addition of new columns, the entity must be constructed so that it has a place to put the data for any new columns that are added.

Parameters:
c - the new column

removeColumn

public void removeColumn(int col)
Removes the specified column from the table. Generally columns should not be removed after the table contains data since this might result in errors. Some side effects include: ClassCastExceptions when panning the table, and incorrect rendering of the table. The first column index is at 0.

Parameters:
col - the column index

getByName

public EntityTableColumn getByName(java.lang.String name)
Returns the column with the specified name. The getColumnName function can be used together with this function to retrieve any column from the table.

Parameters:
name - the String name of the column
Returns:
the EntityTableColumn that matches the specified name

hasEditableColumns

public boolean hasEditableColumns()
Returns true if the table has any editable columns, false otherwise. Editability determines if the user can edit the values of the column or if the values are read only.

Returns:
true if there are editable columns, false otherwise