- All Known Implementing Classes:
AbstractEntityEditModel
,SwingEntityEditModel
public interface EntityEditModel
Specifies a class for editing
Entity
instances.
The underlying attribute values are available via EntityEditModel.EntityEditor.value(Attribute)
.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Represents a task for deleting entities, split up for use with a background thread.static interface
Provides edit access to the underlying entity being edited.static interface
Represents a task for inserting entities, split up for use with a background thread.static interface
Represents a task for updating entities, split up for use with a background thread.static interface
Provides edit access to anAttribute
value in the underlying entity being edited. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<Boolean>
Specifies whether edit models post their insert, update and delete events toEntityEditEvents
Value type: Boolean Default value: true -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(ForeignKey foreignKey, Collection<Entity> entities) Adds the given entities to all foreign key models based on that entity typeObserver<?>
Do not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.Creates a newEntityEditModel.DeleteEntities
instance for deleting the active entity.createDelete
(Collection<Entity> entities) Creates a newEntityEditModel.DeleteEntities
instance for deleting the given entities.Creates a newEntityEditModel.InsertEntities
instance for inserting the active entity.createInsert
(Collection<Entity> entities) Creates a newEntityEditModel.InsertEntities
instance for inserting the given entities.createSearchModel
(ForeignKey foreignKey) Creates aEntitySearchModel
for looking up entities referenced by the given foreign key, using the search attributes defined for that entity type.Creates a newEntityEditModel.UpdateEntities
instance for updating the active entity.createUpdate
(Collection<Entity> entities) Creates a newEntityEditModel.UpdateEntities
instance for updating the given entities.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.Disabling delete causes an exception being thrown when deleting.editor()
Returns aEntityEditModel.EntityEditor
wrapping the entity being edited.entities()
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.Disabling insert causes an exception being thrown when inserting.readOnly()
Making this edit model read-only prevents any changes from being persisted to the database, trying to insert, update or delete will cause an exception being thrown, it does not prevent editing.void
refresh()
Refreshes the active Entity from the database, discarding all changes.void
remove
(ForeignKey foreignKey, Collection<Entity> entities) Removes the given entities from all foreign key models based on that entity type and clears any foreign key values referencing them.void
replace
(ForeignKey foreignKey, Collection<Entity> entities) For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity fromentities
, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.searchModel
(ForeignKey foreignKey) 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.Disabling update causes an exception being thrown when updating.Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.
-
Field Details
-
POST_EDIT_EVENTS
Specifies whether edit models post their insert, update and delete events toEntityEditEvents
- Value type: Boolean
- Default value: true
-
-
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.ValueEditor
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
-
readOnly
State readOnly()Making this edit model read-only prevents any changes from being persisted to the database, trying to insert, update or delete will cause an exception being thrown, it does not prevent editing. UseinsertEnabled()
,updateEnabled()
anddeleteEnabled()
to configure the enabled state of those specific actions.- Returns:
- the
State
controlling whether this model is read only
-
insertEnabled
State insertEnabled()Disabling insert causes an exception being thrown when inserting.- Returns:
- the
State
controlling whether inserting is enabled via this edit model
-
updateEnabled
State updateEnabled()Disabling update causes an exception being thrown when updating.- Returns:
- the
State
controlling whether updating is enabled via this edit model
-
updateMultipleEnabled
State updateMultipleEnabled()Disabling updating multiple entities causes an exception being thrown when trying to update multiple entities at a time.- Returns:
- the
State
controlling whether updating multiple entities is enabled
-
deleteEnabled
State deleteEnabled()Disabling delete causes an exception being thrown when deleting.- Returns:
- the
State
controlling whether deleting is enabled via this edit model
-
createSearchModel
Creates aEntitySearchModel
for looking up entities 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
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
- Parameters:
foreignKey
- the foreign key for which to retrieve theEntitySearchModel
- Returns:
- the
EntitySearchModel
associated with theforeignKey
, if no search model has been initialized for the given foreign key, a new one is created, associated with the foreign key and returned.
-
postEditEvents
State postEditEvents()- Returns:
- a state controlling whether this edit model posts insert, update and delete events
on the
EntityEditEvents
event bus. - See Also:
-
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:
-
createInsert
EntityEditModel.InsertEntities createInsert()Creates a newEntityEditModel.InsertEntities
instance for inserting the active entity.- Returns:
- a new
EntityEditModel.InsertEntities
instance - Throws:
IllegalStateException
- in inserting is not enabledValidationException
- in case validation fails- See Also:
-
createInsert
Creates a newEntityEditModel.InsertEntities
instance for inserting the given entities.- Parameters:
entities
- the entities to insert- Returns:
- a new
EntityEditModel.InsertEntities
instance - Throws:
IllegalStateException
- in inserting is not enabledValidationException
- in case validation fails- See Also:
-
createUpdate
EntityEditModel.UpdateEntities createUpdate()Creates a newEntityEditModel.UpdateEntities
instance for updating the active entity.- Returns:
- a new
EntityEditModel.UpdateEntities
instance - Throws:
IllegalStateException
- in case the active entity is unmodified or if updating is not enabledValidationException
- in case validation fails- See Also:
-
createUpdate
Creates a newEntityEditModel.UpdateEntities
instance for updating the given entities.- Parameters:
entities
- the entities to update- Returns:
- a new
EntityEditModel.UpdateEntities
instance - Throws:
IllegalStateException
- in case any of the given entities are unmodified or if updating is not enabledValidationException
- in case validation fails- See Also:
-
createDelete
EntityEditModel.DeleteEntities createDelete()Creates a newEntityEditModel.DeleteEntities
instance for deleting the active entity.- Returns:
- a new
EntityEditModel.DeleteEntities
instance - Throws:
IllegalStateException
- in deleting is not enabled- See Also:
-
createDelete
Creates a newEntityEditModel.DeleteEntities
instance for deleting the given entities.- Parameters:
entities
- the entities to delete- Returns:
- a new
EntityEditModel.DeleteEntities
instance - Throws:
IllegalStateException
- in deleting is not enabled- See Also:
-
add
Adds the given entities to all foreign key models based on that entity type- Parameters:
foreignKey
- the foreign keyentities
- the values
-
remove
Removes the given entities from all foreign key models based on that entity type and clears any foreign key values referencing them.- Parameters:
foreignKey
- the foreign keyentities
- the values
-
replace
For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity fromentities
, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.- Parameters:
foreignKey
- the foreign keyentities
- the foreign key entities
-
beforeInsert
Observer<Collection<Entity>> beforeInsert()- Returns:
- an observer notified before an insert is performed, after validation
-
afterInsert
Observer<Collection<Entity>> afterInsert()- Returns:
- an observer notified after an insert is performed
-
beforeUpdate
Observer<Collection<Entity>> beforeUpdate()- Returns:
- an observer notified before an update is performed, after validation
-
afterUpdate
- Returns:
- an observer notified after an update is performed
-
beforeDelete
Observer<Collection<Entity>> beforeDelete()- Returns:
- an observer notified before a delete is performed
-
afterDelete
Observer<Collection<Entity>> afterDelete()- Returns:
- an observer notified after a delete is performed
-
afterInsertUpdateOrDelete
Observer<?> afterInsertUpdateOrDelete()- Returns:
- an observer notified each time one or more entities have been inserted, updated or deleted via this model
-