@Test public void booleanToListInitiallyRemovesWhenTrue() { BooleanProperty b = booleanProperty("b", false); List<String> names = new ArrayList<String>(); names.add("foo"); binder.bind(b).to(names).has("foo"); assertThat(names.size(), is(0)); }
/** @return a fluent {@link BooleanPropertyBinder} against {@code property}. */ public <P> BooleanPropertyBinder bind(BooleanProperty property) { return new BooleanPropertyBinder(this, property); }
public void to(final IsRadioButton ifTrue, final IsRadioButton ifFalse) { b.add(ifTrue.addValueChangeHandler(e -> { if (TRUE.equals(e.getValue())) { bp.set(true); set(ifTrue, ifFalse); // update ifFalse } })); b.add(ifFalse.addValueChangeHandler(e -> { if (TRUE.equals(e.getValue())) { bp.set(false); set(ifFalse, ifTrue); // update ifTrue } })); b.add(bp.addPropertyChangedHandler(e -> { if (bp.isTrue()) { set(ifTrue, ifFalse); } else { set(ifFalse, ifTrue); } })); // set the initial value if (bp.isTrue()) { set(ifTrue, ifFalse); } else { set(ifFalse, ifTrue); } }
@Test public void booleanToListRemovesOnChange() { BooleanProperty b = booleanProperty("b", true); List<String> names = new ArrayList<String>(); names.add("foo"); binder.bind(b).to(names).has("foo"); assertThat(names.size(), is(1)); b.set(false); assertThat(names.size(), is(0)); }
@Test public void booleanToListInitializePropertyToTrue() { BooleanProperty b = booleanProperty("b"); List<String> names = new ArrayList<String>(); names.add("foo"); binder.bind(b).to(names).has("foo"); assertThat(b.get(), is(true)); assertThat(b.isTouched(), is(false)); }
@Override public void onBind() { super.onBind(); // two-way binding between checked and view.box() binder.bind(checked).to(view.box()); // one-way binding between our derived value and view.label()'s text binder.bind(() -> checked.isTrue() ? "Checked!" : "Not checked").to(textOf(view.label())); }
@Test public void booleanToListAddsOnChange() { BooleanProperty b = booleanProperty("b", false); List<String> names = new ArrayList<String>(); binder.bind(b).to(names).has("foo"); assertThat(names.size(), is(0)); b.set(true); assertThat(names, hasItem("foo")); }
@Test public void booleanToListInitializePropertyToFalse() { BooleanProperty b = booleanProperty("b"); List<String> names = new ArrayList<String>(); binder.bind(b).to(names).has("foo"); assertThat(b.get(), is(false)); assertThat(b.isTouched(), is(false)); }
@Test public void booleanToListAddsInitiallyWhenTrue() { BooleanProperty b = booleanProperty("b", true); List<String> names = new ArrayList<String>(); binder.bind(b).to(names).has("foo"); assertThat(names, hasItem("foo")); }
@Test public void booleanToListPropertyRemovesOnChange() { BooleanProperty b = booleanProperty("b", true); ListProperty<String> names = listProperty("names"); names.add("foo"); binder.bind(b).to(names).has("foo"); assertThat(names.get().size(), is(1)); b.set(false); assertThat(names.get().size(), is(0)); }
@Test public void booleanToListPropertyInitiallyRemovesWhenTrue() { BooleanProperty b = booleanProperty("b", false); ListProperty<String> names = listProperty("names"); names.add("foo"); binder.bind(b).to(names).has("foo"); assertThat(names.get().size(), is(0)); }
@Test public void booleanToListPropertySetsFalseOnRemove() { BooleanProperty b = booleanProperty("b", true); ListProperty<String> names = listProperty("names"); binder.bind(b).to(names).has("foo"); assertThat(names.get().size(), is(1)); names.remove("foo"); assertThat(b.get(), is(false)); }
@Test public void booleanToListPropertySetsTrueOnAdd() { BooleanProperty b = booleanProperty("b", false); ListProperty<String> names = listProperty("names"); binder.bind(b).to(names).has("foo"); assertThat(names.get().size(), is(0)); names.add("foo"); assertThat(b.get(), is(true)); }
@Test public void booleanToRadioGroupSetsTheInitialValueWhenNull() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b"); binder.bind(b).to(b1, b2); assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), is(true)); }
@Test public void booleanToRadioGroupSetsTheInitialValueWhenFalse() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", false); binder.bind(b).to(b1, b2); assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), is(true)); }
@Test public void testContainsBound() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); BooleanProperty s = p.contains("s"); b.bind(s).to(c); assertThat(c.getValue(), is(false)); }
@Test public void booleanToRadioGroupSetsTheInitialValueWhenTrue() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", true); binder.bind(b).to(b1, b2); assertThat(b1.getValue(), is(true)); assertThat(b2.getValue(), is(false)); }
@Test public void booleanToListPropertyInitializePropertyToFalse() { BooleanProperty b = booleanProperty("b"); ListProperty<String> names = listProperty("names"); binder.bind(b).to(names).has("foo"); assertThat(b.get(), is(false)); assertThat(b.isTouched(), is(false)); }
@Test public void testContainsBoundWhenUiChanges() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); BooleanProperty s = p.contains("s"); b.bind(s).to(c); c.check(); assertThat(p.get(), contains("s")); c.uncheck(); assertThat(p.get().isEmpty(), is(true)); }
@Test public void booleanToListPropertyInitializePropertyToTrue() { BooleanProperty b = booleanProperty("b"); ListProperty<String> names = listProperty("names"); names.add("foo"); binder.bind(b).to(names).has("foo"); assertThat(b.get(), is(true)); assertThat(b.isTouched(), is(false)); }