BindingsManager { public <T> void bind(@NotNull ObservableProperty<T> dest, @NotNull ObservableValue<T> src) { bind(dest, src, BooleanExpressions.TRUE); } 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 oneWayBindingAffectedByTarget() throws Exception { BindingsManager bindings = new BindingsManager(BindingsManager.INVOKE_IMMEDIATELY_STRATEGY); IntValueProperty property1 = new IntValueProperty(10); IntValueProperty property2 = new IntValueProperty(20); bindings.bind(property1, property2); assertThat(property1.get()).isEqualTo(20); property1.set(30); assertThat(property1.get()).isEqualTo(30); assertThat(property2.get()).isEqualTo(20); property2.set(40); assertThat(property1.get()).isEqualTo(40); }
@Test public void oneWayBindingsCanBeEnabledConditionally() { BindingsManager bindings = new BindingsManager(BindingsManager.INVOKE_IMMEDIATELY_STRATEGY); IntValueProperty srcProperty = new IntValueProperty(10); IntValueProperty destProperty = new IntValueProperty(-5); BoolValueProperty bindingEnabled = new BoolValueProperty(true); bindings.bind(destProperty, srcProperty, bindingEnabled); assertThat(destProperty.get()).isEqualTo(10); srcProperty.set(20); assertThat(destProperty.get()).isEqualTo(20); bindingEnabled.set(false); assertThat(destProperty.get()).isEqualTo(20); srcProperty.set(30); assertThat(destProperty.get()).isEqualTo(20); srcProperty.set(40); assertThat(destProperty.get()).isEqualTo(20); bindingEnabled.set(true); assertThat(destProperty.get()).isEqualTo(40); srcProperty.set(50); assertThat(destProperty.get()).isEqualTo(50); }
@Test public void testInvokeStrategyOneStepAtATime() throws Exception { TestInvokeStrategy testInvokeStrategy = new TestInvokeStrategy(); BindingsManager bindings = new BindingsManager(testInvokeStrategy); IntValueProperty a = new IntValueProperty(); IntValueProperty b = new IntValueProperty(); IntValueProperty c = new IntValueProperty(); IntValueProperty d = new IntValueProperty(); bindings.bind(a, b); bindings.bind(b, c); bindings.bind(c, d); testInvokeStrategy.updateOneStep(); assertThat(a.get()).isEqualTo(0); assertThat(b.get()).isEqualTo(0); assertThat(c.get()).isEqualTo(0); assertThat(d.get()).isEqualTo(0); d.set(10); assertThat(a.get()).isEqualTo(0); assertThat(b.get()).isEqualTo(0); assertThat(c.get()).isEqualTo(0); assertThat(d.get()).isEqualTo(10); testInvokeStrategy.updateOneStep(); assertThat(a.get()).isEqualTo(0); assertThat(b.get()).isEqualTo(0); assertThat(c.get()).isEqualTo(10); assertThat(d.get()).isEqualTo(10); testInvokeStrategy.updateOneStep(); assertThat(a.get()).isEqualTo(0); assertThat(b.get()).isEqualTo(10); assertThat(c.get()).isEqualTo(10); assertThat(d.get()).isEqualTo(10); testInvokeStrategy.updateOneStep(); assertThat(a.get()).isEqualTo(10); assertThat(b.get()).isEqualTo(10); assertThat(c.get()).isEqualTo(10); assertThat(d.get()).isEqualTo(10); }