Holger's
Java API

com.antelmann.db
Class PropertyEntryTableModel<T extends PropertyEntry>

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.antelmann.util.table.AbstractObjectTableModel<T>
          extended by com.antelmann.db.PropertyEntryTableModel<T>
All Implemented Interfaces:
ListRetriever<T>, Refreshable, ObjectTableModel<T>, Serializable, Iterable<T>, TableModel

public class PropertyEntryTableModel<T extends PropertyEntry>
extends AbstractObjectTableModel<T>

a TableModel that first uses the value of method names and then tries to retrieve properties based on the name as key. By default, this model remains read-only, but since the setValue(Object, int, int) method is already implemented (which simply sets the property), you can enable certain columns to become editable. Note that for the use of methods, it is required to pass a non-empty list into either the constructor or the refreshAll() method, so that the method name can be determined from an object; otherwise, only the property value can be used; update on this limitation: it has been fixed by providing the type with the constructor at runtime. The functionality is derived from MethodTableName, but is extended to refer to property values, if no appropriate method is found.

Author:
Holger Antelmann
See Also:
MethodTableModel, Serialized Form

Field Summary
protected  HashSet<Integer> editableColumns
           
protected  String[] methodOrPropertyNames
           
protected  Method[] methods
           
protected  Class<T> type
           
 
Fields inherited from class com.antelmann.util.table.AbstractObjectTableModel
columnNames, columnTypes
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
PropertyEntryTableModel(Class<T> type, Collection<T> list, String... methodOrPropertyNames)
           
PropertyEntryTableModel(Class<T> type, String... methodOrPropertyNames)
           
 
Method Summary
 int getColumnCount()
           
 String getColumnName(int column)
          returns the column name which - in the case of a method name - may be altered according to Beans specifications (i.e.
 Object getValueAt(int row, int column)
           
 boolean isCellEditable(int row, int column)
           
 void refreshAll(Class<T> type, Collection<T> list, String... methodOrPropertyNames)
          if no methodOrPropertyNames are given (and the list is non-empty), all properties are listed
 void setColumnEditable(int column, boolean flag)
           
 void setValueAt(Object value, int row, int column)
          sets the property for the given value
 
Methods inherited from class com.antelmann.util.table.AbstractObjectTableModel
add, add, clear, contains, getColumnClass, getList, getRelevantList, getRelevantListDescription, getRowCount, getRowFor, getRowValue, iterator, moveDown, moveUp, refreshContent, remove, remove, setColumnName, setColumnNames, setColumnType, setColumnTypes, setRowValues, swap
 
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
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
 

Field Detail

methodOrPropertyNames

protected String[] methodOrPropertyNames

type

protected Class<T extends PropertyEntry> type

methods

protected Method[] methods

editableColumns

protected HashSet<Integer> editableColumns
Constructor Detail

PropertyEntryTableModel

public PropertyEntryTableModel(Class<T> type,
                               String... methodOrPropertyNames)

PropertyEntryTableModel

public PropertyEntryTableModel(Class<T> type,
                               Collection<T> list,
                               String... methodOrPropertyNames)
                        throws IllegalArgumentException
Throws:
IllegalArgumentException
Method Detail

refreshAll

public void refreshAll(Class<T> type,
                       Collection<T> list,
                       String... methodOrPropertyNames)
                throws IllegalArgumentException
if no methodOrPropertyNames are given (and the list is non-empty), all properties are listed

Throws:
IllegalArgumentException

getColumnCount

public int getColumnCount()

getValueAt

public Object getValueAt(int row,
                         int column)

getColumnName

public String getColumnName(int column)
returns the column name which - in the case of a method name - may be altered according to Beans specifications (i.e. "is" and "get" is removed at the beginning if the following letter is upper-case). If the given column doesn't reflect on a method name, the methodOrPropertyName originally given is returned.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractObjectTableModel<T extends PropertyEntry>

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
sets the property for the given value

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

isCellEditable

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

setColumnEditable

public void setColumnEditable(int column,
                              boolean flag)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads