|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.table.AbstractTableModel com.jidesoft.grid.TableModelWrapperImpl com.jidesoft.grid.CachedTableModel
public class CachedTableModel
CachedTableModel is a table model that can cache the table data. If you use DefaultTableModel,
there is no need to cache the data because the data are actually in the data list. However if you are using
AbstractTableModel and getValueAt() gets the data on fly, you will suffer from performance issue if
getValueAt() is complex. CachedTableModel can solve this issue by caching the value. So each getValueAt()
will be called only once. When data changes, as long as the underlying table model fires the correct table model
event, the cache will update automatically to fetch the new value. If you want to invalidate the cache yourself, you
can always use methods such as invalidateCache()
, invalidateCache(int)
or invalidateCache(int,int)
to invalidate all the cache or portions of it.
setCacheEnabled(boolean)
to disable the caching. Or you can call setCachedColumns(int[])
to specify which columns you want to cache. For example, if the cell value in a column is a
direct value without calculation, you can disable the cache on that column to save memory.
Field Summary | |
---|---|
protected int[] |
_cachedColumns
|
protected List<Object> |
_cachedValueList
The List of Lists of Object values. |
protected int[] |
_conversionIndex
|
Fields inherited from class com.jidesoft.grid.TableModelWrapperImpl |
---|
_model |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Fields inherited from interface com.jidesoft.grid.MultiTableModel |
---|
FOOTER_COLUMN, HEADER_COLUMN, REGULAR_COLUMN |
Fields inherited from interface com.jidesoft.grid.EditorStyleTableModel |
---|
EDITOR_STYLE_EDITABLE, EDITOR_STYLE_NORMAL, EDITOR_STYLE_READ_ONLY, EDITOR_STYLE_SELECT_ONLY |
Constructor Summary | |
---|---|
CachedTableModel(TableModel model)
Constructs a default DefaultTableModel which is a table of zero columns and zero rows. |
Method Summary | |
---|---|
void |
cacheIt()
Cached all the values. |
int |
getActualRowAt(int visualRow)
Gets the actual row index in the underlying table that corresponds the specified row index. |
int[] |
getCachedColumns()
|
protected List<Object> |
getCachedRows()
Gets the cached rows. |
Class<?> |
getCellClassAt(int row,
int column)
Gets the cell class of the underlying table model. |
ConverterContext |
getConverterContextAt(int row,
int column)
Gets the converter context of the underlying table model. |
EditorContext |
getEditorContextAt(int row,
int column)
Gets the editor context of the underlying table model. |
Object |
getValueAt(int row,
int column)
Returns an attribute value for the cell at row and column . |
int |
getVisualRowAt(int actualRow)
Gets the visual row index representing the specified actual row. |
protected void |
insertCache(int rowIndex)
Inserts a new row data at the specified rowIndex. |
void |
invalidateCache()
Invalidate the whole cache. |
void |
invalidateCache(int row)
Invalidate the cache at the specified row index. |
void |
invalidateCache(int row,
int column)
Invalidate the cache at the specified row and column. |
protected boolean |
isCachedValueValid(int row,
int column)
Checks if the cached value at the specified row and column is valid. |
boolean |
isCacheEnabled()
Checks if cache is enabled. |
boolean |
isCellEditable(int row,
int column)
|
boolean |
isColumnCached(int column)
Checks if the column is cached. |
protected void |
removeCache(int rowIndex)
Removes the cached row data at the specified rowIndex. |
void |
setCachedColumns(int[] cachedColumns)
Sets the columns you want to cache. |
void |
setCacheEnabled(boolean cacheEnabled)
Enables or disables the cache. |
void |
setValueAt(Object value,
int row,
int column)
|
protected void |
tableCellsUpdated(int column,
int firstRow,
int lastRow)
Overrides the method in DefaultTableModelWrapper to update the cache when underlying table model is changed. |
protected void |
tableDataChanged()
Overrides the method in DefaultTableModelWrapper to update the cache when underlying table model is changed. |
protected void |
tableRowsDeleted(int firstRow,
int lastRow)
Overrides the method in DefaultTableModelWrapper to update the cache when underlying table model is changed. |
protected void |
tableRowsInserted(int firstRow,
int lastRow)
Overrides the method in DefaultTableModelWrapper to update the cache when underlying table model is changed. |
protected void |
tableRowsUpdated(int firstRow,
int lastRow)
Overrides the method in DefaultTableModelWrapper to update the cache when underlying table model is changed. |
protected void |
tableStructureChanged()
Overrides the method in DefaultTableModelWrapper to update the cache when underlying table model is changed. |
protected void |
updateCachedValue(Object value,
int row,
int column)
Updates the cache at the specified row and column with a new value. |
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
addTableModelListener, findColumn, fireTableCellUpdated, 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 com.jidesoft.grid.TableModelWrapper |
---|
getActualModel |
Methods inherited from interface javax.swing.table.TableModel |
---|
addTableModelListener, removeTableModelListener |
Field Detail |
---|
protected transient List<Object> _cachedValueList
List
of Lists
of Object
values.
protected int[] _cachedColumns
protected int[] _conversionIndex
Constructor Detail |
---|
public CachedTableModel(TableModel model)
DefaultTableModel
which is a table of zero columns and zero rows.
model
- the table model.Method Detail |
---|
public boolean isCacheEnabled()
public void setCacheEnabled(boolean cacheEnabled)
cacheEnabled
- true or false.protected void tableRowsInserted(int firstRow, int lastRow)
tableRowsInserted
in class TableModelWrapperImpl
firstRow
- the index of the first row that was insertedlastRow
- the index of the last row that was insertedprotected void tableRowsDeleted(int firstRow, int lastRow)
tableRowsDeleted
in class TableModelWrapperImpl
firstRow
- the index of the first row that was deletedlastRow
- the index of the last row that was deletedprotected void tableRowsUpdated(int firstRow, int lastRow)
tableRowsUpdated
in class TableModelWrapperImpl
firstRow
- the index of the first row that was updatedlastRow
- the index of the last row that was updatedprotected void tableCellsUpdated(int column, int firstRow, int lastRow)
tableCellsUpdated
in class TableModelWrapperImpl
column
- the index of the column that was updatedfirstRow
- the index of the first row in the above column
that was updatedlastRow
- the index of the last row in the above column
that was updatedprotected void tableDataChanged()
tableDataChanged
in class TableModelWrapperImpl
protected void tableStructureChanged()
tableStructureChanged
in class TableModelWrapperImpl
protected boolean isCachedValueValid(int row, int column)
row
- the row index.column
- the column index.
public void invalidateCache()
public void invalidateCache(int row)
row
- the row index.public void invalidateCache(int row, int column)
row
- the row index.column
- the column index.protected void removeCache(int rowIndex)
rowIndex
- the row indexprotected void insertCache(int rowIndex)
rowIndex
- the row indexprotected void updateCachedValue(Object value, int row, int column)
value
- the new valuerow
- the row indexcolumn
- the column indexpublic Object getValueAt(int row, int column)
row
and column
. If the cached is enabled, it
will get the data from the cache first. If the data is not in cache or it is not valid, it will then get the data
from the actual table model and update the cache.
getValueAt
in interface TableModel
getValueAt
in class TableModelWrapperImpl
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queried
ArrayIndexOutOfBoundsException
- if an invalid row or column was givenpublic boolean isCellEditable(int row, int column)
isCellEditable
in interface TableModel
isCellEditable
in class TableModelWrapperImpl
public Class<?> getCellClassAt(int row, int column)
TableModelWrapperImpl
ContextSensitiveTableModel
. If not, it will return underlying model's
getColumnClass(column).
getCellClassAt
in interface ContextSensitiveTableModel
getCellClassAt
in class TableModelWrapperImpl
row
- the row index.column
- the column index.
public ConverterContext getConverterContextAt(int row, int column)
TableModelWrapperImpl
ContextSensitiveTableModel
. If not, it will return null.
getConverterContextAt
in interface ContextSensitiveTableModel
getConverterContextAt
in class TableModelWrapperImpl
row
- the row index.column
- the column index.
public EditorContext getEditorContextAt(int row, int column)
TableModelWrapperImpl
ContextSensitiveTableModel
. If not, it will return null.
getEditorContextAt
in interface ContextSensitiveTableModel
getEditorContextAt
in class TableModelWrapperImpl
row
- the row index.column
- the column index.
protected List<Object> getCachedRows()
public void cacheIt()
public int[] getCachedColumns()
public void setCachedColumns(int[] cachedColumns)
cachedColumns
- the column index array. Null means all columns will be cached.public boolean isColumnCached(int column)
column
- the column index
public int getActualRowAt(int visualRow)
RowTableModelWrapper
getActualRowAt
in interface RowTableModelWrapper
visualRow
- the visual row index.
public int getVisualRowAt(int actualRow)
RowTableModelWrapper
getVisualRowAt
in interface RowTableModelWrapper
actualRow
- the actual row index.
public void setValueAt(Object value, int row, int column)
setValueAt
in interface TableModel
setValueAt
in class TableModelWrapperImpl
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |