Module is.codion.swing.common.model
Interface FilteredTableModel<R,C>
- Type Parameters:
R
- the type representing the rows in this table modelC
- the type used to identify columns in this table model, Integer for indexed identification for example
- All Superinterfaces:
FilteredModel<R>
,TableModel
- All Known Implementing Classes:
SwingEntityTableModel
Specifies a table model supporting selection as well as filtering
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A builder for aFilteredTableModel
.static interface
Provides columns for aFilteredTableModel
.static interface
Provides the column value for a row and columnstatic interface
Specifies the from and to rows of a row removal operation.Nested classes/interfaces inherited from interface is.codion.common.model.FilteredModel
FilteredModel.AbstractRefresher<T>, FilteredModel.Refresher<T>
-
Field Summary
Fields inherited from interface is.codion.common.model.FilteredModel
ASYNC_REFRESH
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addClearListener
(Runnable listener) void
addDataChangedListener
(Runnable listener) void
Adds the given item to the bottom of this table model.void
void
addItems
(Collection<R> items) Adds the given items to the bottom of this table model.void
addItemsAt
(int index, Collection<R> items) Adds the given items to this table model, non-filtered items are added at the given index.void
addItemsAtSorted
(int index, Collection<R> items) Adds the given items to this table model, non-filtered items are added at the given index.void
addItemSorted
(R item) Adds the given item to the bottom of this table model.void
addItemsSorted
(Collection<R> items) Adds the given items to the bottom of this table model.void
Adds a listener that is notified each time rows are removed from this model.static <R,
C> FilteredTableModel.Builder<R, C> builder
(FilteredTableModel.ColumnFactory<C> columnFactory, FilteredTableModel.ColumnValueProvider<R, C> columnValueProvider) Instantiates a new table model builder.void
clear()
Clears all items from this table modelvoid
Notifies all listeners that all cell values in the table's rows may have changed.void
fireTableRowsUpdated
(int fromIndex, int toIndex) Notifies all listeners that the given rows have changedClass<?>
getColumnClass
(C columnIdentifier) Returns the class of the column with the given identifiergetStringAt
(int rowIndex, C columnIdentifier) Returns a String representation of the value for the given row and column.int
itemAt
(int rowIndex) Note that when merging during refresh, the items are not sorted, since that would cause an empty-selection event, defeating the purpose of merging.void
refresh()
Refreshes the items in this filtered model using itsFilteredModel.Refresher
.void
refreshThen
(Consumer<Collection<R>> afterRefresh) Refreshes the data in this filtered model using itsFilteredModel.Refresher
.void
removeClearListener
(Runnable listener) void
removeDataChangedListener
(Runnable listener) void
removeItem
(R item) Removes the given item from this table modelremoveItemAt
(int index) Removes from this table model the visible element whose index is between indexremoveItems
(int fromIndex, int toIndex) Removes from this table model all visible elements whose index is between fromIndex, inclusive and toIndex, exclusivevoid
removeItems
(Collection<R> items) Removes the given items from this table modelvoid
rowsAsDelimitedString
(char delimiter) <T> Collection<T>
selectedValues
(C columnIdentifier) void
Sets the item at the given index.void
Sorts the visible items according to theFilteredTableSortModel
, keeping the selected items.static <T extends Number,
C>
ColumnSummaryModel.SummaryValueProvider<T>summaryValueProvider
(C columnIdentifier, FilteredTableModel<?, C> tableModel, Format format) Instantiates a newColumnSummaryModel.SummaryValueProvider
instance.<T> Collection<T>
Methods inherited from interface is.codion.common.model.FilteredModel
containsItem, filtered, filteredCount, filteredItems, filterItems, includeCondition, items, refresher, visible, visibleCount, visibleItems
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt
-
Method Details
-
addDataChangedListener
- Parameters:
listener
- a listener to be notified each time the table data changes
-
removeDataChangedListener
- Parameters:
listener
- the listener to remove
-
addClearListener
- Parameters:
listener
- a listener to be notified each time the table model is cleared
-
removeClearListener
- Parameters:
listener
- the listener to remove
-
addRowsRemovedListener
Adds a listener that is notified each time rows are removed from this model.- Parameters:
listener
- the listener
-
removeRowsRemovedListener
- Parameters:
listener
- the listener to remove
-
indexOf
- Parameters:
item
- the item- Returns:
- the index of the item in the table model
-
itemAt
- Parameters:
rowIndex
- the row index- Returns:
- the item at the given row index in the table model
-
getStringAt
Returns a String representation of the value for the given row and column.- Parameters:
rowIndex
- the row indexcolumnIdentifier
- the column identifier- Returns:
- the string value
-
addItems
Adds the given items to the bottom of this table model.- Parameters:
items
- the items to add
-
addItemsSorted
Adds the given items to the bottom of this table model. If sorting is enabled this model is sorted after the items have been added.- Parameters:
items
- the items to add
-
addItemsAt
Adds the given items to this table model, non-filtered items are added at the given index.- Parameters:
index
- the index at which to add the itemsitems
- the items to add
-
addItemsAtSorted
Adds the given items to this table model, non-filtered items are added at the given index. If sorting is enabled this model is sorted after the items have been added.- Parameters:
index
- the index at which to add the itemsitems
- the items to add- See Also:
-
addItem
Adds the given item to the bottom of this table model.- Parameters:
item
- the item to add
-
addItemAt
- Parameters:
index
- the indexitem
- the item to add
-
addItemSorted
Adds the given item to the bottom of this table model. If sorting is enabled this model is sorted after the item has been added.- Parameters:
item
- the item to add
-
setItemAt
Sets the item at the given index. If the item should be filtered calling this method has no effect.- Parameters:
index
- the indexitem
- the item- See Also:
-
removeItems
Removes the given items from this table model- Parameters:
items
- the items to remove from the model
-
removeItem
Removes the given item from this table model- Parameters:
item
- the item to remove from the model
-
removeItemAt
Removes from this table model the visible element whose index is between index- Parameters:
index
- the index of the row to be removed- Returns:
- the removed item
- Throws:
IndexOutOfBoundsException
- in case the indexe is out of bounds
-
removeItems
Removes from this table model all visible elements whose index is between fromIndex, inclusive and toIndex, exclusive- Parameters:
fromIndex
- index of first row to be removedtoIndex
- index after last row to be removed- Returns:
- the removed items
- Throws:
IndexOutOfBoundsException
- in case the indexes are out of bounds
-
values
- Type Parameters:
T
- the value type- Parameters:
columnIdentifier
- the identifier of the column for which to retrieve the values- Returns:
- the values (including nulls) of the column identified by the given identifier from the visible rows in the table model
-
getColumnClass
Returns the class of the column with the given identifier- Parameters:
columnIdentifier
- the column identifier- Returns:
- the Class representing the given column
-
selectedValues
- Type Parameters:
T
- the value type- Parameters:
columnIdentifier
- the identifier of the column for which to retrieve the values- Returns:
- the values (including nulls) of the column identified by the given identifier from the selected rows in the table model
-
rowsAsDelimitedString
- Parameters:
delimiter
- the delimiter- Returns:
- the table rows as a tab delimited string, with column names as a header
-
mergeOnRefresh
State mergeOnRefresh()Note that when merging during refresh, the items are not sorted, since that would cause an empty-selection event, defeating the purpose of merging.- Returns:
- the State controlling whether merge on refresh should be enabled
-
sortItems
void sortItems()Sorts the visible items according to theFilteredTableSortModel
, keeping the selected items. Calling this method with the sort model disabled has no effect.- See Also:
-
columnModel
FilteredTableColumnModel<C> columnModel()- Returns:
- the FilteredTableColumnModel used by this TableModel
-
selectionModel
FilteredTableSelectionModel<R> selectionModel()- Returns:
- the selection model used by this table model
-
sortModel
FilteredTableSortModel<R,C> sortModel()- Returns:
- the sorting model
-
searchModel
FilteredTableSearchModel searchModel()- Returns:
- the search model
-
filterModel
TableConditionModel<C> filterModel()- Returns:
- the filter model used by this table model
-
summaryModel
TableSummaryModel<C> summaryModel()- Returns:
- the summary model
-
refresh
void refresh()Refreshes the items in this filtered model using itsFilteredModel.Refresher
.
Retains the selection and filtering. Sorts the refreshed data unless merging on refresh is enabled. Note that an empty selection event will be triggered during a normal refresh, since the model is cleared before it is repopulated, during which the selection is cleared as well. Using merge on refresh (mergeOnRefresh()
) will prevent that at a considerable performance cost.- Specified by:
refresh
in interfaceFilteredModel<R>
- See Also:
-
refreshThen
Refreshes the data in this filtered model using itsFilteredModel.Refresher
. Note that this method only throws exceptions when run synchronously off the user interface thread. UseFilteredModel.Refresher.addRefreshFailedListener(Consumer)
to listen for exceptions that happen during asynchronous refresh.
Retains the selection and filtering. Sorts the refreshed data unless merging on refresh is enabled. Note that an empty selection event will be triggered during a normal refresh, since the model is cleared before it is repopulated, during which the selection is cleared as well. Using merge on refresh (mergeOnRefresh()
) will prevent that at a considerable performance cost.- Specified by:
refreshThen
in interfaceFilteredModel<R>
- Parameters:
afterRefresh
- called after a successful refresh, may be null- See Also:
-
clear
void clear()Clears all items from this table model -
fireTableDataChanged
void fireTableDataChanged()Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same. -
fireTableRowsUpdated
void fireTableRowsUpdated(int fromIndex, int toIndex) Notifies all listeners that the given rows have changed- Parameters:
fromIndex
- the from indextoIndex
- the to index
-
builder
static <R,C> FilteredTableModel.Builder<R,C> builder(FilteredTableModel.ColumnFactory<C> columnFactory, FilteredTableModel.ColumnValueProvider<R, C> columnValueProvider) Instantiates a new table model builder.- Type Parameters:
R
- the row typeC
- the column identifier type- Parameters:
columnFactory
- the column factorycolumnValueProvider
- the column value provider- Returns:
- a new builder instance
- Throws:
NullPointerException
- in casecolumnFactory
orcolumnValueProvider
is null
-
summaryValueProvider
static <T extends Number,C> ColumnSummaryModel.SummaryValueProvider<T> summaryValueProvider(C columnIdentifier, FilteredTableModel<?, C> tableModel, Format format) Instantiates a newColumnSummaryModel.SummaryValueProvider
instance.- Type Parameters:
T
- the column value typeC
- the column identifier type- Parameters:
columnIdentifier
- the column identifiertableModel
- the table modelformat
- the format, may be null- Returns:
- a new
ColumnSummaryModel.SummaryValueProvider
instance
-