ca.odell.glazedlists.swing
Class DefaultEventTableModel<E>

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by ca.odell.glazedlists.swing.DefaultEventTableModel<E>
All Implemented Interfaces:
ListEventListener<E>, AdvancedTableModel<E>, Serializable, EventListener, TableModel
Direct Known Subclasses:
EventTableModel

public class DefaultEventTableModel<E>
extends AbstractTableModel
implements AdvancedTableModel<E>, ListEventListener<E>

A 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) 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

Field Summary
protected  EventList<E> source
          the source of data for this TableModel, which may or may not be #swingThreadSource
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
protected DefaultEventTableModel(EventList<E> source, boolean disposeSource, TableFormat<? super E> tableFormat)
          Creates a new table model that extracts column data from the given source using the the given tableFormat.
  DefaultEventTableModel(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.
 
Method Summary
 void dispose()
          Releases the resources consumed by this AdvancedTableModel so that it may eventually be garbage collected.
 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.
 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 the TableFormat used by this table model.
 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<? super E> tableFormat)
          Sets the TableFormat that will extract column data from each element.
 void setValueAt(Object editedValue, int row, int column)
          Attempts to update the object for the given row with the editedValue.
 
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

source

protected EventList<E> source
the source of data for this TableModel, which may or may not be #swingThreadSource

Constructor Detail

DefaultEventTableModel

public DefaultEventTableModel(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.

Parameters:
source - the EventList that provides the row objects
tableFormat - 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 given source using the the given tableFormat.

Parameters:
source - the EventList that provides the row objects
diposeSource - true if the source list should be disposed when disposing this model, false otherwise
tableFormat - the object responsible for extracting column data from the row objects
Method Detail

getTableFormat

public TableFormat<? super E> getTableFormat()
Gets the TableFormat used by this table model.

Specified by:
getTableFormat in interface AdvancedTableModel<E>

setTableFormat

public void setTableFormat(TableFormat<? super E> tableFormat)
Sets the 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.

Specified by:
setTableFormat in interface AdvancedTableModel<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 interface AdvancedTableModel<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 by GlazedListsSwing.swingThreadProxyList(ca.odell.glazedlists.EventList), all natural calls to this method are guaranteed to occur on the Swing EDT.

Specified by:
listChanged in interface ListEventListener<E>
Parameters:
listChanges - a ListEvent describing the changes to the list

handleListChange

protected void handleListChange(ListEvent<E> listChanges)
Default implementation for converting a ListEvent 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 String getColumnName(int column)
Fetch the name for the specified column.

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

getRowCount

public int getRowCount()
The number of rows equals the number of entries in the source event list.

Specified by:
getRowCount in interface TableModel

getColumnCount

public int getColumnCount()
Get the column count as specified by the table format.

Specified by:
getColumnCount in interface TableModel

getColumnClass

public Class getColumnClass(int columnIndex)
Gets the class of elements in the specified column. This behaviour can be customized by implementing the AdvancedTableFormat interface.

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

getValueAt

public Object getValueAt(int row,
                         int column)
Retrieves the value at the specified location of the table.

Specified by:
getValueAt in interface 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 a WritableTableFormat. Otherwise, the column is assumed to be uneditable.

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

setValueAt

public void setValueAt(Object editedValue,
                       int row,
                       int column)
Attempts to update the object for the given row with the 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.

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

dispose

public void dispose()
Releases the resources consumed by this AdvancedTableModel so that it may eventually be garbage collected.

An AdvancedTableModel will be garbage collected without a call to AdvancedTableModel.dispose(), but not before its source EventList is garbage collected. By calling AdvancedTableModel.dispose(), you allow the AdvancedTableModel to be garbage collected before its source EventList. This is necessary for situations where an AdvancedTableModel is short-lived but its source EventList is long-lived.

Warning: It is an error to call any method on an AdvancedTableModel after it has been disposed. As such, this AdvancedTableModel should be detached from its corresponding Component before it is disposed.

Specified by:
dispose in interface AdvancedTableModel<E>


Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by hbrands at 2015-02-16 14:02