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:
is.codion.common.model.FilteredModel<R>,TableModel
public interface FilteredTableModel<R,C>
extends TableModel, is.codion.common.model.FilteredModel<R>
Specifies a table model supporting selection as well as filtering
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder for aFilteredTableModel.static interfaceProvides columns for aFilteredTableModel.static interfaceProvides the column value for a row and columnstatic interfaceSpecifies the from and to rows of a row removal operation. -
Field Summary
Fields inherited from interface is.codion.common.model.FilteredModel
ASYNC_REFRESH -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClearListener(Runnable listener) voidaddDataChangedListener(Runnable listener) voidAdds the given item to the bottom of this table model.voidvoidaddItems(Collection<R> items) Adds the given items to the bottom of this table model.voidaddItemsAt(int index, Collection<R> items) Adds the given items to this table model, non-filtered items are added at the given index.voidaddItemsAtSorted(int index, Collection<R> items) Adds the given items to this table model, non-filtered items are added at the given index.voidaddItemSorted(R item) Adds the given item to the bottom of this table model.voidaddItemsSorted(Collection<R> items) Adds the given items to the bottom of this table model.voidAdds 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.voidclear()Clears all items from this table modelis.codion.common.model.table.TableConditionModel<C>voidNotifies all listeners that all cell values in the table's rows may have changed.voidfireTableRowsUpdated(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.intitemAt(int rowIndex) is.codion.common.state.StateNote that when merging during refresh, the items are not sorted, since that would cause an empty-selection event, defeating the purpose of merging.voidrefresh()
Retains the selection and filtering.voidrefreshThen(Consumer<Collection<R>> afterRefresh)
Retains the selection and filtering.voidremoveClearListener(Runnable listener) voidremoveDataChangedListener(Runnable listener) voidremoveItem(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, exclusivevoidremoveItems(Collection<R> items) Removes the given items from this table modelvoidrowsAsDelimitedString(char delimiter) <T> Collection<T>selectedValues(C columnIdentifier) voidSets the item at the given index.voidSorts the visible items according to theFilteredTableSortModel, keeping the selected items.is.codion.common.model.table.TableSummaryModel<C>static <T extends Number,C>
is.codion.common.model.table.ColumnSummaryModel.SummaryValueProvider<T>summaryValueProvider(C columnIdentifier, FilteredTableModel<?, C> tableModel, Format format) Instantiates a newColumnSummaryModel.SummaryValueProviderinstance.<T> Collection<T>Methods inherited from interface is.codion.common.model.FilteredModel
containsItem, filtered, filteredCount, filteredItems, filterItems, includeCondition, items, refresher, visible, visibleCount, visibleItemsMethods 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:
-
FilteredModel.includeCondition()
-
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
is.codion.common.state.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
is.codion.common.model.table.TableConditionModel<C> filterModel()- Returns:
- the filter model used by this table model
-
summaryModel
is.codion.common.model.table.TableSummaryModel<C> summaryModel()- Returns:
- the summary model
-
refresh
void 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:
refreshin interfaceis.codion.common.model.FilteredModel<R>- See Also:
-
refreshThen
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:
refreshThenin interfaceis.codion.common.model.FilteredModel<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 casecolumnFactoryorcolumnValueProvideris null
-
summaryValueProvider
static <T extends Number,C> is.codion.common.model.table.ColumnSummaryModel.SummaryValueProvider<T> summaryValueProvider(C columnIdentifier, FilteredTableModel<?, C> tableModel, Format format) Instantiates a newColumnSummaryModel.SummaryValueProviderinstance.- 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.SummaryValueProviderinstance
-