T
- the type of elements in this table modelpublic abstract class PagingTableModel<T> extends AbstractTableModel
TableModel
. The model will have at most, by default, 50 rows loaded in memory at any given time. The advertised row count will be
of all the entries (as if they were all loaded in memory).
If a JTable
, using this model, is wrapped in a JScrollPane
the vertical scroll
bar will be shown as if all the entries were loaded.
Rows (page segments) will be loaded in a separate thread, on demand.
Implementation based on PagingTableModel located in http://www.coderanch.com/t/345383/GUI/java/JTable-Paging, with permission from the author, Brian
Cole ([email protected], http://bitguru.com).
Contains the following changes:
loadPage(int, int)
,
setMaxPageSize(int)
,
TableModel
,
JTable
,
JScrollPane
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_PAGE_SIZE
Default maximum page size.
|
static String |
DEFAULT_SEGMENT_LOADER_THREAD_NAME
Default segment loader thread name.
|
listenerList
Constructor and Description |
---|
PagingTableModel()
Constructs a
PagingTableModel with default default segment loader thread name (
"ZAP-PagingTableModel-SegmentLoaderThread") and default maximum page size (50). |
PagingTableModel(int maxPageSize)
Constructs a
PagingTableModel with the given maximum page size and default segment
loader thread name ( "ZAP-PagingTableModel-SegmentLoaderThread"). |
PagingTableModel(String segmentLoaderThreadName)
Constructs a
PagingTableModel with the given segment loader thread name and default
maximum page size (50). |
PagingTableModel(String segmentLoaderThreadName,
int maxPageSize)
Constructs a
PagingTableModel with the given segment loader thread name and given
maximum page size. |
Modifier and Type | Method and Description |
---|---|
protected void |
clear() |
void |
fireTableDataChanged() |
int |
getMaxPageSize()
Returns the maximum page size.
|
protected abstract Object |
getPlaceholderValueAt(int columnIndex)
Gets the placeholder value that should be shown for the given column, until the actual values
are ready to be shown.
|
protected abstract Object |
getRealValueAt(T rowObject,
int columnIndex)
Called by
getValueAt(int, int) when requested row is already loaded. |
abstract int |
getRowCount()
Returns the number of all items.
|
protected T |
getRowObject(int rowIndex)
Gets the object at the given row.
|
Object |
getValueAt(int rowIndex,
int columnIndex) |
protected abstract List<T> |
loadPage(int offset,
int length)
Called when a new page is required.
|
void |
setMaxPageSize(int maxPageSize)
Sets the maximum size of the page.
|
void |
setMaxPageSizeWithoutPageChanges(int maxPageSize)
Sets the maximum size of the page.
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getColumnCount
public static final String DEFAULT_SEGMENT_LOADER_THREAD_NAME
public static final int DEFAULT_MAX_PAGE_SIZE
public PagingTableModel()
PagingTableModel
with default default segment loader thread name (
"ZAP-PagingTableModel-SegmentLoaderThread") and default maximum page size (50).public PagingTableModel(String segmentLoaderThreadName)
PagingTableModel
with the given segment loader thread name and default
maximum page size (50).segmentLoaderThreadName
- the name for segment loader threadIllegalArgumentException
- if maxPageSize
is negative or zero.public PagingTableModel(int maxPageSize)
PagingTableModel
with the given maximum page size and default segment
loader thread name ( "ZAP-PagingTableModel-SegmentLoaderThread").maxPageSize
- the maximum page sizeIllegalArgumentException
- if maxPageSize
is negative or zero.public PagingTableModel(String segmentLoaderThreadName, int maxPageSize)
PagingTableModel
with the given segment loader thread name and given
maximum page size.segmentLoaderThreadName
- the name for segment loader threadmaxPageSize
- the maximum page sizeIllegalArgumentException
- if maxPageSize
is negative or zero.public int getMaxPageSize()
public void setMaxPageSize(int maxPageSize)
If the given maximum size is greater than the current maximum size a new page will be
loaded, otherwise the current page will be shrunk to meet the given maximum size. In both
cases the TableModelListener
will be notified of the change.
The call to this method has no effect if the given maximum size is equal to the current maximum size.
maxPageSize
- the new maximum page sizeIllegalArgumentException
- if maxPageSize
is negative or zero.setMaxPageSizeWithoutPageChanges(int)
,
TableModelListener
public void setMaxPageSizeWithoutPageChanges(int maxPageSize)
As opposed to method #setMaxPageSize(int)
no changes will be made to the current
page.
maxPageSize
- the new maximum page sizeIllegalArgumentException
- if maxPageSize
is negative or zero.setMaxPageSize(int)
public void fireTableDataChanged()
fireTableDataChanged
in class AbstractTableModel
public abstract int getRowCount()
protected abstract Object getRealValueAt(T rowObject, int columnIndex)
getValueAt(int, int)
when requested row is already loaded.rowObject
- the row objectcolumnIndex
- the column indexprotected abstract Object getPlaceholderValueAt(int columnIndex)
columnIndex
- the column indexprotected abstract List<T> loadPage(int offset, int length)
The returned List
should support fast (preferably constant time) random access.
offset
- the start offset of the pagelength
- the length of the pageList.get(int)
public final Object getValueAt(int rowIndex, int columnIndex)
protected T getRowObject(int rowIndex)
rowIndex
- the index of the rownull
if object is not in the current pageprotected void clear()