Class DefaultEventTableModel<E>
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- ca.odell.glazedlists.swing.DefaultEventTableModel<E>
-
- All Implemented Interfaces:
ListEventListener<E>
,AdvancedTableModel<E>
,java.io.Serializable
,java.util.EventListener
,javax.swing.table.TableModel
- Direct Known Subclasses:
EventTableModel
public class DefaultEventTableModel<E> extends javax.swing.table.AbstractTableModel implements AdvancedTableModel<E>, ListEventListener<E>
ATableModel
that holds anEventList
. Each element of the list corresponds to a row in theTableModel
. The columns of the table are specified using aTableFormat
.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)
and wrap the source list (or some part of the source list's pipeline) using GlazedListsSwing#swingThreadProxyList(EventList).- Author:
- Jesse Wilson
- See Also:
- Glazed Lists Tutorial,
GlazedListsSwing.swingThreadProxyList(EventList)
,SwingUtilities.invokeAndWait(Runnable)
, Bug 112, Bug 146, Bug 177, Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultEventTableModel(EventList<E> source, boolean disposeSource, TableFormat<? super E> tableFormat)
Creates a new table model that extracts column data from the givensource
using the the giventableFormat
.DefaultEventTableModel(EventList<E> source, TableFormat<? super E> tableFormat)
Creates a new table model that extracts column data from the givensource
using the the giventableFormat
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
Releases the resources consumed by thisAdvancedTableModel
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 MutableTableModelEvent
getMutableTableModelEvent()
int
getRowCount()
The number of rows equals the number of entries in the source event list.TableFormat<? super E>
getTableFormat()
Gets theTableFormat
used by this table model.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 aListEvent
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 aWritableTableFormat
.void
listChanged(ListEvent<E> listChanges)
For implementing the ListEventListener interface.void
setTableFormat(TableFormat<? super E> tableFormat)
Sets theTableFormat
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 theeditedValue
.-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Constructor Detail
-
DefaultEventTableModel
public DefaultEventTableModel(EventList<E> source, TableFormat<? super E> tableFormat)
Creates a new table model that extracts column data from the givensource
using the the giventableFormat
.- Parameters:
source
- the EventList that provides the row objectstableFormat
- the object responsible for extracting column data from the row objects
-
DefaultEventTableModel
protected DefaultEventTableModel(EventList<E> source, boolean disposeSource, TableFormat<? super E> tableFormat)
Creates a new table model that extracts column data from the givensource
using the the giventableFormat
.- Parameters:
source
- the EventList that provides the row objectsdiposeSource
-true
if the source list should be disposed when disposing this model,false
otherwisetableFormat
- the object responsible for extracting column data from the row objects
-
-
Method Detail
-
getTableFormat
public TableFormat<? super E> getTableFormat()
Gets theTableFormat
used by this table model.- Specified by:
getTableFormat
in interfaceAdvancedTableModel<E>
-
setTableFormat
public void setTableFormat(TableFormat<? super E> tableFormat)
Sets theTableFormat
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.- Specified by:
setTableFormat
in interfaceAdvancedTableModel<E>
-
getElementAt
public E getElementAt(int index)
Retrieves the value at the specified location from the table.This may be used by renderers to paint the cells of a row differently based on the entire value for that row.
- Specified by:
getElementAt
in interfaceAdvancedTableModel<E>
- See Also:
TableModel.getValueAt(int,int)
-
listChanged
public void listChanged(ListEvent<E> listChanges)
For implementing the ListEventListener interface. This sends changes to the table which repaints the table cells. Because this class is backed byGlazedListsSwing.swingThreadProxyList(ca.odell.glazedlists.EventList<E>)
, all natural calls to this method are guaranteed to occur on the Swing EDT.- Specified by:
listChanged
in interfaceListEventListener<E>
- Parameters:
listChanges
- aListEvent
describing the changes to the list
-
handleListChange
protected void handleListChange(ListEvent<E> listChanges)
Default implementation for converting aListEvent
to TableModelEvents. There will be one TableModelEvent per ListEvent block. Subclasses may choose to implement a different conversion.- Parameters:
listChanges
- ListEvent to translate
-
getMutableTableModelEvent
protected final MutableTableModelEvent getMutableTableModelEvent()
- Returns:
- reusable TableModelEvent for broadcasting changes
-
getColumnName
public java.lang.String getColumnName(int column)
Fetch the name for the specified column.- Specified by:
getColumnName
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnName
in classjavax.swing.table.AbstractTableModel
-
getRowCount
public int getRowCount()
The number of rows equals the number of entries in the source event list.- Specified by:
getRowCount
in interfacejavax.swing.table.TableModel
-
getColumnCount
public int getColumnCount()
Get the column count as specified by the table format.- Specified by:
getColumnCount
in interfacejavax.swing.table.TableModel
-
getColumnClass
public java.lang.Class getColumnClass(int columnIndex)
Gets the class of elements in the specified column. This behaviour can be customized by implementing theAdvancedTableFormat
interface.- Specified by:
getColumnClass
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnClass
in classjavax.swing.table.AbstractTableModel
-
getValueAt
public java.lang.Object getValueAt(int row, int column)
Retrieves the value at the specified location of the table.- Specified by:
getValueAt
in interfacejavax.swing.table.TableModel
-
isCellEditable
public boolean isCellEditable(int row, int column)
Delegates the question of whether the cell is editable or not to the backing TableFormat if it is aWritableTableFormat
. Otherwise, the column is assumed to be uneditable.- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
-
setValueAt
public void setValueAt(java.lang.Object editedValue, int row, int column)
Attempts to update the object for the given row with theeditedValue
. This requires the backing TableFormat be aWritableTableFormat
.WritableTableFormat.setColumnValue(E, java.lang.Object, int)
is expected to contain the logic for updating the object at the givenrow
with theeditedValue
which was in the givencolumn
.- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
dispose
public void dispose()
Releases the resources consumed by thisAdvancedTableModel
so that it may eventually be garbage collected.An
AdvancedTableModel
will be garbage collected without a call toAdvancedTableModel.dispose()
, but not before its sourceEventList
is garbage collected. By callingAdvancedTableModel.dispose()
, you allow theAdvancedTableModel
to be garbage collected before its sourceEventList
. This is necessary for situations where anAdvancedTableModel
is short-lived but its sourceEventList
is long-lived.Warning: It is an error to call any method on an
AdvancedTableModel
after it has been disposed. As such, thisAdvancedTableModel
should be detached from its corresponding Component before it is disposed.- Specified by:
dispose
in interfaceAdvancedTableModel<E>
-
-