Interface EntityEditor.EditorValue<T>

Type Parameters:
T - the attribute value type
All Superinterfaces:
Observable<T>, Observer<T>, Value<T>
Enclosing interface:
EntityEditor

public static interface EntityEditor.EditorValue<T> extends Value<T>
Provides edit access to an Attribute value in the underlying entity being edited.
  • Method Details

    • attribute

      Attribute<T> attribute()
      Returns:
      the attribute
    • original

      @Nullable T original()
      Returns:
      the original value, or the current one if not modified
      See Also:
    • revert

      void revert()
      Reverts to the original value if modified
    • validate

      void validate()
      Updates the valid state of this value according to the underlying validator
      See Also:
    • persist

      State persist()

      Returns a State controlling whether the last used value for this attribute should persist when defaults are set.

      Returns:
      a State controlling whether the given attribute value should persist when defaults are set
      See Also:
    • valid

      Returns:
      an ObservableState indicating the valid status of this attribute value.
    • present

      ObservableState present()
      Returns:
      an ObservableState indicating whether the value of this attribute is non-null
    • message

      Observable<String> message()
      Returns:
      the validation message in case the value is invalid, otherwise the attribute description
    • modified

      ObservableState modified()

      Returns an ObservableState instance indicating whether the value of the given attribute has been modified, that is, if the current value differs from its default value.

      Note that unlike EntityEditor.modified() this state does not depend on whether the underlying entity exists.

      Returns:
      an ObservableState indicating the modified state of the value of the given attribute
      See Also:
    • edited

      Observer<T> edited()

      Returns an observer notified each time this value is modified via Value.set(Object).

      This event is NOT triggered when the value changes due to the entity being set via EntityEditor.EditorEntity.set(Entity), EntityEditor.EditorValues.defaults() or EntityEditor.EditorValues.clear().

      Note that this event is only triggered if the value actually changes.

      Returns:
      an observer notified when the given attribute value is edited
    • defaultValue

      Value<Supplier<T>> defaultValue()

      Returns the Value instance controlling the default value supplier for the given attribute.

      Used when the underlying value is not persistent.

      Use EntityEditor.EditorValues.defaults() to populate the editor with default values.

      Returns:
      the Value instance controlling the default value supplier
      See Also:
    • propagate

      <V> void propagate(Attribute<V> attribute, Function<@Nullable T,@Nullable V> deriver)

      Adds a propagation mapping from this attribute to the given attribute. Each time this attribute is edited via Value.set(Object) or set in an entity via set(Entity, Object), the function is applied to derive the target attribute value.

      When editing via the editor, derived values are set via their respective EntityEditor.EditorValue instances, triggering edit events. When setting values in an entity, derived values are set directly on the entity via Entity.set(Attribute, Object).

      Multiple propagations can be added for a single source attribute.

       // Populate billing address fields when customer changes
       editor().value(Invoice.CUSTOMER_FK).propagate(Invoice.BILLINGADDRESS,
           customer -> customer == null ? null : customer.get(Customer.ADDRESS));
       editor().value(Invoice.CUSTOMER_FK).propagate(Invoice.BILLINGCITY,
           customer -> customer == null ? null : customer.get(Customer.CITY));
      
       // Decompose a date into constituent parts
       editor().value(Sample.SAMPLE_DATE).propagate(Sample.DAY,
           date -> date == null ? null : date.getDayOfMonth());
       editor().value(Sample.SAMPLE_DATE).propagate(Sample.MONTH,
           date -> date == null ? null : date.getMonthValue());
      
      Type Parameters:
      V - the target attribute value type
      Parameters:
      attribute - the target attribute to propagate to
      deriver - the function deriving the target value from this attribute's value
    • set

      void set(Entity entity, @Nullable T value)

      Sets the given value for the underlying attribute in the given entity, applying the associated propagators, if any are specified.

      This method is used by components providing edit functionality outside the editor, such as editable table cells or multi-item editing dialogs, to ensure that derived values are updated along with the primary attribute value.

      Note that value may be null.

      Parameters:
      entity - the entity
      value - the value to set
      See Also: