Skip to content

Commit e9a3677

Browse files
author
nicolaiparlog
committed
Improve documentation to include introduction of "missing behavior"
1 parent 47904d7 commit e9a3677

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

src/main/java/org/codefx/libfx/nesting/Nesting.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/**
1010
* <p>
11-
* A nesting encapsulates a hierarchy of nested {@link ObservableValue ObservableValues} and its
12-
* {@link #innerObservableProperty() innerObservable} property always contains the current innermost {@code Observable}
13-
* in that hierarchy as an {@link Optional}. A {@code Nesting} can be used as a basic building block for other nested
14-
* functionality.
11+
* A nesting encapsulates a hierarchy of nested {@link ObservableValue ObservableValues}.
12+
* <p>
13+
* Its {@link #innerObservableProperty() innerObservable} property always contains the current innermost
14+
* {@code Observable} in that hierarchy as an {@link Optional}. A {@code Nesting} can be used as a basic building block
15+
* for other nested functionality.
1516
* <h2>Nesting Hierarchy</h2> A nesting hierarchy is composed of some {@code ObservableValues}, often simply called
1617
* <b>observables</b>, and <b>nesting steps</b> which lead from one observable to the next.
1718
* <p>
@@ -24,7 +25,7 @@
2425
* Hence they must all implement {@link ObservableValue ObservableValue}. No step is used on the inner observable so it
2526
* suffices that it implements {@link Observable}.
2627
* <h3>Example</h3> Consider a class {@code Employee} which has an {@code Property<Address> address}, where
27-
* {@code Address} has a {@code StringProperty streetName}. There might be a {@code Property<Emplyee> currentEmployee},
28+
* {@code Address} has a {@code StringProperty streetName}. There might be a {@code Property<Employee> currentEmployee},
2829
* which always holds the current employee.
2930
* <p>
3031
* In this case the hierarchy would be {@code currentEmployee -> address -> streetName} where {@code currentEmployee} is

src/main/java/org/codefx/libfx/nesting/property/NestedProperty.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@
66

77
/**
88
* <p>
9-
* A {@link Property} which is based on a {@link Nesting}. Simply put, this property is always bound to the nesting's
10-
* inner observable (more precisely, it is bound to the {@link Property} instance contained in the optional value held
11-
* by the nesting's {@link Nesting#innerObservableProperty() innerObservable} property).
12-
* <h2>Inner Observable's Value Changes</h2> This property is bound to the nesting's inner observable. So when that
13-
* observable's value changes, so does this property.
9+
* A {@link Property} which is based on a {@link Nesting}.
10+
* <p>
11+
* Simply put, this property is always bound to the nesting's inner observable (more precisely, it is bound to the
12+
* {@link Property} instance contained in the optional value held by the nesting's
13+
* {@link Nesting#innerObservableProperty() innerObservable} property).
14+
* <h2>Value Changes</h2> This property is bidirectionally bound to the nesting's inner observable. So when that
15+
* observable's value changes, so does this property's value and vice versa.
1416
* <h2>Inner Observable Is Replaced</h2> When the nesting's inner observable is replaced by a present observable, this
1517
* nested property's value changes to the new observable's value. Like all other value changes this one also results in
1618
* calling invalidation and change listeners.
17-
* <p>
18-
* If the new observable is missing, this property stays unbound and keeps its value (and hence no listener is called).
19-
* <h2>Inner Observable is Missing</h2> It is possible that a nesting's inner observable is missing (see comment on
19+
* <h2>Missing Inner Observable</h2> It is possible that a nesting's inner observable is missing (see comment on
2020
* {@link Nesting}). In that case the {@link NestedProperty#innerObservablePresentProperty() innerObservablePresent}
21-
* property is false and changes made to this property's value can not be propagated to another property.
22-
* <p>
23-
* If the inner observable changes back to a present value, everything said above applies. This implies that when the
24-
* nested property's value changed while the inner observable was missing, these changes are replaced by the new
25-
* observable's value when one is set. Since this property's change listeners are called, the replaced value can be
26-
* caught there before it gets lost. TODO add comments explaining what happens when inner observable goes missing
21+
* property is false. How else the nested property behaves depends on its configuration which was determined when it was
22+
* build.
23+
* <h3>When Inner Observable Goes Missing</h3> When the inner observable goes missing, the nested property will either
24+
* keep its value (this is the default behavior) or change to a value which was determined at build time. This can be
25+
* done with the {@code onInnerObservableMissing...} methods on the nested property builder (e.g.
26+
* {@link NestedObjectPropertyBuilder#onInnerObservableMissingSetDefaultValue() onInnerObservableMissingSetDefaultValue}
27+
* ).
28+
* <h3>Update While Inner Observable Is Missing</h3> When a value is set on the nested property while the inner
29+
* observable is missing, it can not be propagated anywhere. For this reason the default behavior is to throw an
30+
* exception. Alternatively the property can hold new values until a new inner observable is found (with
31+
* {@link NestedObjectPropertyBuilder#onUpdateWhenInnerObservableMissingAcceptValues()
32+
* onUpdateWhenInnerObservableMissingAcceptValues}). The property will then be bound to the new observable and hence
33+
* forget the intermediate value. (Since this property's change listeners are called, the replaced value can be caught
34+
* there before it gets lost.)
2735
*
2836
* @param <T>
2937
* the type of the value wrapped by the property

0 commit comments

Comments
 (0)