Interface EntityEditor.EditorValue<T>
- Type Parameters:
T- the attribute value type
- All Superinterfaces:
Observable<T>,Observer<T>,Sensor,Value<T>
- Enclosing interface:
EntityEditor<R extends EntityEditor<R>>
Attribute value in the underlying entity being edited.-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.common.reactive.value.Value
Value.Builder<T,B extends Value.Builder<T, B>>, Value.BuilderFactory, Value.Locked, Value.Notify, Value.Validator<T> -
Method Summary
Modifier and TypeMethodDescriptionReturns theValueinstance controlling the default value supplier for the given attribute.editable()Returns aStateinstance controlling whether the value of the given attribute is editable.edited()Returns an observer notified each time this value is modified viaset(Object).error()Returns the validation message for this value, present only while the value is invalid.modified()Returns anObservableStateinstance indicating whether the value of the given attribute has been modified, that is, if the current value differs from its default value, in case of a new entity, or the original value, in case of an existing entity.original()persist()Returns aStatecontrolling whether the last used value for this attribute should persist when defaults are set.present()<V> voidAdds a propagation mapping from this attribute to the given attribute.<V> voidpropagate(Attribute<V> attribute, Predicate<@Nullable T> condition, Function<@Nullable T, @Nullable V> deriver) Adds a conditional propagation mapping from this attribute to the given attribute.voidrevert()Reverts to the original value if modified.voidSets this value, an edit.voidSets the given value for the underlying attribute in the given entity, applying the associated propagators, if any are specified, in case the value changes.valid()voidvalidate()Updates the valid state of this value according to the underlying validatorwarned()Returns anObservableStateindicating whether this value carries a warning — a soft constraint (EntityValidator.warning(Entity, Attribute)).warning()Returns the warning for this value, present only while it carries one.Methods inherited from interface is.codion.common.reactive.observable.Observable
changed, get, getOrThrow, getOrThrow, is, isNot, isNull, isNullable, optionalMethods inherited from interface is.codion.common.reactive.observer.Observer
addConsumer, addWeakConsumer, observer, removeConsumer, removeWeakConsumer, sensor, when, whenMethods inherited from interface is.codion.common.reactive.sensor.Sensor
addListener, addWeakListener, removeListener, removeWeakListenerMethods inherited from interface is.codion.common.reactive.value.Value
addValidator, clear, link, link, locked, observable, removeValidator, unlink, unlink, update, validate
-
Method Details
-
attribute
- Returns:
- the attribute
-
set
Sets this value, an edit. Ignored while the values of an entity being set are notified, setting an entity never modifying it, seeEntityEditor.EditorEntity.- Specified by:
setin interfaceValue<T>- Parameters:
value- the value- Throws:
IllegalStateException- in case the value is not editable- See Also:
-
original
- Returns:
- the original value, or the current one if not modified
- See Also:
-
revert
void revert()Reverts to the original value if modified. This is an edit of this value, likeset(Object), applying its propagators, which give their targets their original values back, and throwing an exception if noteditable().- See Also:
-
validate
void validate()Updates the valid state of this value according to the underlying validator- See Also:
-
persist
State persist()Returns a
Statecontrolling whether the last used value for this attribute should persist when defaults are set.For the master foreign key of a detail editor registered via
EntityEditor.DetailEditors.add(EditorLink)this state is framework-managed: it is held false and locked for as long as the editor is registered.- Returns:
- a
Statecontrolling whether the given attribute value should persist when defaults are set - See Also:
-
valid
ObservableState valid()- Returns:
- an
ObservableStateindicating the valid status of this attribute value.
-
present
ObservableState present()- Returns:
- an
ObservableStateindicating whether the value of this attribute is non-null
-
error
Observable<String> error()Returns the validation message for this value, present only while the value is invalid.
- Returns:
- an
Observableholding the validation message while this value is invalid, empty otherwise - See Also:
-
warned
ObservableState warned()Returns an
ObservableStateindicating whether this value carries a warning — a soft constraint (EntityValidator.warning(Entity, Attribute)).Independent of
valid(): a warned value is a permitted one. Nothing is blocked by this being true.- Returns:
- an
ObservableStateindicating whether this value carries a warning - See Also:
-
warning
Observable<String> warning()Returns the warning for this value, present only while it carries one.
The soft counterpart to
error(): where an error says the value may not be saved, a warning says it may be, and that someone should look at it first.- Returns:
- an
Observableholding the warning for this value, empty when there is none - See Also:
-
modified
ObservableState modified()Returns an
ObservableStateinstance indicating whether the value of the given attribute has been modified, that is, if the current value differs from its default value, in case of a new entity, or the original value, in case of an existing entity.Note that unlike
EntityEditor.EditorEntity.modified()this state does not depend on whether the underlying entity exists.- Returns:
- an
ObservableStateindicating the modified state of the value of the given attribute - See Also:
-
edited
Returns an observer notified each time this value is modified via
set(Object).This event is NOT triggered when the value changes due to the entity being set via
EntityEditor.EditorEntity.set(Entity),EntityEditor.EditorEntity.defaults()orEntityEditor.EditorEntity.clear().Note that this event is only triggered if the value actually changes.
- Returns:
- an observer notified when the given attribute value is edited
-
editable
State editable()Returns a
Stateinstance controlling whether the value of the given attribute is editable. Non-editable values throw an exception onset(Object), values derived viapropagate(Attribute, Function)excepted.- Returns:
- a
Statecontrolling the editable state of the value of the given attribute - See Also:
-
defaultValue
Returns the
Valueinstance controlling the default value supplier for the given attribute.Used when the underlying value is not persistent.
Use
EntityEditor.EditorEntity.defaults()to populate the editor with default values.- Returns:
- the
Valueinstance controlling the default value supplier - See Also:
-
propagate
Adds a propagation mapping from this attribute to the given attribute. Each time this attribute is changed via
set(Object)or in an entity viaset(Entity, Object), the function is applied to derive the target attribute value. Setting the value it already has does not propagate. Setting it back to its original value gives the target attribute its original value back, rather than a derived one, which may differ from what the entity held, so an edit undone, by hand or viarevert(), leaves the entity as it was. A valuepersistedwhenEntityEditor.EditorEntity.defaults()resets the editor, unless null, propagates as if it had just been set. A foreign key value replaced because the referenced entity was updated or deleted elsewhere is not an edit and does not propagate, nor doesEntityEditor.EditorEntity.revert().When editing via the editor, derived values are set via their respective
EntityEditor.EditorValueinstances, triggering edit events. When setting values in an entity, derived values are set directly on the entity viaEntity.set(Attribute, Object). Either way the target attribute need not beeditable().A target attribute has one propagation mapping, adding another replaces it. The mappings apply in the order their target attributes were added.
The function should depend only on the value it is given. When setting a value in an entity the editor holds a different entity, so the editor's own values say nothing about the one being set.
Propagation is transitive, a value derived for a target attribute in turn applies that attribute's own propagators. It stops as soon as a derived value equals the current one, and an attribute already propagating in the current cascade is given its derived value but propagates no further - so a pair deriving from each other settles after one lap whether or not it ever reaches a fixpoint.
// 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));- Type Parameters:
V- the target attribute value type- Parameters:
attribute- the target attribute to propagate toderiver- the function deriving the target value from the source attribute's value
-
propagate
<V> void propagate(Attribute<V> attribute, Predicate<@Nullable T> condition, Function<@Nullable T, @Nullable V> deriver) Adds a conditional propagation mapping from this attribute to the given attribute. It behaves as
propagate(Attribute, Function)when the condition holds for the value, and otherwise leaves the target attribute as it is, nothing propagating from it.Like the function, the condition should depend only on the value it is given.
// Populate the billing address when a customer is selected, keeping it when the customer is cleared editor.value(Invoice.CUSTOMER_FK).propagate(Invoice.BILLINGADDRESS, Objects::nonNull, customer -> customer.get(Customer.ADDRESS));- Type Parameters:
V- the target attribute value type- Parameters:
attribute- the target attribute to propagate tocondition- the condition the value must satisfy to be propagatedderiver- the function deriving the target value from the source attribute's value
-
set
Sets the given value for the underlying attribute in the given entity, applying the associated propagators, if any are specified, in case the value changes.
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
valuemay be null.- Parameters:
entity- the entityvalue- the value to set- See Also:
-