Module is.codion.framework.model
Package is.codion.framework.model
Interface EntityTableModel<E extends EntityEditModel>
- Type Parameters:
E
- the type ofEntityEditModel
used by thisEntityTableModel
- All Superinterfaces:
FilterModel<Entity>
- All Known Implementing Classes:
SwingEntityTableModel
Specifies a table model containing
Entity
instances.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Defines the actions a table model can perform when entities are inserted via the associated edit modelNested classes/interfaces inherited from interface is.codion.common.model.FilterModel
FilterModel.AbstractRefresher<T>, FilterModel.Refresher<T>
-
Field Summary
Modifier and TypeFieldDescriptionstatic final PropertyValue<Boolean>
Specifies whether table models handle entity edit events, by replacing updated entities
Value type: Boolean
Default value: truestatic final PropertyValue<EntityTableModel.OnInsert>
Specifies the default action a table model takes when entities are inserted via its edit model.Fields inherited from interface is.codion.common.model.FilterModel
ASYNC_REFRESH
-
Method Summary
Modifier and TypeMethodDescriptionReturns the ValueSet controlling which attributes are included when selecting entities to populate this model.backgroundColor
(int row, Attribute<?> attribute) void
clear()
Clears all items from this table modelReturns a State controlling whether this table model should display all underlying entities when no query condition has been set.Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.Deletes the selected entitieseditable()
<C extends E>
Centities()
find
(Entity.Key primaryKey) Finds the entity in this table model having the given primary keyfind
(Collection<Entity.Key> keys) Finds entities in this table model according to the values inkeys
foregroundColor
(int row, Attribute<?> attribute) int
int
indexOf
(Entity.Key primaryKey) limit()
Returns the Value controlling the maximum number of rows to fetch via the underlying query the next time this table model is refreshed, a null value means all rows should be fetchedonInsert()
orderBy()
Controls the order by clause to use when selecting the data for this model.void
refresh()
Refreshes the items in this table model, according to the underlying conditionvoid
refresh
(Collection<Entity.Key> keys) Refreshes the entities with the given keys by re-selecting them from the underlying database.void
replace
(ForeignKey foreignKey, Collection<Entity> foreignKeyValues) For every entity in this table model, replaces the foreign key instance bearing the primary key with the corresponding entity fromforeignKeyValues
, useful when attribute values have been changed in the referenced entity that must be reflected in the table model.void
replace
(Collection<Entity> entities) Replaces the given entities in this table modelvoid
select
(Collection<Entity.Key> keys) Selects entities according to the primary keys inprimaryKeys
Methods inherited from interface is.codion.common.model.FilterModel
containsItem, filtered, filteredCount, filteredItems, filterItems, includeCondition, items, refresher, refreshThen, visible, visibleCount, visibleItems
-
Field Details
-
ON_INSERT
Specifies the default action a table model takes when entities are inserted via its edit model. Value type:EntityTableModel.OnInsert
Default value:EntityTableModel.OnInsert.ADD_TOP
-
HANDLE_EDIT_EVENTS
Specifies whether table models handle entity edit events, by replacing updated entities
Value type: Boolean
Default value: true
-
-
Method Details
-
entityType
EntityType entityType()- Returns:
- the type of the entity this table model is based on
-
connectionProvider
EntityConnectionProvider connectionProvider()- Returns:
- the connection provider used by this table model
-
connection
EntityConnection connection()Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.- Returns:
- the connection used by this table model
-
entities
Entities entities()- Returns:
- the underlying domain entities
-
entityDefinition
EntityDefinition entityDefinition()- Returns:
- the definition of the underlying entity
-
editModel
- Type Parameters:
C
- the edit model type Returns theEntityEditModel
associated with this table model- Returns:
- the edit model associated with this table model
-
replace
For every entity in this table model, replaces the foreign key instance bearing the primary key with the corresponding entity fromforeignKeyValues
, useful when attribute values have been changed in the referenced entity that must be reflected in the table model.- Parameters:
foreignKey
- the foreign keyforeignKeyValues
- the foreign key entities
-
replace
Replaces the given entities in this table model- Parameters:
entities
- the entities to replace
-
refresh
Refreshes the entities with the given keys by re-selecting them from the underlying database.- Parameters:
keys
- the keys of the entities to refresh
-
conditionModel
EntityTableConditionModel conditionModel()- Returns:
- the
EntityTableConditionModel
instance used by this table model
-
editable
State editable()- Returns:
- the State controlling whether this table model is editable
-
backgroundColor
- Parameters:
row
- the row for which to retrieve the background colorattribute
- the attribute for which to retrieve the background color- Returns:
- an Object representing the background color for this row and attribute, specified by the row entity
- See Also:
-
foregroundColor
- Parameters:
row
- the row for which to retrieve the foreground colorattribute
- the attribute for which to retrieve the foreground color- Returns:
- an Object representing the foreground color for this row and attribute, specified by the row entity
- See Also:
-
attributes
Returns the ValueSet controlling which attributes are included when selecting entities to populate this model. Note that an empty ValueSet indicates that the default select attributes should be used.- Returns:
- the ValueSet controlling the selected attributes
-
limit
Returns the Value controlling the maximum number of rows to fetch via the underlying query the next time this table model is refreshed, a null value means all rows should be fetched- Returns:
- the value controlling the limit
-
orderBy
Controls the order by clause to use when selecting the data for this model. Setting this value to null reverts back to the default order by for the underlying entity, if one has been specified- Returns:
- the value controlling the order by clause
- See Also:
-
deleteSelected
Deletes the selected entities- Returns:
- the deleted entities
- Throws:
DatabaseException
- in case of a database exceptionCancelException
- in case the user cancels the operationIllegalStateException
- in case this table model has no edit model or if the edit model does not allow deleting
-
conditionRequired
State conditionRequired()Returns a State controlling whether this table model should display all underlying entities when no query condition has been set. Setting this value to 'true' prevents all rows from being fetched by accident, when no condition has been set, which is recommended for tables with a large underlying dataset.- Returns:
- a State specifying whether this table model requires a query condition
-
handleEditEvents
State handleEditEvents()- Returns:
- the state controlling whether this table model handles entity edit events, by replacing updated entities
- See Also:
-
onInsert
Value<EntityTableModel.OnInsert> onInsert()- Returns:
- the Value controlling the action to perform when entities are inserted via the associated edit model
- See Also:
-
removeDeleted
State removeDeleted()- Returns:
- the State controlling whether entities that are deleted via the associated edit model should be automatically removed from this table model
-
find
Finds entities in this table model according to the values inkeys
- Parameters:
keys
- the primary key values to use as condition- Returns:
- the entities from this table model having the primary key values as in
keys
-
select
Selects entities according to the primary keys inprimaryKeys
- Parameters:
keys
- the primary keys of the entities to select
-
find
Finds the entity in this table model having the given primary key- Parameters:
primaryKey
- the primary key to search by- Returns:
- the entity with the given primary key from the table model, an empty Optional if not found
-
indexOf
- Parameters:
primaryKey
- the primary key- Returns:
- the row index of the entity with the given primary key, -1 if not found
-
refresh
void refresh()Refreshes the items in this table model, according to the underlying condition- Specified by:
refresh
in interfaceFilterModel<E extends EntityEditModel>
- See Also:
-
clear
void clear()Clears all items from this table model -
getRowCount
int getRowCount()- Returns:
- the number of visible rows in this table model
-
selectionModel
TableSelectionModel<Entity> selectionModel()- Returns:
- the
TableSelectionModel
-
conditionChanged
StateObserver conditionChanged()- Returns:
- a StateObserver indicating if the search condition has changed since last refresh
-
selectionEvent
EventObserver<?> selectionEvent()- Returns:
- an observer notified when the selection changes in the underlying selection model
-