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>
ATableModelthat 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 protectedDefaultEventTableModel(EventList<E> source, boolean disposeSource, TableFormat<? super E> tableFormat)Creates a new table model that extracts column data from the givensourceusing the the giventableFormat.DefaultEventTableModel(EventList<E> source, TableFormat<? super E> tableFormat)Creates a new table model that extracts column data from the givensourceusing the the giventableFormat.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Releases the resources consumed by thisAdvancedTableModelso that it may eventually be garbage collected.java.lang.ClassgetColumnClass(int columnIndex)Gets the class of elements in the specified column.intgetColumnCount()Get the column count as specified by the table format.java.lang.StringgetColumnName(int column)Fetch the name for the specified column.EgetElementAt(int index)Retrieves the value at the specified location from the table.protected MutableTableModelEventgetMutableTableModelEvent()intgetRowCount()The number of rows equals the number of entries in the source event list.TableFormat<? super E>getTableFormat()Gets theTableFormatused by this table model.java.lang.ObjectgetValueAt(int row, int column)Retrieves the value at the specified location of the table.protected voidhandleListChange(ListEvent<E> listChanges)Default implementation for converting aListEventto TableModelEvents.booleanisCellEditable(int row, int column)Delegates the question of whether the cell is editable or not to the backing TableFormat if it is aWritableTableFormat.voidlistChanged(ListEvent<E> listChanges)For implementing the ListEventListener interface.voidsetTableFormat(TableFormat<? super E> tableFormat)Sets theTableFormatthat will extract column data from each element.voidsetValueAt(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 givensourceusing 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 givensourceusing the the giventableFormat.- Parameters:
source- the EventList that provides the row objectsdiposeSource-trueif the source list should be disposed when disposing this model,falseotherwisetableFormat- the object responsible for extracting column data from the row objects
-
-
Method Detail
-
getTableFormat
public TableFormat<? super E> getTableFormat()
Gets theTableFormatused by this table model.- Specified by:
getTableFormatin interfaceAdvancedTableModel<E>
-
setTableFormat
public void setTableFormat(TableFormat<? super E> tableFormat)
Sets theTableFormatthat 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:
setTableFormatin 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:
getElementAtin 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:
listChangedin interfaceListEventListener<E>- Parameters:
listChanges- aListEventdescribing the changes to the list
-
handleListChange
protected void handleListChange(ListEvent<E> listChanges)
Default implementation for converting aListEventto 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:
getColumnNamein interfacejavax.swing.table.TableModel- Overrides:
getColumnNamein classjavax.swing.table.AbstractTableModel
-
getRowCount
public int getRowCount()
The number of rows equals the number of entries in the source event list.- Specified by:
getRowCountin interfacejavax.swing.table.TableModel
-
getColumnCount
public int getColumnCount()
Get the column count as specified by the table format.- Specified by:
getColumnCountin 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 theAdvancedTableFormatinterface.- Specified by:
getColumnClassin interfacejavax.swing.table.TableModel- Overrides:
getColumnClassin 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:
getValueAtin 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:
isCellEditablein interfacejavax.swing.table.TableModel- Overrides:
isCellEditablein 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 givenrowwith theeditedValuewhich was in the givencolumn.- Specified by:
setValueAtin interfacejavax.swing.table.TableModel- Overrides:
setValueAtin classjavax.swing.table.AbstractTableModel
-
dispose
public void dispose()
Releases the resources consumed by thisAdvancedTableModelso that it may eventually be garbage collected.An
AdvancedTableModelwill be garbage collected without a call toAdvancedTableModel.dispose(), but not before its sourceEventListis garbage collected. By callingAdvancedTableModel.dispose(), you allow theAdvancedTableModelto be garbage collected before its sourceEventList. This is necessary for situations where anAdvancedTableModelis short-lived but its sourceEventListis long-lived.Warning: It is an error to call any method on an
AdvancedTableModelafter it has been disposed. As such, thisAdvancedTableModelshould be detached from its corresponding Component before it is disposed.- Specified by:
disposein interfaceAdvancedTableModel<E>
-
-