Interface EntityEditModel

    • Field Detail

      • PERSIST_FOREIGN_KEY_VALUES

        static final PropertyValue<Boolean> PERSIST_FOREIGN_KEY_VALUES
        Specifies whether foreign key values should persist when the UI is cleared or be reset 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
      • COMBO_BOX_NULL_VALUE_ITEM

        static final PropertyValue<String> COMBO_BOX_NULL_VALUE_ITEM
        Specifies the value used by default to represent a null value in combo box models. Using the value null indicates that no null value item should be used.
        Value type: String
        Default value: -
      • POST_EDIT_EVENTS

        static final PropertyValue<Boolean> POST_EDIT_EVENTS
        Specifies whether edit models post their insert, update and delete events to the EntityEditEvents
        Value type: Boolean
        Default value: false
    • Method Detail

      • getEntityId

        String getEntityId()
        Returns:
        the ID of the entity this edit model is based on
      • getConnectionProvider

        EntityConnectionProvider getConnectionProvider()
        Returns:
        the connection provider used by this edit model
      • getDefaultEntity

        Entity getDefaultEntity()
        Returns:
        an Entity instance populated with default values for all properties
        See Also:
        getDefaultValue(Property)
      • setEntity

        void setEntity​(Entity entity)
        Copies the values from the given Entity into the underlying Entity being edited by this edit model. If entity is null then the entity being edited is populated with default values
        Parameters:
        entity - the entity
      • refreshEntity

        void refreshEntity()
        Refreshes the active Entity from the database, discarding all changes. If the active Entity is new then calling this method has no effect.
      • isEntityNew

        boolean isEntityNew()
        Returns true if the active entity is new or false if it represents a row already persisted. By default an entity is new if either its primary key or the original primary key are null. It is not recommended to base the result of this function on a database query since it is called frequently, as in, every time a property value changes.
        Returns:
        true if the active entity is new, that is, does not represent a persistent row
        See Also:
        getPrimaryKeyNullObserver(), Entity.Key.isNull()
      • containsUnsavedData

        boolean containsUnsavedData()
        Returns true if an entity is selected and a value has been modified or if the entity is new and one or more non-default values have been entered
        Returns:
        true if this edit model contains unsaved data
        See Also:
        WARN_ABOUT_UNSAVED_DATA
      • isNull

        boolean isNull​(String propertyId)
        Parameters:
        propertyId - the ID of the property
        Returns:
        true if the value of the given property is null
      • isNotNull

        boolean isNotNull​(String propertyId)
        Parameters:
        propertyId - the ID of the property
        Returns:
        true if the value of the given property is not null
      • isNullable

        boolean isNullable​(Property property)
        Parameters:
        property - the property
        Returns:
        true if this value is allowed to be null in the underlying entity
      • put

        void put​(String propertyId,
                 Object value)
        Sets the given value in the underlying Entity
        Parameters:
        propertyId - the ID of the property to associate the given value with
        value - the value to associate with the given property
      • put

        void put​(Property property,
                 Object value)
        Sets the given value in the underlying Entity
        Parameters:
        property - the property to associate the given value with
        value - the value to associate with the given property
      • remove

        Object remove​(String propertyId)
        Removes the given value from the underlying Entity
        Parameters:
        propertyId - the ID of the property
        Returns:
        the value, if any
      • remove

        Object remove​(Property property)
        Removes the given value from the map
        Parameters:
        property - the property associated with the value to remove
        Returns:
        the value, if any
      • get

        Object get​(String propertyId)
        Returns the value associated with the given property
        Parameters:
        propertyId - the ID of the property
        Returns:
        the value associated with the given property
      • get

        Object get​(Property property)
        Returns the value associated with the given property in the underlying Entity
        Parameters:
        property - the property of the value to retrieve
        Returns:
        the value associated with the given property
      • getForeignKey

        Entity getForeignKey​(String foreignKeyPropertyId)
        Returns the value associated with the given propertyId assuming it is an Entity instance
        Parameters:
        foreignKeyPropertyId - the ID of the property
        Returns:
        the value assuming it is an Entity
        Throws:
        ClassCastException - in case the value was not an Entity
      • value

        <V> Value<V> value​(String propertyId)
        Instantiates a new Value based on the property identified by propertyId in this edit model
        Type Parameters:
        V - the value type
        Parameters:
        propertyId - the property id
        Returns:
        a Value based on the given edit model value
      • getDomain

        Domain getDomain()
        Returns:
        the underlying domain model
      • getEntityDefinition

        EntityDefinition getEntityDefinition()
        Returns:
        the definition of the underlying entity
      • isWarnAboutUnsavedData

        boolean isWarnAboutUnsavedData()
        Returns:
        true if this model warns about unsaved data
        See Also:
        WARN_ABOUT_UNSAVED_DATA
      • setWarnAboutUnsavedData

        EntityEditModel setWarnAboutUnsavedData​(boolean warnAboutUnsavedData)
        Parameters:
        warnAboutUnsavedData - if true then this model warns about unsaved data
        Returns:
        this edit model instance
        See Also:
        WARN_ABOUT_UNSAVED_DATA
      • isInsertEnabled

        boolean isInsertEnabled()
        Returns:
        true if this model should enable records to be inserted
      • setInsertEnabled

        EntityEditModel setInsertEnabled​(boolean insertEnabled)
        Parameters:
        insertEnabled - true if this model should enable inserts
        Returns:
        this edit model instance
      • isUpdateEnabled

        boolean isUpdateEnabled()
        Returns:
        true if this model should enable records to be updated
      • setUpdateEnabled

        EntityEditModel setUpdateEnabled​(boolean updateEnabled)
        Parameters:
        updateEnabled - true if this model should enable records to be updated
        Returns:
        this edit model instance
      • isDeleteEnabled

        boolean isDeleteEnabled()
        Returns:
        true if this model should allow records to be deleted
      • setDeleteEnabled

        EntityEditModel setDeleteEnabled​(boolean deleteEnabled)
        Parameters:
        deleteEnabled - true if this model should enable records to be deleted
        Returns:
        this edit model instance
      • isPostEditEvents

        boolean isPostEditEvents()
        Returns true if this edit model posts its insert, update and delete events on the EntityEditEvents event bus
        Returns:
        true if insert, update and delete events are posted on the edit event bus
      • setPostEditEvents

        EntityEditModel setPostEditEvents​(boolean postEditEvents)
        Set to true if this edit model should post its insert, update and delete events on the EntityEditEvents event bus
        Parameters:
        postEditEvents - true if edit events should be posted
        Returns:
        this edit model instance
      • createForeignKeyLookupModel

        EntityLookupModel createForeignKeyLookupModel​(ForeignKeyProperty foreignKeyProperty)
        Creates a EntityLookupModel for looking up entities referenced by the given foreign key property, using the search properties defined for that entity type, or if none are defined all string based searchable properties in that entity.
        Parameters:
        foreignKeyProperty - the foreign key property for which to create a EntityLookupModel
        Returns:
        a EntityLookupModel for looking up entities of the type referenced by the given foreign key property,
        Throws:
        IllegalStateException - in case no searchable properties can be found for the entity type referenced by the given foreign key property
      • containsLookupModel

        boolean containsLookupModel​(String foreignKeyPropertyId)
        Returns true if this edit model contains a EntityLookupModel for the given foreign key property
        Parameters:
        foreignKeyPropertyId - the ID of the property
        Returns:
        true if a EntityLookupModel has been initialized for the given foreign key property
      • getForeignKeyLookupModel

        EntityLookupModel getForeignKeyLookupModel​(String foreignKeyPropertyId)
        Parameters:
        foreignKeyPropertyId - the ID of the property for which to retrieve the EntityLookupModel
        Returns:
        the EntityLookupModel associated with the property, if no lookup model has been initialized for the given property, a new one is created, associated with the property and returned.
      • getForeignKeyLookupModel

        EntityLookupModel getForeignKeyLookupModel​(ForeignKeyProperty foreignKeyProperty)
        Parameters:
        foreignKeyProperty - the foreign key property for which to retrieve the EntityLookupModel
        Returns:
        the EntityLookupModel associated with the property, if no lookup model has been initialized for the given property, a new one is created, associated with the property and returned.
      • isLookupEnabled

        boolean isLookupEnabled​(Property property)
        Returns true if values based on this property should be available for lookup via this EditModel. This means displaying all the distinct property values to the user, allowing her to select one.
        Parameters:
        property - the property
        Returns:
        true if value lookup should be enabled for this property
      • isPersistValue

        boolean isPersistValue​(Property property)
        Returns true if the last available value for this property should be used when initializing a default entity. Override for selective reset of field values when the model is cleared. For foreign key property values this method by default returns the value of the property PERSIST_FOREIGN_KEY_VALUES.
        Parameters:
        property - the property
        Returns:
        true if the given field value should be reset when the model is cleared
        See Also:
        PERSIST_FOREIGN_KEY_VALUES
      • setPersistValue

        EntityEditModel setPersistValue​(String propertyId,
                                        boolean persistValue)
        Parameters:
        propertyId - the property ID
        persistValue - true if this model should persist the value of the given property on clear
        Returns:
        this edit model instance
        See Also:
        PERSIST_FOREIGN_KEY_VALUES
      • isModified

        boolean isModified()
        Returns:
        true if the underlying Entity is modified
        See Also:
        getModifiedObserver()
      • addForeignKeyValues

        void addForeignKeyValues​(List<Entity> values)
        Adds the inserted entities to all foreign key models based on that entity type
        Parameters:
        values - the values
      • removeForeignKeyValues

        void removeForeignKeyValues​(List<Entity> values)
        Removes the deleted entities from all foreign key models based on that entity type todo set foreign key values referencing the deleted entity to null
        Parameters:
        values - the values
      • replaceForeignKeyValues

        void replaceForeignKeyValues​(Collection<Entity> values)
        For every field referencing the given foreign key values, replaces that foreign key instance with the corresponding entity from values, useful when property values have been changed in the referenced entity that must be reflected in the edit model.
        Parameters:
        values - the foreign key entities
      • setForeignKeyValues

        void setForeignKeyValues​(Collection<Entity> values)
        Sets the values in the given list as the values for the respective foreign keys, uses the first value found for each entity type in case of multiple entities of that type
        Parameters:
        values - the entities
      • getValidator

        Validator getValidator()
        Returns:
        the validator
      • validate

        void validate​(Property property)
               throws ValidationException
        Checks if the value associated with the given property is valid, throws a ValidationException if not
        Parameters:
        property - the property the value is associated with
        Throws:
        ValidationException - if the given value is not valid for the given property
      • validate

        void validate​(Entity entity)
               throws ValidationException
        Validates the current state of the given entity
        Parameters:
        entity - the entity to validate
        Throws:
        ValidationException - in case the entity is invalid
      • isValid

        boolean isValid()
        Returns:
        true if the underlying Entity contains only valid values
        See Also:
        getValidObserver()
      • getModifiedObserver

        StateObserver getModifiedObserver()
        Returns a StateObserver responsible for indicating when and if any values in the underlying Entity have been modified.
        Returns:
        a StateObserver indicating the modified state of this edit model
        See Also:
        isModified()
      • getEntityNewObserver

        StateObserver getEntityNewObserver()
        Returns:
        an observer indicating whether or not the active entity is new
        See Also:
        isEntityNew()
      • getPrimaryKeyNullObserver

        StateObserver getPrimaryKeyNullObserver()
        Returns:
        a StateObserver indicating whether or not the primary key of the active entity is null
      • addValueEditListener

        void addValueEditListener​(String propertyId,
                                  EventDataListener<ValueChange> listener)
        Adds a listener notified each time the value associated with the given property is edited via put(Property, Object) or remove(Property), note that this event is only fired when the value actually changes.
        Parameters:
        propertyId - the ID of the property for which to monitor value edits
        listener - a listener notified each time the value of the given property is edited via this model
      • removeValueEditListener

        void removeValueEditListener​(String propertyId,
                                     EventDataListener<ValueChange> listener)
        Removes the given listener.
        Parameters:
        propertyId - the propertyId
        listener - the listener to remove
      • addValueListener

        void addValueListener​(String propertyId,
                              EventDataListener<ValueChange> listener)
        Adds a listener notified each time the value associated with the given key changes, either via editing or when the active entity is set.
        Parameters:
        propertyId - the ID of the property for which to monitor value changes
        listener - a listener notified each time the value of the property identified by propertyId changes
        See Also:
        setEntity(Entity)
      • removeValueListener

        void removeValueListener​(String propertyId,
                                 EventDataListener<ValueChange> listener)
        Removes the given listener.
        Parameters:
        propertyId - the ID of the property for which to remove the listener
        listener - the listener to remove
      • removeEntitySetListener

        void removeEntitySetListener​(EventDataListener<Entity> listener)
        Removes the given listener.
        Parameters:
        listener - the listener to remove
      • addBeforeInsertListener

        void addBeforeInsertListener​(EventDataListener<List<Entity>> listener)
        Parameters:
        listener - a listener to be notified before an insert is performed
      • removeBeforeInsertListener

        void removeBeforeInsertListener​(EventDataListener<List<Entity>> listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addAfterInsertListener

        void addAfterInsertListener​(EventDataListener<List<Entity>> listener)
        Parameters:
        listener - a listener to be notified each time a insert has been performed
      • removeAfterInsertListener

        void removeAfterInsertListener​(EventDataListener<List<Entity>> listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addBeforeUpdateListener

        void addBeforeUpdateListener​(EventDataListener<Map<Entity.Key,​Entity>> listener)
        Parameters:
        listener - a listener to be notified before an update is performed
      • removeBeforeUpdateListener

        void removeBeforeUpdateListener​(EventDataListener<Map<Entity.Key,​Entity>> listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addAfterUpdateListener

        void addAfterUpdateListener​(EventDataListener<Map<Entity.Key,​Entity>> listener)
        Parameters:
        listener - a listener to be notified each time an update has been performed, with the updated entities, mapped to their respective original primary keys, that is, the primary keys before the update was performed
      • removeAfterUpdateListener

        void removeAfterUpdateListener​(EventDataListener<Map<Entity.Key,​Entity>> listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addBeforeDeleteListener

        void addBeforeDeleteListener​(EventDataListener<List<Entity>> listener)
        Parameters:
        listener - a listener to be notified before a delete is performed
      • removeBeforeDeleteListener

        void removeBeforeDeleteListener​(EventDataListener<List<Entity>> listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addAfterDeleteListener

        void addAfterDeleteListener​(EventDataListener<List<Entity>> listener)
        Parameters:
        listener - a listener to be notified each time a delete has been performed
      • removeAfterDeleteListener

        void removeAfterDeleteListener​(EventDataListener<List<Entity>> listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addBeforeRefreshListener

        void addBeforeRefreshListener​(EventListener listener)
        Parameters:
        listener - a listener to be notified before a refresh is performed
      • removeBeforeRefreshListener

        void removeBeforeRefreshListener​(EventListener listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addAfterRefreshListener

        void addAfterRefreshListener​(EventListener listener)
        Parameters:
        listener - a listener to be notified each time a refresh has been performed
      • removeAfterRefreshListener

        void removeAfterRefreshListener​(EventListener listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addEntitiesChangedListener

        void addEntitiesChangedListener​(EventListener listener)
        Parameters:
        listener - a listener to be notified each time a entity is modified via this model, updated, inserted or deleted
      • removeEntitiesChangedListener

        void removeEntitiesChangedListener​(EventListener listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove
      • addConfirmSetEntityObserver

        void addConfirmSetEntityObserver​(EventDataListener<State> listener)
        Parameters:
        listener - a listener notified each time the active entity is about to be set
      • removeConfirmSetEntityObserver

        void removeConfirmSetEntityObserver​(EventDataListener<State> listener)
        Removes the given listener.
        Parameters:
        listener - a listener to remove