public class EventTableModel<E> extends javax.swing.table.AbstractTableModel implements ListEventListener<E>
TableModel that holds an EventList. Each element of the list
corresponds to a row in the TableModel. The columns of the table are
specified using a TableFormat.
The EventTableModel class is not thread-safe. Unless otherwise
noted, all methods are only safe to be called from the event dispatch thread.
To do this programmatically, use SwingUtilities.invokeAndWait(Runnable).
SwingUtilities.invokeAndWait(Runnable),
Bug 112,
Bug 146,
Bug 177,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
protected EventList<E> |
source
the source of data for this TableModel, which may or may not be
swingThreadSource |
protected TransformedList<E,E> |
swingThreadSource
the proxy moves events to the Swing Event Dispatch thread
|
| Constructor and Description |
|---|
EventTableModel(EventList<E> source,
java.lang.String[] propertyNames,
java.lang.String[] columnLabels,
boolean[] writable)
Creates a new table that renders the specified list with an automatically
generated
TableFormat. |
EventTableModel(EventList<E> source,
TableFormat<? super E> tableFormat)
Creates a new table model that extracts column data from the given
source using the the given tableFormat. |
| Modifier and Type | Method and Description |
|---|---|
protected TransformedList<E,E> |
createSwingThreadProxyList(EventList<E> source)
This method exists as a hook for subclasses that may have custom
threading needs within their EventTableModels.
|
void |
dispose()
Releases the resources consumed by this
EventTableModel so that it
may eventually be garbage collected. |
java.lang.Class |
getColumnClass(int columnIndex)
Gets the class of elements in the specified column.
|
int |
getColumnCount()
Get the column count as specified by the table format.
|
java.lang.String |
getColumnName(int column)
Fetch the name for the specified column.
|
E |
getElementAt(int index)
Retrieves the value at the specified location from the table.
|
protected ca.odell.glazedlists.swing.MutableTableModelEvent |
getMutableTableModelEvent() |
int |
getRowCount()
The number of rows equals the number of entries in the source event list.
|
TableFormat<? super E> |
getTableFormat()
Gets the Table Format.
|
java.lang.Object |
getValueAt(int row,
int column)
Retrieves the value at the specified location of the table.
|
protected void |
handleListChange(ListEvent<E> listChanges)
Default implementation for converting a
ListEvent to
TableModelEvents. |
boolean |
isCellEditable(int row,
int column)
Delegates the question of whether the cell is editable or not to the
backing TableFormat if it is a
WritableTableFormat. |
void |
listChanged(ListEvent<E> listChanges)
For implementing the ListEventListener interface.
|
void |
setTableFormat(TableFormat<E> tableFormat)
Sets the
TableFormat that will extract column data from each
element. |
void |
setValueAt(java.lang.Object editedValue,
int row,
int column)
Attempts to update the object for the given row with the
editedValue. |
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListenerprotected TransformedList<E,E> swingThreadSource
protected EventList<E> source
swingThreadSourcepublic EventTableModel(EventList<E> source, TableFormat<? super E> tableFormat)
source using the the given tableFormat.source - the EventList that provides the row objectstableFormat - the object responsible for extracting column data
from the row objectspublic EventTableModel(EventList<E> source, java.lang.String[] propertyNames, java.lang.String[] columnLabels, boolean[] writable)
TableFormat. It uses JavaBeans and reflection to create
a TableFormat as specified.
Note that the classes which will be obfuscated may not work with
reflection. In this case, implement a TableFormat manually.
source - the EventList that provides the row objectspropertyNames - an array of property names in the JavaBeans format.
For example, if your list contains Objects with the methods getFirstName(),
setFirstName(String), getAge(), setAge(Integer), then this array should
contain the two strings "firstName" and "age". This format is specified
by the JavaBeans PropertyDescriptor.columnLabels - the corresponding column names for the listed property
names. For example, if your columns are "firstName" and "age", then
your labels might be "First Name" and "Age".writable - an array of booleans specifying which of the columns in
your table are writable.protected TransformedList<E,E> createSwingThreadProxyList(EventList<E> source)
source in a SwingThreadProxyList if it
is not already a SwingThreadProxyList. Subclasses may replace this logic
and return either a custom ThreadProxyEventList of their choosing, or
return null or the source unchanged in order
to indicate that NO ThreadProxyEventList is desired.
In these cases it is expected that some external mechanism will ensure
that threading is handled correctly.source - the EventList that provides the row objectsnull or the
source unchanged to indicate that NO
Thread-proxying is desiredpublic TableFormat<? super E> getTableFormat()
public void setTableFormat(TableFormat<E> tableFormat)
TableFormat that will extract column data from each
element. This has some very important consequences. Any cell selections
will be lost - this is due to the fact that the TableFormats may have
different numbers of columns, and JTable has no event to specify columns
changing without rows.public E getElementAt(int index)
This may be used by renderers to paint the cells of a row differently based on the entire value for that row.
getValueAt(int,int)public void listChanged(ListEvent<E> listChanges)
GlazedListsSwing.swingThreadProxyList(ca.odell.glazedlists.EventList<E>), all natural
calls to this method are guaranteed to occur on the Swing EDT.listChanged in interface ListEventListener<E>protected void handleListChange(ListEvent<E> listChanges)
ListEvent to
TableModelEvents. There will be one TableModelEvent per ListEvent block.
Subclasses may choose to implement a different conversion.listChanges - ListEvent to translateprotected final ca.odell.glazedlists.swing.MutableTableModelEvent getMutableTableModelEvent()
public java.lang.String getColumnName(int column)
getColumnName in interface javax.swing.table.TableModelgetColumnName in class javax.swing.table.AbstractTableModelpublic int getRowCount()
getRowCount in interface javax.swing.table.TableModelpublic int getColumnCount()
getColumnCount in interface javax.swing.table.TableModelpublic java.lang.Class getColumnClass(int columnIndex)
AdvancedTableFormat interface.getColumnClass in interface javax.swing.table.TableModelgetColumnClass in class javax.swing.table.AbstractTableModelpublic java.lang.Object getValueAt(int row,
int column)
getValueAt in interface javax.swing.table.TableModelpublic boolean isCellEditable(int row,
int column)
WritableTableFormat. Otherwise,
the column is assumed to be uneditable.isCellEditable in interface javax.swing.table.TableModelisCellEditable in class javax.swing.table.AbstractTableModelpublic void setValueAt(java.lang.Object editedValue,
int row,
int column)
editedValue. This requires the backing TableFormat
be a WritableTableFormat. WritableTableFormat.setColumnValue(E, java.lang.Object, int)
is expected to contain the logic for updating the object at the given
row with the editedValue which was in the
given column.setValueAt in interface javax.swing.table.TableModelsetValueAt in class javax.swing.table.AbstractTableModelpublic void dispose()
EventTableModel so that it
may eventually be garbage collected.
An EventTableModel will be garbage collected without a call to
dispose(), but not before its source EventList is garbage
collected. By calling dispose(), you allow the EventTableModel
to be garbage collected before its source EventList. This is
necessary for situations where an EventTableModel is short-lived but
its source EventList is long-lived.
Warning: It is an error
to call any method on an EventTableModel after it has been disposed.
As such, this EventTableModel should be detached from its
corresponding Component before it is disposed.
Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by builder at 2012-09-17 16:07