|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.table.AbstractTableModel
org.knime.core.node.tableview.TableContentModel
public class TableContentModel
Proprietary implementation of a model for a table view. Input of the
model is a DataTable that is to be displayed
in the table view.
This class uses a ring buffer to cache the rows being displayed.
As new rows are read from the DataTable
(using the the table's RowIterator) they are
added to the ring buffer (and "old" rows
are deleted). Each time a row is requested that resides before the cursor
of the current iterator and is not in the cache (default size: 500), the
cache is cleared and a new iterator is instantiated. Thus, this class will
have some performance problems when the user scrolls up in the table view.
However, when scrolling down, the data flow is somewhat "fluent".
This class also supports hiliting of rows (even though it is a view property). We do store the hilite status of the rows in here as it complies nicely with the caching strategy.
DataTable,
Serialized Form| Nested Class Summary | |
|---|---|
static class |
TableContentModel.TableContentFilter
Possible hilite filter incarnations. |
| Field Summary | |
|---|---|
static int |
CACHE_SIZE
Default size of the ring buffer (500). |
static int |
CHUNK_SIZE
Number of rows being read at a time (50). |
static String |
PROPERTY_DATA
Property name of the event when the data table has changed. |
static String |
PROPERTY_HILITE
Property name of the event when hilite handler changes. |
| Fields inherited from class javax.swing.table.AbstractTableModel |
|---|
listenerList |
| Constructor Summary | |
|---|---|
TableContentModel()
Creates a new TableContentModel with empty content. |
|
TableContentModel(DataTable data)
Creates a new TableContentModel displaying data. |
|
TableContentModel(DataTable data,
HiLiteHandler prop)
Creates a new TableContentModel displaying data. |
|
| Method Summary | |
|---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds property change listener to this instance. |
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Adds property change listener to this instance. |
protected void |
boundColumn(int columnIndex)
Checks if given argument is in range and throws an exception if it is not. |
protected void |
boundRow(int rowIndex)
Checks if given argument is in range and throws an exception if it is not. |
void |
cancelRowCountingInBackground()
Cancels the potential row counter thread invoked by countRowsInBackground(). |
protected void |
clearCache()
Clears cache, instantiates new Iterator. |
void |
countRowsInBackground()
Starts a new internal thread that will iterate over the table and count the rows in it. |
int |
getCacheSize()
Get the size of the cache. |
int |
getChunkSize()
Get the chunk size. |
ColorAttr |
getColorAttr(int row)
Get the color information for a row. |
Class<DataCell> |
getColumnClass(int column)
Returns DataCell.class. |
int |
getColumnCount()
Get the column count. |
String |
getColumnName(int colIndex)
Get the column header for some specific column index. |
DataTable |
getDataTable()
Get reference to underlying DataTable as it was passed
in the constructor or changed by successive calls of
setDataTable(DataTable). |
DataTableSpec |
getDataTableSpec()
Get the table spec of the current DataTable. |
HiLiteHandler |
getHiLiteHandler()
Return a reference to the hilite handler currently being used. |
protected PropertyChangeSupport |
getPropertyChangeSupport()
Get reference to PropertyChangeSupport to allow subclasses
to fire customized events. |
protected DataRow |
getRow(int row)
Gets a row with a specified index. |
int |
getRowCount()
Get the number of rows in this model. |
RowKey |
getRowKey(int row)
Get the row key for a given row index. |
TableContentModel.TableContentFilter |
getTableContentFilter()
|
String |
getTableName()
Get the name of the current data table (if any) or null. |
TableSortOrder |
getTableSortOrder()
|
DataCell |
getValueAt(int row,
int column)
Get the DataCell at a specific location. |
boolean |
hasData()
Is there valid data to show? |
boolean |
hasHiLiteHandler()
Is there a HiLiteHandler connected? |
boolean |
hasListeners(String propertyName)
Are there listeners registered to this class? |
void |
hiLite(KeyEvent e)
Invoked when some item(s) were hilit. |
boolean |
isHiLit(int row)
Is the Row row hilited? The row with the index will
be cached (if it hasn't been in there) and the hilite status of the
row is returned. |
boolean |
isRowCountFinal()
Returns true if the iterator has traversed the whole
DataTable at least once. |
boolean |
isSortingAllowed()
Whether interactive sorting on column header click is enabled (default is false). |
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a listener from this instance. |
void |
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Removes a listener from this instance. |
protected void |
requestHiLite(ListSelectionModel selModel)
HiLites all rows that are selected according to the given selection model. |
protected void |
requestResetHiLite()
Resets the hiliting of all keys by invoking the reset method in the HiLiteHandler. |
void |
requestSort(int column,
JComponent parComponent)
Sorts the table according the argument column. |
protected void |
requestUnHiLite(ListSelectionModel selModel)
"Unhilites" all rows that are selected according to the given selection model. |
protected int |
setCacheSize(int size)
Changes the size of the ring buffer so that size rows
can be cached. |
protected int |
setChunkSize(int newSize)
Set a new chunk size. |
void |
setDataTable(DataTable data)
Sets new data for this table. |
(package private) void |
setDataTableOnSort(DataTable data,
TableSortOrder newOrder)
Sets new data for this table. |
void |
setHiLiteHandler(HiLiteHandler hiliter)
Set a new HiLiteHandler. |
(package private) void |
setRowCount(int newCount,
boolean isFinal)
Used by the row counter thread to inform about new rows. |
void |
setSortingAllowed(boolean isSortingAllowed)
Enables/disables interactive sorting, which is usually invoked by clicking the column header. |
void |
setTableContentFilter(TableContentModel.TableContentFilter newFilter)
Set new filter instance. |
void |
showHiLitedOnly(boolean showOnlyHilite)
Deprecated. This method has been replaced by setTableContentFilter(TableContentFilter). |
boolean |
showsHiLitedOnly()
Deprecated. This method has been replaced by getTableContentFilter() |
void |
unHiLite(KeyEvent e)
Invoked when some item(s) were unhilit. |
void |
unHiLiteAll(KeyEvent event)
Invoked, when everything (all rows) are unhilit. |
| Methods inherited from class javax.swing.table.AbstractTableModel |
|---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.knime.core.node.tableview.TableContentInterface |
|---|
addTableModelListener, removeTableModelListener |
| Field Detail |
|---|
public static final String PROPERTY_DATA
public static final String PROPERTY_HILITE
public static final int CACHE_SIZE
public static final int CHUNK_SIZE
DataTable's
iterator to get CHUNK_SIZE new rows which are added to the
cache.
Suppose you have a table with more than 100 rows: Those are then accessed
| Constructor Detail |
|---|
public TableContentModel()
setDataTable(DataTable) to set a valid data table. No
HiLiting is available.
setDataTable(DataTable),
setHiLiteHandler(HiLiteHandler)public TableContentModel(DataTable data)
data.
No HiLiting is available.
data - the table to be displayed. May be null to
indicate that there is no data available.
public TableContentModel(DataTable data,
HiLiteHandler prop)
data.
If prop is not null, its
HiLiteHandler is used to do hilite synchronization.
data - the table to be displayed. May be null to
indicate that there is no data available.prop - the HiLiteHandler However, may
also be null to disable any hiliting.| Method Detail |
|---|
public void setDataTable(DataTable data)
null to
indicate invalid data (nothing displayed).
data - the new data being displayed or null
void setDataTableOnSort(DataTable data,
TableSortOrder newOrder)
data - the new data being displayednewOrder - the new order of the sorted data (needed for the next
sort and for the display in the table header)public TableSortOrder getTableSortOrder()
public void countRowsInBackground()
cancelRowCountingInBackground().
public void cancelRowCountingInBackground()
countRowsInBackground(). If this method has not been called
yet, this method does nothing.
public void setHiLiteHandler(HiLiteHandler hiliter)
HiLiteHandler. If the argument is
null hiliting is disabled.
hiliter - the new handler to use.public HiLiteHandler getHiLiteHandler()
null if none is setpublic boolean isSortingAllowed()
setSortingAllowed(boolean)public final void setSortingAllowed(boolean isSortingAllowed)
requestSort(int, JComponent) call is ignored or not.
The default is false, i.e. sorting is not allowed.
isSortingAllowed - the isSortingAllowed to set
public final void requestSort(int column,
JComponent parComponent)
isSortingAllowed() is false.
column - The column that was clicked. It will be sorted either
ascending or descending (or unsorted) depending on the previous sorting.parComponent - The parent component. The worker will create a modal
progress dialog on this component.public final boolean hasData()
true if underlying DataTable is not
nullpublic String getTableName()
null.
null.public final boolean hasHiLiteHandler()
true if global hiliting is possible@Deprecated public final void showHiLitedOnly(boolean showOnlyHilite)
setTableContentFilter(TableContentFilter).
showOnlyHilite - true Filter and display only rows
whose hilite status is set.@Deprecated public boolean showsHiLitedOnly()
getTableContentFilter()
true if only hilited rows are shown,
false if all rows are shown.public final void setTableContentFilter(TableContentModel.TableContentFilter newFilter)
newFilter - The new filter to be applied.
NullPointerException - If argument is null.public TableContentModel.TableContentFilter getTableContentFilter()
public int getColumnCount()
getColumnCount in interface TableModelDataTable
or 0 if hasData() returns false.public int getRowCount()
DataTable. (Note,
the final size of a DataTable is not necessarily known in advance.) The
row count is updated each time a new row is requested. The return value
is:
DataTable, if the table
was traversed completely at least once.
getRowCount in interface TableModelgetRowCount in interface TableContentInterfaceTableModel.getRowCount()
public DataCell getValueAt(int row,
int column)
getValueAt in interface TableModelrow - the row indexcolumn - the column index
DataCell in the underlying
DataTable at position [row, column]
IndexOutOfBoundsException - if either argument violates its rangepublic RowKey getRowKey(int row)
getRowKey in interface TableContentInterfacerow - The row index.
public String getColumnName(int colIndex)
DataCell
toString() method.
getColumnName in interface TableModelgetColumnName in class AbstractTableModelcolIndex - the column's index
colIndex
IndexOutOfBoundsException - if colIndex out of rangeAbstractTableModel.getColumnName(int),
DataColumnSpec.getName()public Class<DataCell> getColumnClass(int column)
getColumnClass in interface TableModelgetColumnClass in class AbstractTableModelpublic final DataTable getDataTable()
DataTable as it was passed
in the constructor or changed by successive calls of
setDataTable(DataTable).
null if hasData()
returns falseTableContentModel(DataTable)public DataTableSpec getDataTableSpec()
null
if the model is currently not having a table.
public boolean isRowCountFinal()
true if the iterator has traversed the whole
DataTable at least once. The value returned by
getRowCount() is therefore final. It returns
false if the value can still increase.
Note: The row count may not increase even if
isRowCountFinal() returns false. This unlikely
case occurs when - by chance - getRowCount() + 1 is indeed
the final row count. See the getRowCount() method
for further details.
protected final int setCacheSize(int size)
size rows
can be cached. This method will clear the current cache. The cache should
have at least a size so that all rows that are displayed at a time can
be buffered (however, no further checking is carried out).
If size is less than twice the chunk size, i.e.
size < 2*getChunkSize(), it will be set to it.
So when a "new" row is requested, at least getChunkSize()
rows after (including that row) and before the new row will be also in
the cache.
size - size of the new cache.
size, see above)
IllegalArgumentException - if size <= 0.public final int getCacheSize()
CACHE_SIZEprotected final int setChunkSize(int newSize)
CHUNK_SIZE
on start-up. The new value can be at most getCacheSize()/2.
If it is bigger, it's value is reduced to getCacheSize()/2.
newSize - the new value
IllegalArgumentException - if newSize is <= 0.getCacheSize()public final int getChunkSize()
CHUNK_SIZE.public boolean isHiLit(int row)
row hilited? The row with the index will
be cached (if it hasn't been in there) and the hilite status of the
row is returned. This method may change the current cache content since
it ensures row is in the cache.
isHiLit in interface TableContentInterfacerow - The row index of interest
true If that index is currently hilitedpublic ColorAttr getColorAttr(int row)
getColorAttr in interface TableContentInterfacerow - The row of interest
protected void requestHiLite(ListSelectionModel selModel)
selModel - To get selection status from
NullPointerException - if selModel is nullprotected void requestUnHiLite(ListSelectionModel selModel)
selModel - To get selection status from
NullPointerException - if selModel is nullprotected void requestResetHiLite()
HiLiteHandler. This method does nothing if no handler
is connected.
HiLiteHandler.fireClearHiLiteEvent()public void hiLite(KeyEvent e)
hiLite in interface HiLiteListenere - contains a list of row keys that were hilitpublic void unHiLite(KeyEvent e)
unHiLite in interface HiLiteListenere - contains a list of row keys that were unhilitpublic void unHiLiteAll(KeyEvent event)
unHiLiteAll in interface HiLiteListenerevent - contains a list of row key that were unhilitprotected DataRow getRow(int row)
row - row index of interest
IndexOutOfBoundsException - if row violates its rangeprotected void clearCache()
void setRowCount(int newCount,
boolean isFinal)
newCount - the new row countisFinal - if there are possibly more rows to countpublic void addPropertyChangeListener(PropertyChangeListener listener)
listener - A new listener to register.#addPropertyChangeListener(PropertyChangeListener)
public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
propertyName - only events with that id are fired to the listener.listener - the listener to register here#addPropertyChangeListener(String, PropertyChangeListener)public boolean hasListeners(String propertyName)
propertyName - property name of interest
true if there are known listeners,
false otherwisePropertyChangeSupport.hasListeners(java.lang.String)public void removePropertyChangeListener(PropertyChangeListener listener)
listener - listener to be removed#removePropertyChangeListener(PropertyChangeListener)
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
propertyName - only if it listens to this property idlistener - listener to be removed#removePropertyChangeListener(String, PropertyChangeListener)protected final PropertyChangeSupport getPropertyChangeSupport()
PropertyChangeSupport to allow subclasses
to fire customized events.
null.protected final void boundRow(int rowIndex)
rowIndex - row index to check
IndexOutOfBoundsException - if argument violates rangeprotected final void boundColumn(int columnIndex)
columnIndex - column index to check
IndexOutOfBoundsException - if argument violates range
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||