- All Known Implementing Classes:
AbstractEntityEditModel
,SwingEntityEditModel
Entity
instance.
The underlying attribute values are available via EntityEditModel.EntityEditor.value(Attribute)
.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
static interface
Provides edit access to anAttribute
value in the underlying entity being edited.static interface
Represents a task for inserting, updating or deleting entities, split up for use with a background thread.static interface
Provides edit access to the underlying entity.static interface
The edit model settings. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue
<Boolean> Specifies whether edit models post their insert, update and delete events toEntityEditModel.EditEvents
Value type: Boolean Default value: true -
Method Summary
Modifier and TypeMethodDescription<T> void
applyEdit
(Collection<Entity> entities, Attribute<T> attribute, @Nullable T value) Applies the given value to the given entities.Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.createSearchModel
(ForeignKey foreignKey) Creates aEntitySearchModel
for looking up entities of the type referenced by the given foreign key, using the search attributes defined for that entity type.delete()
Note: This method must be called on the UI thread in case a panel has been based on this model.delete
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.Creates a newEntityEditModel.EditTask
instance for deleting the active entity.deleteTask
(Collection<Entity> entities) Creates a newEntityEditModel.EditTask
instance for deleting the given entities.editor()
Returns aEntityEditModel.EntityEditor
wrapping the entity being edited.entities()
static EntityEditModel.EditEvents
events
(EntityType entityType) insert()
Note: This method must be called on the UI thread in case a panel has been based on this model.insert
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.Creates a newEntityEditModel.EditTask
instance for inserting the active entity.insertTask
(Collection<Entity> entities) Creates a newEntityEditModel.EditTask
instance for inserting the given entities.void
refresh()
Refreshes the active Entity from the database, discarding all changes.searchModel
(ForeignKey foreignKey) Returns theEntitySearchModel
associated with the given foreign key.settings()
update()
Note: This method must be called on the UI thread in case a panel has been based on this model.update
(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.Creates a newEntityEditModel.EditTask
instance for updating the active entity.updateTask
(Collection<Entity> entities) Creates a newEntityEditModel.EditTask
instance for updating the given entities.
-
Field Details
-
EDIT_EVENTS
Specifies whether edit models post their insert, update and delete events toEntityEditModel.EditEvents
- Value type: Boolean
- Default value: true
- See Also:
-
-
Method Details
-
entityType
EntityType entityType()- Returns:
- the type of the entity this edit model is based on
-
connectionProvider
EntityConnectionProvider connectionProvider()- Returns:
- the connection provider used by this edit 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 edit model
-
editor
EntityEditModel.EntityEditor editor()Returns aEntityEditModel.EntityEditor
wrapping the entity being edited.EntityEditModel.EntityEditor.get()
returns an immutable copy of theEntity
instance being edited, whileEntityEditModel.EntityEditor.set(Entity)
copies the values from the givenEntity
into the underlyingEntity
. Note that value changes must go through theEntityEditModel.EditorValue
accessible viaEntityEditModel.EntityEditor.value(Attribute)
.- Returns:
- the
EntityEditModel.EntityEditor
wrapping theEntity
instance being edited - See Also:
-
entities
Entities entities()- Returns:
- the underlying domain entities
-
entityDefinition
EntityDefinition entityDefinition()- Returns:
- the definition of the underlying entity
-
settings
EntityEditModel.Settings settings()- Returns:
- the edit model settings
-
createSearchModel
Creates a
EntitySearchModel
for looking up entities of the type referenced by the given foreign key, using the search attributes defined for that entity type.- Parameters:
foreignKey
- the foreign key for which to create aEntitySearchModel
- Returns:
- a new
EntitySearchModel
for looking up entities of the type referenced by the given foreign key attribute, - Throws:
IllegalStateException
- in case no searchable attributes can be found for the entity type referenced by the given foreign key
-
searchModel
Returns the
EntitySearchModel
associated with the given foreign key. If no such search model exists, one is created by callingcreateSearchModel(ForeignKey)
.This method always returns the same
EntitySearchModel
instance, once one has been created.- Parameters:
foreignKey
- the foreign key for which to retrieve theEntitySearchModel
- Returns:
- the
EntitySearchModel
associated with the given foreign key
-
refresh
void refresh()Refreshes the active Entity from the database, discarding all changes. If the active Entity is new then calling this method has no effect. -
insert
Entity insert()Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an insert on the active entity, sets the primary key values of the active entity according to the primary key of the inserted entity- Returns:
- the inserted entity
- Throws:
DatabaseException
- in case of a database exceptionValidationException
- in case validation failsIllegalStateException
- in case inserting is not enabled- See Also:
-
insert
Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an insert on the given entities.- Parameters:
entities
- the entities to insert- Returns:
- a list containing the inserted entities
- Throws:
DatabaseException
- in case of a database exceptionValidationException
- in case validation failsIllegalStateException
- in case inserting is not enabled- See Also:
-
update
Entity update()Note: This method must be called on the UI thread in case a panel has been based on this model. Performs an update on the active entity- Returns:
- the updated entity
- Throws:
DatabaseException
- in case of a database exceptionRecordModifiedException
- in case the entity has been modified since it was loadedValidationException
- in case validation failsIllegalStateException
- in case updating is not enabledUpdateException
- in case the active entity is not modified- See Also:
-
update
Note: This method must be called on the UI thread in case a panel has been based on this model. Updates the given entities.- Parameters:
entities
- the entities to update- Returns:
- the updated entities
- Throws:
DatabaseException
- in case of a database exceptionRecordModifiedException
- in case an entity has been modified since it was loadedValidationException
- in case validation failsIllegalStateException
- in case updating is not enabledUpdateException
- in case any of the given entities are not modified- See Also:
-
delete
Entity delete()Note: This method must be called on the UI thread in case a panel has been based on this model.- Returns:
- the deleted entity
- Throws:
DatabaseException
- in case of a database exceptionIllegalStateException
- in case deleting is not enabled- See Also:
-
delete
Note: This method must be called on the UI thread in case a panel has been based on this model.- Parameters:
entities
- the entities to delete- Returns:
- the deleted entities
- Throws:
DatabaseException
- in case of a database exceptionIllegalStateException
- in case deleting is not enabled- See Also:
-
insertTask
EntityEditModel.EditTask insertTask()Creates a newEntityEditModel.EditTask
instance for inserting the active entity.- Returns:
- a new
EntityEditModel.EditTask
instance - Throws:
IllegalStateException
- in inserting is not enabledValidationException
- in case validation fails- See Also:
-
insertTask
Creates a newEntityEditModel.EditTask
instance for inserting the given entities.- Parameters:
entities
- the entities to insert- Returns:
- a new
EntityEditModel.EditTask
instance - Throws:
IllegalStateException
- in inserting is not enabledValidationException
- in case validation fails- See Also:
-
updateTask
EntityEditModel.EditTask updateTask()Creates a newEntityEditModel.EditTask
instance for updating the active entity.- Returns:
- a new
EntityEditModel.EditTask
instance - Throws:
IllegalStateException
- in case the active entity is unmodified or if updating is not enabledValidationException
- in case validation fails- See Also:
-
updateTask
Creates a newEntityEditModel.EditTask
instance for updating the given entities.- Parameters:
entities
- the entities to update- Returns:
- a new
EntityEditModel.EditTask
instance - Throws:
IllegalStateException
- in case any of the given entities are unmodified or if updating is not enabledValidationException
- in case validation fails- See Also:
-
deleteTask
EntityEditModel.EditTask deleteTask()Creates a newEntityEditModel.EditTask
instance for deleting the active entity.- Returns:
- a new
EntityEditModel.EditTask
instance - Throws:
IllegalStateException
- in deleting is not enabled- See Also:
-
deleteTask
Creates a newEntityEditModel.EditTask
instance for deleting the given entities.- Parameters:
entities
- the entities to delete- Returns:
- a new
EntityEditModel.EditTask
instance - Throws:
IllegalStateException
- in deleting is not enabled- See Also:
-
beforeInsert
Observer<Collection<Entity>> beforeInsert()- Returns:
- an observer notified before insert is performed, after validation
-
afterInsert
Observer<Collection<Entity>> afterInsert()- Returns:
- an observer notified after insert is performed
-
beforeUpdate
Observer<Collection<Entity>> beforeUpdate()- Returns:
- an observer notified before update is performed, after validation
-
afterUpdate
- Returns:
- an observer notified after update is performed, with the updated entities, mapped to their state before the update
-
beforeDelete
Observer<Collection<Entity>> beforeDelete()- Returns:
- an observer notified before delete is performed
-
afterDelete
Observer<Collection<Entity>> afterDelete()- Returns:
- an observer notified after delete is performed
-
afterInsertUpdateOrDelete
Observer<Collection<Entity>> afterInsertUpdateOrDelete()- Returns:
- an observer notified each time one or more entities have been inserted, updated or deleted via this model
-
applyEdit
Applies the given value to the given entities. This method can be used by components providing edit functionality, such as editable tables, in order to apply the edited value, ensuring that any associated values are updated as well.
By default, this sets the given attribute value in the entities via
Entity.set(Attribute, Object)
.Override to customize, f.ex. when associated values must be changed accordingly.
@Override public <T> void applyEdit(Collection<Entity> entities, Attribute<T> attribute, T value) { super.applyEdit(entities, attribute, value); if (attribute.equals(Invoice.CUSTOMER_FK)) { Entity customer = (Entity) value; // Set the billing address when the customer is changed entities.forEach(entity -> entity.set(Invoice.BILLINGADDRESS, customer.get(Customer.ADDRESS))); } }
- Parameters:
entities
- the entities to apply the value toattribute
- the attribute being editedvalue
- the value to apply- See Also:
-
events
- Parameters:
entityType
- the entity type- Returns:
- the central
EntityEditModel.EditEvents
instance for the given entity type
-