Groovy Documentation

com.wordpress.tipsforjava.swing.table
[Java] Class BeanTableModel

java.lang.Object
  javax.swing.table.AbstractTableModel
      com.wordpress.tipsforjava.swing.table.RowTableModel
          com.wordpress.tipsforjava.swing.table.BeanTableModel

public class BeanTableModel
extends RowTableModel

The BeanTableModel will use reflection to determine the columns of data to be displayed in the table model. Reflection is used to find all the methods declared in the specified bean. The criteria used for adding columns to the model are: a) the method name must start with either "get" or "is" b) the parameter list for the method must contain 0 parameters You can also specify an ancestor class in which case the declared methods of the ancestor and all its descendents will be included in the model. A column name will be assigned to each column based on the method name. The cell will be considered editable when a corresponding "set" method name is found. Reflection will also be used to implement the getValueAt() and setValueAt() methods.

Authors:
Rob Camick
Darryl Burke


Nested Class Summary
private class BeanTableModel.ColumnInformation

 
Field Summary
private Class ancestorClass

private Class beanClass

private List columns

private static Map primitives

 
Fields inherited from class RowTableModel
columnClasses, columnNames, isColumnEditable, isModelEditable, modelData, rowClass
 
Constructor Summary
BeanTableModel(Class beanClass)

Constructs an empty BeanTableModel for the specified bean.

BeanTableModel(Class beanClass, Class ancestorClass)

Constructs an empty BeanTableModel for the specified bean.

BeanTableModel(Class beanClass, List modelData)

Constructs an empty BeanTableModel for the specified bean.

BeanTableModel(Class beanClass, Class ancestorClass, List modelData)

Constructs an empty BeanTableModel for the specified bean.

 
Method Summary
private void buildColumnInformation(Method theMethod, String theMethodName)

private void createColumnInformation()

private Class getReturnType(Method theMethod)

Object getValueAt(int row, int column)

Returns an attribute value for the cell at row and column.

private void resetModelDefaults()

void setColumnClass(int column, Class columnClass)

You are not allowed to change the class of any column.

void setColumnEditable(int column, boolean isEditable)

Sets the editability for the specified column.

void setColumnName(int column, String name)

Convenience method to change the generated column header name.

void setValueAt(Object value, int row, int column)

Sets the object value for the cell at column and row.

void sortColumnNames()

 
Methods inherited from class RowTableModel
addRow, formatColumnName, getColumnClass, getColumnCount, getColumnName, getRow, getRowCount, getRowsAsArray, getRowsAsList, insertRow, insertRows, insertRows, isCellEditable, moveRow, removeRowRange, removeRows, replaceRow, setColumnClass, setColumnEditable, setDataAndColumnNames, setModelEditable, setRowClass
 
Methods inherited from class AbstractTableModel
getListeners, getColumnName, getColumnClass, isCellEditable, setValueAt, addTableModelListener, removeTableModelListener, fireTableStructureChanged, fireTableChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableCellUpdated, findColumn, getTableModelListeners, fireTableDataChanged, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll, getRowCount, getColumnCount, getValueAt
 

Field Detail

ancestorClass

private Class ancestorClass


beanClass

private Class beanClass


columns

private List columns


primitives

private static Map primitives


 
Constructor Detail

BeanTableModel

public BeanTableModel(Class beanClass)
Constructs an empty BeanTableModel for the specified bean.
Parameters:
beanClass - class of the beans that will be added to the model. The class is also used to determine the columns that will be displayed in the model


BeanTableModel

public BeanTableModel(Class beanClass, Class ancestorClass)
Constructs an empty BeanTableModel for the specified bean.
Parameters:
beanClass - class of the beans that will be added to the model.
ancestorClass - the methods of this class and its descendents down to the bean class can be included in the model.


BeanTableModel

public BeanTableModel(Class beanClass, List modelData)
Constructs an empty BeanTableModel for the specified bean.
Parameters:
beanClass - class of the beans that will be added to the model.
modelData - the data of the table


BeanTableModel

public BeanTableModel(Class beanClass, Class ancestorClass, List modelData)
Constructs an empty BeanTableModel for the specified bean.
Parameters:
beanClass - class of the beans that will be added to the model.
ancestorClass - the methods of this class and its descendents down to the bean class can be included in the model.
modelData - the data of the table


 
Method Detail

buildColumnInformation

ssWarnings("unchecked")
	private
private void buildColumnInformation(Method theMethod, String theMethodName)


createColumnInformation

ssWarnings("unchecked")
	private
private void createColumnInformation()


getReturnType

private Class getReturnType(Method theMethod)


getValueAt

de
	public
public Object getValueAt(int row, int column)
Returns an attribute value for the cell at row and column.
Throws:
IndexOutOfBoundsException if an invalid row or column was given
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the value Object at the specified cell


resetModelDefaults

private void resetModelDefaults()


setColumnClass

de
	public
public void setColumnClass(int column, Class columnClass)
You are not allowed to change the class of any column.


setColumnEditable

de
	public
public void setColumnEditable(int column, boolean isEditable)
Sets the editability for the specified column. Override to make sure you can't set a column editable that doesn't have a defined setter method.
Throws:
ArrayIndexOutOfBoundsException if an invalid column was given
Parameters:
column - the column whose Class is being changed
isEditable - indicates if the column is editable or not


setColumnName

public void setColumnName(int column, String name)
Convenience method to change the generated column header name. This method must be invoked before the model is added to the table.
Throws:
IndexOutOfBoundsException if an invalid column was given
Parameters:
column - the column whose value is to be queried


setValueAt

de
	public
public void setValueAt(Object value, int row, int column)
Sets the object value for the cell at column and row. value is the new value. This method will generate a tableChanged notification.
Throws:
IndexOutOfBoundsException if an invalid row or column was given
Parameters:
value - the new value; this can be null
row - the row whose value is to be changed
column - the column whose value is to be changed


sortColumnNames

public void sortColumnNames()


 

Groovy Documentation