|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
com.gargoylesoftware.base.gui.ReflectedTableModel
public class ReflectedTableModel
A table model that uses reflection to retrieve values out of the row objects.
The sample below will create a JTable with one row of data and one column per property in the Date class (Date has 10 properties in JDK1.3).
final JTable table = new JTable(); final ReflectedTableModel model = new ReflectedTableModel(Date.class); model.getRows().add( new Date() ); table.setModel(model);This sample will only provide columns for month and year.
final JTable table = new JTable();
final ReflectedTableModel model = new ReflectedTableModel();
model.getRows().add( new Date() );
model.getColumns().add( new ReflectedTableModel.ColumnInfo("month") );
model.getColumns().add( new ReflectedTableModel.ColumnInfo("year") );
table.setModel(model);
Tip: To enable debugging information call setTraceChannel(TraceChannel)
with a non-null TraceChannel.
model.setTraceChannel(Trace.out)
| Nested Class Summary | |
|---|---|
static class |
ReflectedTableModel.ColumnInfo
This class contains information about one specific column in the table. |
private class |
ReflectedTableModel.RowElementControlData
|
| Field Summary | |
|---|---|
private NotificationListListener |
columnListener_
If any change occurs to the columns then fire a structure changed. |
private java.util.List |
columns_
|
private static java.lang.Object[] |
EMPTY_OBJECT_ARRAY
|
private java.beans.PropertyChangeListener |
propertyChangeListener_
|
private java.util.Map |
rowElementControlDatas_
|
private NotificationListListener |
rowListener_
If the row list changes then fire the appropriate table event. |
private java.util.List |
rows_
|
private static long |
serialVersionUID
|
private TraceChannel |
traceChannel_
|
| Fields inherited from class javax.swing.table.AbstractTableModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
ReflectedTableModel()
Create an empty model with no columns and no rows. |
|
ReflectedTableModel(java.lang.Class clazz)
Create an empty model with no rows but the columns preset to match the properties in the given class. |
|
| Method Summary | |
|---|---|
private void |
addRowElement(java.lang.Object object)
Add a row element |
private void |
addRowElements(java.util.List list)
|
protected void |
assertNotNull(java.lang.String fieldName,
java.lang.Object object)
Throw an exception if the specified object is null |
int |
getColumnCount()
Return the number of columns. |
java.lang.String |
getColumnName(int index)
Return the name of the column at the specified index. |
java.util.List |
getColumns()
Return a list containing the ColumnInfo objects that are used to define each column. |
int |
getRowCount()
Return the number of rows. |
java.util.List |
getRows()
Return a list containing the objects that are used to create each row. |
TraceChannel |
getTraceChannel()
Return the channel currently being used for tracing or null if tracing is disabled. |
java.lang.Object |
getValueAt(int rowIndex,
int columnIndex)
Return the specified object. |
private void |
removeRowElement(java.lang.Object object)
Remove one row |
private void |
removeRowElements(java.util.List list)
|
void |
setTraceChannel(TraceChannel channel)
Set the channel to be used for tracing. |
| Methods inherited from class javax.swing.table.AbstractTableModel |
|---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final long serialVersionUID
private NotificationListListener rowListener_
private NotificationListListener columnListener_
private java.beans.PropertyChangeListener propertyChangeListener_
private final java.util.Map rowElementControlDatas_
private final java.util.List rows_
private final java.util.List columns_
private static final java.lang.Object[] EMPTY_OBJECT_ARRAY
private TraceChannel traceChannel_
| Constructor Detail |
|---|
public ReflectedTableModel()
public ReflectedTableModel(java.lang.Class clazz)
throws java.beans.IntrospectionException
clazz - The class to get properties from.
java.beans.IntrospectionException - If the Introspector is unable to get
the properties for this class.| Method Detail |
|---|
public java.util.List getRows()
public java.util.List getColumns()
public int getColumnCount()
public int getRowCount()
public java.lang.Object getValueAt(int rowIndex,
int columnIndex)
rowIndex - The row indexcolumnIndex - The columnIndex
public java.lang.String getColumnName(int index)
getColumnName in interface javax.swing.table.TableModelgetColumnName in class javax.swing.table.AbstractTableModelindex - The index of the column.
public void setTraceChannel(TraceChannel channel)
channel - The channel to be used for tracing or null if tracing is
to be disabled.public TraceChannel getTraceChannel()
private void addRowElement(java.lang.Object object)
object - the object that will be used to populate this rowprivate void addRowElements(java.util.List list)
list - The list of objects that will be used to create the rows.private void removeRowElements(java.util.List list)
list - The list of object that will be removed from the modelprivate void removeRowElement(java.lang.Object object)
object - The object that was used to create this row.
protected final void assertNotNull(java.lang.String fieldName,
java.lang.Object object)
fieldName - The name of the paremeter we are checkingobject - The value of the parameter we are checking
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||