- All Implemented Interfaces:
EntityEditModel
- Direct Known Subclasses:
SwingEntityEditModel
EntityEditModel implementation-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.framework.model.EntityEditModel
EntityEditModel.EditEvents, EntityEditModel.EditorValue<T>, EntityEditModel.EditTask, EntityEditModel.EntityEditor, EntityEditModel.Settings -
Field Summary
Fields inherited from interface is.codion.framework.model.EntityEditModel
EDIT_EVENTS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractEntityEditModel(EntityType entityType, EntityConnectionProvider connectionProvider) Instantiates a newAbstractEntityEditModelbased on the given entity type. -
Method Summary
Modifier and TypeMethodDescriptionfinal Observer<Collection<Entity>> final Observer<Collection<Entity>> final Observer<Collection<Entity>> <T> voidapplyEdit(Collection<Entity> entities, Attribute<T> attribute, @Nullable T value) Applies the given value to the given entities.final Observer<Collection<Entity>> final Observer<Collection<Entity>> final Observer<Collection<Entity>> protected voidconfigure(ForeignKey foreignKey, EntitySearchModel entitySearchModel) Called when aEntitySearchModelis created insearchModel(ForeignKey).final EntityConnectionDo not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.final EntityConnectionProvidercreateSearchModel(ForeignKey foreignKey) Creates aEntitySearchModelfor looking up entities of the type referenced by the given foreign key, using the search attributes defined for that entity type.final Entitydelete()Note: This method must be called on the UI thread in case a panel has been based on this model.final Collection<Entity> delete(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.protected voiddelete(Collection<Entity> entities, EntityConnection connection) Deletes the given entities from the database using the given connectionprotected voiddeleted(ForeignKey foreignKey, Collection<Entity> entities) Called when entities of the type referenced by the given foreign key are deleted.final EntityEditModel.EditTaskCreates a newEntityEditModel.EditTaskinstance for deleting the active entity.final EntityEditModel.EditTaskdeleteTask(Collection<Entity> entities) Creates a newEntityEditModel.EditTaskinstance for deleting the given entities.editor()Returns aEntityEditModel.EntityEditorwrapping the entity being edited.final Entitiesentities()final EntityDefinitionfinal EntityTypefinal Entityinsert()Note: This method must be called on the UI thread in case a panel has been based on this model.final Collection<Entity> insert(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.protected Collection<Entity> insert(Collection<Entity> entities, EntityConnection connection) Inserts the given entities into the database using the given connectionprotected voidinserted(ForeignKey foreignKey, Collection<Entity> entities) Called when entities of the type referenced by the given foreign key are inserted.final EntityEditModel.EditTaskCreates a newEntityEditModel.EditTaskinstance for inserting the active entity.final EntityEditModel.EditTaskinsertTask(Collection<Entity> entities) Creates a newEntityEditModel.EditTaskinstance for inserting the given entities.protected final voidnotifyAfterDelete(Collection<Entity> deletedEntities) Notifies that delete has been performedprotected final voidnotifyAfterInsert(Collection<Entity> insertedEntities) Notifies that insert has been performedprotected final voidnotifyAfterUpdate(Map<Entity, Entity> updatedEntities) Notifies that update has been performedprotected final voidnotifyBeforeDelete(Collection<Entity> entitiesToDelete) Notifies that delete is about to be performedprotected final voidnotifyBeforeInsert(Collection<Entity> entitiesToInsert) Notifies that insert is about to be performedprotected final voidnotifyBeforeUpdate(Collection<Entity> entitiesToUpdate) Notifies that update is about to be performedfinal voidrefresh()Refreshes the active Entity from the database, discarding all changes.final EntitySearchModelsearchModel(ForeignKey foreignKey) Returns theEntitySearchModelassociated with the given foreign key.final EntityEditModel.Settingssettings()final StringtoString()final Entityupdate()Note: This method must be called on the UI thread in case a panel has been based on this model.final Collection<Entity> update(Collection<Entity> entities) Note: This method must be called on the UI thread in case a panel has been based on this model.protected Collection<Entity> update(Collection<Entity> entities, EntityConnection connection) Updates the given entities in the database using the given connectionprotected voidupdated(ForeignKey foreignKey, Map<Entity.Key, Entity> entities) Called when entities of the type referenced by the given foreign key have been updated.final EntityEditModel.EditTaskCreates a newEntityEditModel.EditTaskinstance for updating the active entity.final EntityEditModel.EditTaskupdateTask(Collection<Entity> entities) Creates a newEntityEditModel.EditTaskinstance for updating the given entities.
-
Constructor Details
-
AbstractEntityEditModel
protected AbstractEntityEditModel(EntityType entityType, EntityConnectionProvider connectionProvider) Instantiates a newAbstractEntityEditModelbased on the given entity type.- Parameters:
entityType- the type of the entity to base thisAbstractEntityEditModelonconnectionProvider- theEntityConnectionProviderinstance
-
-
Method Details
-
entities
- Specified by:
entitiesin interfaceEntityEditModel- Returns:
- the underlying domain entities
-
entityDefinition
- Specified by:
entityDefinitionin interfaceEntityEditModel- Returns:
- the definition of the underlying entity
-
toString
-
settings
- Specified by:
settingsin interfaceEntityEditModel- Returns:
- the edit model settings
-
entityType
- Specified by:
entityTypein interfaceEntityEditModel- Returns:
- the type of the entity this edit model is based on
-
connectionProvider
- Specified by:
connectionProviderin interfaceEntityEditModel- Returns:
- the connection provider used by this edit model
-
connection
Description copied from interface:EntityEditModelDo not cache or keep the connection returned by this method in a long living field, since it may become invalid and thereby unusable.- Specified by:
connectionin interfaceEntityEditModel- Returns:
- the connection used by this edit model
-
editor
Description copied from interface:EntityEditModelReturns aEntityEditModel.EntityEditorwrapping the entity being edited.EntityEditModel.EntityEditor.get()returns an immutable copy of theEntityinstance being edited, whileEntityEditModel.EntityEditor.set(Entity)copies the values from the givenEntityinto the underlyingEntity. Note that value changes must go through theEntityEditModel.EditorValueaccessible viaEntityEditModel.EntityEditor.value(Attribute).- Specified by:
editorin interfaceEntityEditModel- Returns:
- the
EntityEditModel.EntityEditorwrapping theEntityinstance being edited - See Also:
-
refresh
public final void refresh()Description copied from interface:EntityEditModelRefreshes the active Entity from the database, discarding all changes. If the active Entity is new then calling this method has no effect.- Specified by:
refreshin interfaceEntityEditModel
-
insert
Description copied from interface:EntityEditModelNote: 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- Specified by:
insertin interfaceEntityEditModel- Returns:
- the inserted entity
- See Also:
-
insert
Description copied from interface:EntityEditModelNote: 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.- Specified by:
insertin interfaceEntityEditModel- Parameters:
entities- the entities to insert- Returns:
- a list containing the inserted entities
- See Also:
-
update
Description copied from interface:EntityEditModelNote: 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- Specified by:
updatein interfaceEntityEditModel- Returns:
- the updated entity
- See Also:
-
update
Description copied from interface:EntityEditModelNote: This method must be called on the UI thread in case a panel has been based on this model. Updates the given entities.- Specified by:
updatein interfaceEntityEditModel- Parameters:
entities- the entities to update- Returns:
- the updated entities
- See Also:
-
delete
Description copied from interface:EntityEditModelNote: This method must be called on the UI thread in case a panel has been based on this model.- Specified by:
deletein interfaceEntityEditModel- Returns:
- the deleted entity
- See Also:
-
delete
Description copied from interface:EntityEditModelNote: This method must be called on the UI thread in case a panel has been based on this model.- Specified by:
deletein interfaceEntityEditModel- Parameters:
entities- the entities to delete- Returns:
- the deleted entities
- See Also:
-
insertTask
Description copied from interface:EntityEditModelCreates a newEntityEditModel.EditTaskinstance for inserting the active entity.- Specified by:
insertTaskin interfaceEntityEditModel- Returns:
- a new
EntityEditModel.EditTaskinstance - See Also:
-
insertTask
Description copied from interface:EntityEditModelCreates a newEntityEditModel.EditTaskinstance for inserting the given entities.- Specified by:
insertTaskin interfaceEntityEditModel- Parameters:
entities- the entities to insert- Returns:
- a new
EntityEditModel.EditTaskinstance - See Also:
-
updateTask
Description copied from interface:EntityEditModelCreates a newEntityEditModel.EditTaskinstance for updating the active entity.- Specified by:
updateTaskin interfaceEntityEditModel- Returns:
- a new
EntityEditModel.EditTaskinstance - See Also:
-
updateTask
Description copied from interface:EntityEditModelCreates a newEntityEditModel.EditTaskinstance for updating the given entities.- Specified by:
updateTaskin interfaceEntityEditModel- Parameters:
entities- the entities to update- Returns:
- a new
EntityEditModel.EditTaskinstance - See Also:
-
deleteTask
Description copied from interface:EntityEditModelCreates a newEntityEditModel.EditTaskinstance for deleting the active entity.- Specified by:
deleteTaskin interfaceEntityEditModel- Returns:
- a new
EntityEditModel.EditTaskinstance - See Also:
-
deleteTask
Description copied from interface:EntityEditModelCreates a newEntityEditModel.EditTaskinstance for deleting the given entities.- Specified by:
deleteTaskin interfaceEntityEditModel- Parameters:
entities- the entities to delete- Returns:
- a new
EntityEditModel.EditTaskinstance - See Also:
-
createSearchModel
Description copied from interface:EntityEditModelCreates a
EntitySearchModelfor looking up entities of the type referenced by the given foreign key, using the search attributes defined for that entity type.- Specified by:
createSearchModelin interfaceEntityEditModel- Parameters:
foreignKey- the foreign key for which to create aEntitySearchModel- Returns:
- a new
EntitySearchModelfor looking up entities of the type referenced by the given foreign key attribute,
-
searchModel
Description copied from interface:EntityEditModelReturns the
EntitySearchModelassociated with the given foreign key. If no such search model exists, one is created by callingEntityEditModel.createSearchModel(ForeignKey).This method always returns the same
EntitySearchModelinstance, once one has been created.- Specified by:
searchModelin interfaceEntityEditModel- Parameters:
foreignKey- the foreign key for which to retrieve theEntitySearchModel- Returns:
- the
EntitySearchModelassociated with the given foreign key
-
beforeInsert
- Specified by:
beforeInsertin interfaceEntityEditModel- Returns:
- an observer notified before insert is performed, after validation
-
afterInsert
- Specified by:
afterInsertin interfaceEntityEditModel- Returns:
- an observer notified after insert is performed
-
beforeUpdate
- Specified by:
beforeUpdatein interfaceEntityEditModel- Returns:
- an observer notified before update is performed, after validation
-
afterUpdate
- Specified by:
afterUpdatein interfaceEntityEditModel- Returns:
- an observer notified after update is performed, with the updated entities, mapped to their state before the update
-
beforeDelete
- Specified by:
beforeDeletein interfaceEntityEditModel- Returns:
- an observer notified before delete is performed
-
afterDelete
- Specified by:
afterDeletein interfaceEntityEditModel- Returns:
- an observer notified after delete is performed
-
afterInsertUpdateOrDelete
- Specified by:
afterInsertUpdateOrDeletein interfaceEntityEditModel- Returns:
- an observer notified each time one or more entities have been inserted, updated or deleted via this model
-
applyEdit
Description copied from interface:EntityEditModelApplies 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.
Note that that
valuemay be null.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 == null ? null : customer.get(Customer.ADDRESS))); } }- Specified by:
applyEditin interfaceEntityEditModel- Parameters:
entities- the entities to apply the value toattribute- the attribute being editedvalue- the value to apply- See Also:
-
configure
Called when a
EntitySearchModelis created insearchModel(ForeignKey).- Parameters:
foreignKey- the foreign keyentitySearchModel- the search model
-
insert
Inserts the given entities into the database using the given connection- Parameters:
entities- the entities to insertconnection- the connection to use- Returns:
- the inserted entities
- Throws:
DatabaseException- in case of a database exception
-
update
Updates the given entities in the database using the given connection- Parameters:
entities- the entities to updateconnection- the connection to use- Returns:
- the updated entities
- Throws:
DatabaseException- in case of a database exception
-
delete
Deletes the given entities from the database using the given connection- Parameters:
entities- the entities to deleteconnection- the connection to use- Throws:
DatabaseException- in case of a database exception
-
inserted
Called when entities of the type referenced by the given foreign key are inserted.
- Parameters:
foreignKey- the foreign keyentities- the inserted entities- See Also:
-
updated
Called when entities of the type referenced by the given foreign key have been updated.
For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding value from
entities- Parameters:
foreignKey- the foreign keyentities- the updated entities, mapped to their original primary key- See Also:
-
deleted
Called when entities of the type referenced by the given foreign key are deleted.
Clears any foreign key values referencing the deleted entities.
- Parameters:
foreignKey- the foreign keyentities- the deleted entities- See Also:
-
notifyBeforeInsert
Notifies that insert is about to be performed- Parameters:
entitiesToInsert- the entities about to be inserted- See Also:
-
notifyAfterInsert
Notifies that insert has been performed- Parameters:
insertedEntities- the inserted entities- See Also:
-
notifyBeforeUpdate
Notifies that update is about to be performed- Parameters:
entitiesToUpdate- the entities about to be updated- See Also:
-
notifyAfterUpdate
Notifies that update has been performed- Parameters:
updatedEntities- a map containing the updated entities, mapped to their state before the update- See Also:
-
notifyBeforeDelete
Notifies that delete is about to be performed- Parameters:
entitiesToDelete- the entities about to be deleted- See Also:
-
notifyAfterDelete
Notifies that delete has been performed- Parameters:
deletedEntities- the deleted entities- See Also:
-