BindingsManager { public <T> void bindTwoWay(@NotNull ObservableProperty<T> first, @NotNull ObservableProperty<T> second) { releaseTwoWay(first, second); myTwoWayBindings.put(first, second, new TwoWayBinding<T>(first, second)); } BindingsManager();  BindingsManager(InvokeStrategy invokeStrategy); void bind(@NotNull ObservableProperty<T> dest, @NotNull ObservableValue<T> src); void bind(@NotNull ObservableProperty<T> dest, @NotNull ObservableValue<T> src, @NotNull ObservableValue<Boolean> enabled); void bindTwoWay(@NotNull ObservableProperty<T> first, @NotNull ObservableProperty<T> second); void bindList(@NotNull ObservableList<D> destList, @NotNull ListExpression<S, D> srcExpression); void release(@NotNull ObservableProperty<?> dest); void releaseTwoWay(@NotNull ObservableProperty<T> first, @NotNull ObservableProperty<T> second); void releaseList(@NotNull ObservableList<T> destList); void releaseAll(); static final InvokeStrategy APPLICATION_INVOKE_LATER_STRATEGY; static final InvokeStrategy SWING_INVOKE_LATER_STRATEGY; static final InvokeStrategy INVOKE_IMMEDIATELY_STRATEGY; }
@Test public void twoWayBindingsAffectEachOther() throws Exception { BindingsManager bindings = new BindingsManager(BindingsManager.INVOKE_IMMEDIATELY_STRATEGY); IntValueProperty property1 = new IntValueProperty(10); IntValueProperty property2 = new IntValueProperty(20); bindings.bindTwoWay(property1, property2); assertThat(property1.get()).isEqualTo(20); property1.set(30); assertThat(property2.get()).isEqualTo(30); property2.set(40); assertThat(property1.get()).isEqualTo(40); }
@Test public void twoWayBindingsCanBeChained() { BindingsManager bindings = new BindingsManager(BindingsManager.INVOKE_IMMEDIATELY_STRATEGY); IntValueProperty a = new IntValueProperty(); IntValueProperty b = new IntValueProperty(); IntValueProperty c = new IntValueProperty(); bindings.bindTwoWay(a, b); bindings.bindTwoWay(b, c); c.set(30); assertThat(a.get()).isEqualTo(30); assertThat(b.get()).isEqualTo(30); assertThat(c.get()).isEqualTo(30); b.set(-100); assertThat(a.get()).isEqualTo(-100); assertThat(b.get()).isEqualTo(-100); assertThat(c.get()).isEqualTo(-100); a.set(9); assertThat(a.get()).isEqualTo(9); assertThat(b.get()).isEqualTo(9); assertThat(c.get()).isEqualTo(9); }