Interface EntityEditModel

All Known Implementing Classes:
AbstractEntityEditModel, SwingEntityEditModel

public interface EntityEditModel
Specifies a class for editing Entity instances.
  • Field Details

    • PERSIST_FOREIGN_KEYS

      static final PropertyValue<Boolean> PERSIST_FOREIGN_KEYS
      Specifies whether writable foreign key values should persist when the model is cleared or set to null
      Value type: Boolean
      Default value: true
    • WARN_ABOUT_UNSAVED_DATA

      static final PropertyValue<Boolean> WARN_ABOUT_UNSAVED_DATA
      Indicates whether the application should ask for confirmation when exiting if some data is unsaved
      and whether it should warn when unsaved data is about to be lost, i.e. due to selection changes. Value type: Boolean
      Default value: false
    • EDIT_EVENTS

      static final PropertyValue<Boolean> EDIT_EVENTS
      Specifies whether edit models post their insert, update and delete events to EntityEditEvents
      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
    • defaults

      void defaults()
      Populates this edit model with default values for all attributes.
      See Also:
    • set

      void set(Entity entity)
      Copies the values from the given Entity into the underlying Entity being edited by this edit model. If entity is null the effect is the same as calling defaults().
      Parameters:
      entity - the entity
      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.
    • entity

      Entity entity()
      Returns:
      an immutable version of the Entity instance being edited
      See Also:
    • isNull

      StateObserver isNull(Attribute<?> attribute)
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating whether the value of the given attribute is null
    • isNotNull

      StateObserver isNotNull(Attribute<?> attribute)
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating whether the value of the given attribute is not null
    • nullable

      boolean nullable(Attribute<?> attribute)
      Parameters:
      attribute - the attribute
      Returns:
      true if this value is allowed to be null in the underlying entity
    • put

      <T> T put(Attribute<T> attribute, T value)
      Sets the given value in the underlying Entity
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute to associate the given value with
      value - the value to associate with the given attribute
      Returns:
      the previous value, if any
    • remove

      <T> T remove(Attribute<T> attribute)
      Removes the given value from the underlying Entity
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the value, if any
    • get

      <T> T get(Attribute<T> attribute)
      Returns the value associated with the given attribute
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the value associated with the given attribute
    • optional

      <T> Optional<T> optional(Attribute<T> attribute)
      Returns the value associated with the given attribute
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the value associated with the given attribute, an empty Optional in case it is null
    • value

      <T> Value<T> value(Attribute<T> attribute)
      Returns a Value based on attribute in this edit model, note that subsequent calls for the same attribute return the same value instance.
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      a Value based on the given edit model value
    • entities

      Entities entities()
      Returns:
      the underlying domain entities
    • entityDefinition

      EntityDefinition entityDefinition()
      Returns:
      the definition of the underlying entity
    • overwriteWarning

      State overwriteWarning()
      Returns:
      a state controlling whether this edit model triggers a warning before overwriting unsaved data
      See Also:
    • 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. Use insertEnabled(), updateEnabled() and deleteEnabled() 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
    • createForeignKeySearchModel

      EntitySearchModel createForeignKeySearchModel(ForeignKey foreignKey)
      Creates a EntitySearchModel 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 a EntitySearchModel
      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
    • foreignKeySearchModel

      EntitySearchModel foreignKeySearchModel(ForeignKey foreignKey)
      Parameters:
      foreignKey - the foreign key for which to retrieve the EntitySearchModel
      Returns:
      the EntitySearchModel associated with the foreignKey, if no search model has been initialized for the given foreign key, a new one is created, associated with the foreign key and returned.
    • defaultValue

      <S extends Supplier<T>, T> Value<S> defaultValue(Attribute<T> attribute)
      Returns the Value instance controlling the default value supplier for the given attribute. Used when the underlying value is not persistent. Use defaults() or set(Entity) with a null parameter to populate the model with the default values.
      Type Parameters:
      S - the value supplier type
      T - the value type
      Parameters:
      attribute - the attribute
      Returns:
      the Value instance controlling the default value supplier
      See Also:
    • editEvents

      State editEvents()
      Returns:
      a state controlling whether this edit model posts insert, update and delete events on the EntityEditEvents event bus.
      See Also:
    • persist

      State persist(Attribute<?> attribute)
      Returns a State controlling whether the last used value for this attribute should persist when the model is cleared.
      Parameters:
      attribute - the attribute
      Returns:
      a State controlling whether the given attribute value should persist when the model is cleared
      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 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 exception
      ValidationException - in case validation fails
      IllegalStateException - 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 exception
      ValidationException - in case validation fails
      IllegalStateException - in case inserting is not enabled
      See Also:
    • 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 exception
      RecordModifiedException - in case the entity has been modified since it was loaded
      ValidationException - in case validation fails
      IllegalStateException - in case updating is not enabled
      UpdateException - 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 exception
      RecordModifiedException - in case an entity has been modified since it was loaded
      ValidationException - in case validation fails
      IllegalStateException - in case updating is not enabled
      See Also:
    • delete

      Entity delete() throws DatabaseException
      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 exception
      IllegalStateException - 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 exception
      IllegalStateException - in case deleting is not enabled
      See Also:
    • createInsert

      Creates a new EntityEditModel.Insert instance for inserting the active entity.
      Returns:
      a new EntityEditModel.Insert instance
      Throws:
      ValidationException - in case validation fails
    • createInsert

      Creates a new EntityEditModel.Insert instance for inserting the given entities.
      Parameters:
      entities - the entities to insert
      Returns:
      a new EntityEditModel.Insert instance
      Throws:
      ValidationException - in case validation fails
    • createUpdate

      Creates a new EntityEditModel.Update instance for updating the active entity.
      Returns:
      a new EntityEditModel.Update instance
      Throws:
      IllegalArgumentException - in case the active entity is unmodified
      ValidationException - in case validation fails
    • createUpdate

      Creates a new EntityEditModel.Update instance for updating the given entities.
      Parameters:
      entities - the entities to update
      Returns:
      a new EntityEditModel.Update instance
      Throws:
      IllegalArgumentException - in case any of the given entities are unmodified
      ValidationException - in case validation fails
    • createDelete

      EntityEditModel.Delete createDelete()
      Creates a new EntityEditModel.Delete instance for deleting the active entity.
      Returns:
      a new EntityEditModel.Delete instance
    • createDelete

      EntityEditModel.Delete createDelete(Collection<Entity> entities)
      Creates a new EntityEditModel.Delete instance for deleting the given entities.
      Parameters:
      entities - the entities to delete
      Returns:
      a new EntityEditModel.Delete instance
    • add

      void add(ForeignKey foreignKey, Collection<Entity> entities)
      Adds the given entities to all foreign key models based on that entity type
      Parameters:
      foreignKey - the foreign key
      entities - the values
    • remove

      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.
      Parameters:
      foreignKey - the foreign key
      entities - the values
    • replace

      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 from entities, useful when attribute values have been changed in the referenced entity that must be reflected in the edit model.
      Parameters:
      foreignKey - the foreign key
      entities - the foreign key entities
    • validate

      void validate(Attribute<?> attribute) throws ValidationException
      Validates the value associated with the given attribute, using the underlying validator.
      Parameters:
      attribute - the attribute the value is associated with
      Throws:
      ValidationException - if the given value is not valid for the given attribute
    • validate

      void validate() throws ValidationException
      Validates the current state of the entity
      Throws:
      ValidationException - in case the entity is invalid
    • validate

      void validate(Collection<Entity> entities) throws ValidationException
      Validates the given entities, using the underlying validator. For entities of a type other than this edit model is based on, their respective validators are used.
      Parameters:
      entities - the entities to validate
      Throws:
      ValidationException - on finding the first invalid entity
      See Also:
    • validate

      void validate(Entity entity) throws ValidationException
      Validates the given entity, using the underlying validator. For entities of a type other than this edit model is based on, their respective validators are used.
      Parameters:
      entity - the entity to validate
      Throws:
      ValidationException - in case the entity is invalid
      NullPointerException - in case the entity is null
    • valid

      StateObserver valid()
      Returns:
      a StateObserver indicating the valid status of the underlying Entity.
      See Also:
    • valid

      StateObserver valid(Attribute<?> attribute)
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating the valid status of the given attribute.
    • modified

      StateObserver modified()
      Returns a StateObserver indicating when and if any values in the underlying Entity have been modified.
      Returns:
      a StateObserver indicating the modified state of this edit model
    • modified

      StateObserver modified(Attribute<?> attribute)
      Returns a StateObserver instance indicating whether the value of the given attribute has been modified.
      Parameters:
      attribute - the attribute
      Returns:
      a StateObserver indicating the modified state of the value of the given attribute
      Throws:
      IllegalArgumentException - in case attribute is not part of the underlying entity
      See Also:
    • exists

      StateObserver exists()
      Returns:
      a StateObserver indicating whether the active entity exists in the database
    • primaryKeyNull

      StateObserver primaryKeyNull()
      Returns:
      a StateObserver indicating whether the primary key of the active entity is null
    • editEvent

      <T> EventObserver<T> editEvent(Attribute<T> attribute)
      Returns an observer notified each time the value associated with the given attribute is edited via put(Attribute, Object) or remove(Attribute), note that this event is only fired if the value actually changes.
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute which edit observer to return
      Returns:
      an observer for the given attribute value edits
    • valueEvent

      <T> EventObserver<T> valueEvent(Attribute<T> attribute)
      Returns an observer notified each time the value associated with the given attribute changes, either via editing or when the active entity is set.
      Type Parameters:
      T - the value type
      Parameters:
      attribute - the attribute which value observer to return
      Returns:
      an observer for the given attribute value changes
      See Also:
    • entityEvent

      EventObserver<Entity> entityEvent()
      Returns:
      an observer notified each time the entity is set via set(Entity) or defaults().
      See Also:
    • beforeInsertEvent

      EventObserver<Collection<Entity>> beforeInsertEvent()
      Returns:
      an observer notified before an insert is performed
    • afterInsertEvent

      EventObserver<Collection<Entity>> afterInsertEvent()
      Returns:
      an observer notified after an insert is performed
    • beforeUpdateEvent

      EventObserver<Map<Entity.Key,Entity>> beforeUpdateEvent()
      Returns:
      an observer notified before an update is performed
    • afterUpdateEvent

      EventObserver<Map<Entity.Key,Entity>> afterUpdateEvent()
      Returns:
      an observer notified after an update is performed
    • beforeDeleteEvent

      EventObserver<Collection<Entity>> beforeDeleteEvent()
      Returns:
      an observer notified before a delete is performed
    • afterDeleteEvent

      EventObserver<Collection<Entity>> afterDeleteEvent()
      Returns:
      an observer notified after a delete is performed
    • insertUpdateOrDeleteEvent

      EventObserver<?> insertUpdateOrDeleteEvent()
      Returns:
      an observer notified each time one or more entities are updated, inserted or deleted via this model
    • confirmOverwriteEvent

      EventObserver<State> confirmOverwriteEvent()
      Returns:
      an observer notified each time the active entity is about to be set