com.pcauto.gui.table
Class AbstractEntityTableColumnModel

java.lang.Object
  extended byjavax.swing.table.DefaultTableColumnModel
      extended bycom.pcauto.gui.table.AbstractEntityTableColumnModel
All Implemented Interfaces:
EntityTableColumnModel, java.util.EventListener, javax.swing.event.ListSelectionListener, java.beans.PropertyChangeListener, java.io.Serializable, javax.swing.table.TableColumnModel

public abstract class AbstractEntityTableColumnModel
extends javax.swing.table.DefaultTableColumnModel
implements EntityTableColumnModel

The AbstractEntityTableColumnModel is a super class for models that define the columns to be displayed in an EntityTable. If default behaviour is required, developers should subclass AbstractEntityTableColumnModel to quickly get an implementation of the EntityTableColumnModel interface which, provides a mapping between entity objects and a table view.

The EntityTableColumnModel defines column properties including the datatypes, editors, and attributes associated with each column, such as sortability and column order. An entity(which is used in some of the methods in this class) represents a row of data contained within a table. For any entity, the user must implement the getCellValue(int,Object) and setCellValue(int,Object,Object) functions since they are specific to the entity used and map entities to table columns.

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 order of the columns matches the order they were added to this AbstractEntityTableColumnModel. The first column is at index 0. The entity Object is required because it contains the data for the row.

Some examples of the functionality that this class provides include:

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
 
Constructor Summary
AbstractEntityTableColumnModel()
          Constructs a new EntityTableColumnModel.
 
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.
abstract  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.
 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.
abstract  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 class javax.swing.table.DefaultTableColumnModel
addColumn, addColumnModelListener, createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, moveColumn, propertyChange, recalcWidthCache, removeColumn, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.pcauto.gui.table.EntityTableColumnModel
getColumnCount
 
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
 

Constructor Detail

AbstractEntityTableColumnModel

public AbstractEntityTableColumnModel()
Constructs a new EntityTableColumnModel.

Method Detail

getCellValue

public abstract java.lang.Object getCellValue(int col,
                                              java.lang.Object entity)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
getCellValue in interface EntityTableColumnModel
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 abstract void setCellValue(int col,
                                  java.lang.Object entity,
                                  java.lang.Object value)
Description copied from interface: EntityTableColumnModel
Changes the specified entity to store the specified value based on the column index. The index of the first column is 0.

Specified by:
setCellValue in interface EntityTableColumnModel
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

getColumnClass

public java.lang.Class getColumnClass(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
getColumnClass in interface EntityTableColumnModel
Parameters:
col - the index of the column
Returns:
the Class of the specified column

isLocked

public boolean isLocked(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
isLocked in interface EntityTableColumnModel
Parameters:
col - the column index
Returns:
true if locked, false otherwise

setLocked

public void setLocked(int col,
                      boolean newValue)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
setLocked in interface EntityTableColumnModel
Parameters:
col - the column index
newValue - locked if true, unlocked if false

isSortable

public boolean isSortable(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
isSortable in interface EntityTableColumnModel
Parameters:
col - the column index
Returns:
true if sortable, false otherwise

setSortable

public void setSortable(int col,
                        boolean newValue)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
setSortable in interface EntityTableColumnModel
Parameters:
col - the column index
newValue - sortable if true, not sortable if false

isRightAlignmentSortable

public boolean isRightAlignmentSortable(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
isRightAlignmentSortable in interface EntityTableColumnModel
Parameters:
col - the column index
Returns:
true if right alignment sortable, false otherwise

setRightAlignmentSortable

public void setRightAlignmentSortable(int col,
                                      boolean newValue)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
setRightAlignmentSortable in interface EntityTableColumnModel
Parameters:
col - the column index
newValue - enabled if true, disabled otherwise

isHidden

public boolean isHidden(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
isHidden in interface EntityTableColumnModel
Parameters:
col - the column index
Returns:
true if hidden, false otherwise

setHidden

public void setHidden(int col,
                      boolean newValue)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
setHidden in interface EntityTableColumnModel
Parameters:
col - the column index
newValue - hidden if true, visible otherwise

isEditable

public boolean isEditable(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
isEditable in interface EntityTableColumnModel
Parameters:
col - the column index
Returns:
true if editable, false otherwise

setEditable

public void setEditable(int col,
                        boolean newValue)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
setEditable in interface EntityTableColumnModel
Parameters:
col - the column index
newValue - editable if true, not editable if false

getColumnName

public java.lang.String getColumnName(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
getColumnName in interface EntityTableColumnModel
Parameters:
col - the column index
Returns:
the String column name

addColumn

public void addColumn(EntityTableColumn c)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
addColumn in interface EntityTableColumnModel
Parameters:
c - the new column

removeColumn

public void removeColumn(int col)
Description copied from interface: EntityTableColumnModel
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.

Specified by:
removeColumn in interface EntityTableColumnModel
Parameters:
col - the column index

getByName

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

Specified by:
getByName in interface EntityTableColumnModel
Parameters:
name - the String name of the column
Returns:
the EntityTableColumn that matches the specified name

getRealColumnCount

public int getRealColumnCount()
Description copied from interface: EntityTableColumnModel
Returns the number of visible columns.

Specified by:
getRealColumnCount in interface EntityTableColumnModel
Returns:
the number of visible columns

hasEditableColumns

public boolean hasEditableColumns()
Description copied from interface: EntityTableColumnModel
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.

Specified by:
hasEditableColumns in interface EntityTableColumnModel
Returns:
true if there are editable columns, false otherwise