uk.ac.starlink.vo
Class BeanTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by uk.ac.starlink.vo.BeanTableModel
All Implemented Interfaces:
Serializable, TableModel

public class BeanTableModel
extends AbstractTableModel

TableModel which displays beans. The table is constructed to display beans of a particular class, and each of its row displays one instance of this class. It has one column for each readable property. As usual, a bean is anything which has likely-looking getter methods, though by using the java.beans package any cleverer stuff held in BeanInfos will get used as well/instead. What a neat idea!

Since:
21 Dec 2004
Author:
Mark Taylor (Starlink)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
BeanTableModel(Class clazz)
          Constructs a new table model for displaying beans of a given class.
 
Method Summary
 Class getColumnClass(int icol)
           
 int getColumnCount()
           
 String getColumnName(int icol)
           
 Object[] getData()
          Returns the array of objects which this model displays, one per row.
 int getRowCount()
           
 Object getValueAt(int irow, int icol)
           
 boolean isCellEditable(int irow, int icol)
           
 Comparator propertySorter(String propertyName)
          Returns a sorter which can be used to sort rows of this table (data array elements).
 void setData(Object[] data)
          Populates this model with items.
 void setValueAt(Object value, int irow, int icol)
           
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanTableModel

public BeanTableModel(Class clazz)
               throws IntrospectionException
Constructs a new table model for displaying beans of a given class.

Parameters:
clazz - class of items which will be displayed in this table
Throws:
IntrospectionException
Method Detail

setData

public void setData(Object[] data)
Populates this model with items.

Parameters:
data - array of items, one for each row. This array's runtime type must match that for which this model was constructed (on pain of ClassCastException)

getData

public Object[] getData()
Returns the array of objects which this model displays, one per row. The runtime type of the returned array matches that of the bean class this model displays.

Returns:
table data

propertySorter

public Comparator propertySorter(String propertyName)
Returns a sorter which can be used to sort rows of this table (data array elements).

Parameters:
propertyName - name of readable bean property to sort on
Returns:
a comparator that sorts on propertyName, or null if propertyName does not name a suitable property

getColumnName

public String getColumnName(int icol)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumnClass

public Class getColumnClass(int icol)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

getColumnCount

public int getColumnCount()

getRowCount

public int getRowCount()

getValueAt

public Object getValueAt(int irow,
                         int icol)

isCellEditable

public boolean isCellEditable(int irow,
                              int icol)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

setValueAt

public void setValueAt(Object value,
                       int irow,
                       int icol)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel


Copyright © 2014 Central Laboratory of the Research Councils. All Rights Reserved.