use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testCorrectUnbind.
@Test
public void testCorrectUnbind() {
ObservableList<String> dolphinList = new ObservableArrayList<>();
ObservableList<String> dolphinList2 = new ObservableArrayList<>();
javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
Binding binding = FXBinder.bind(javaFXList).to(dolphinList);
dolphinList.add("Foo");
assertEquals(dolphinList.size(), 1);
assertEquals(dolphinList2.size(), 0);
assertEquals(javaFXList.size(), 1);
binding.unbind();
FXBinder.bind(javaFXList).to(dolphinList2);
assertEquals(dolphinList.size(), 1);
assertEquals(dolphinList2.size(), 0);
assertEquals(javaFXList.size(), 0);
dolphinList2.add("Foo");
dolphinList2.add("Bar");
assertEquals(dolphinList.size(), 1);
assertEquals(dolphinList2.size(), 2);
assertEquals(javaFXList.size(), 2);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXStringUnidirectional.
@Test
public void testJavaFXStringUnidirectional() {
Property<String> stringDolphinProperty = new MockedProperty<>();
StringProperty stringJavaFXProperty = new SimpleStringProperty();
WritableStringValue writableStringValue = new SimpleStringProperty();
stringDolphinProperty.set("Hello");
assertNotEquals(stringJavaFXProperty.get(), "Hello");
Binding binding = FXBinder.bind(stringJavaFXProperty).to(stringDolphinProperty);
assertEquals(stringJavaFXProperty.get(), "Hello");
stringDolphinProperty.set("Hello JavaFX");
assertEquals(stringJavaFXProperty.get(), "Hello JavaFX");
stringDolphinProperty.set(null);
assertEquals(stringJavaFXProperty.get(), null);
binding.unbind();
stringDolphinProperty.set("Hello JavaFX");
assertEquals(stringJavaFXProperty.get(), null);
binding = FXBinder.bind(writableStringValue).to(stringDolphinProperty);
assertEquals(writableStringValue.get(), "Hello JavaFX");
stringDolphinProperty.set("Dolphin Platform");
assertEquals(writableStringValue.get(), "Dolphin Platform");
stringDolphinProperty.set(null);
assertEquals(writableStringValue.get(), null);
binding.unbind();
stringDolphinProperty.set("Dolphin Platform");
assertEquals(writableStringValue.get(), null);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXIntegerUnidirectional.
@Test
public void testJavaFXIntegerUnidirectional() {
Property<Integer> integerDolphinProperty = new MockedProperty<>();
Property<Number> numberDolphinProperty = new MockedProperty<>();
IntegerProperty integerJavaFXProperty = new SimpleIntegerProperty();
WritableIntegerValue writableIntegerValue = new SimpleIntegerProperty();
integerDolphinProperty.set(47);
assertNotEquals(integerJavaFXProperty.doubleValue(), 47);
Binding binding = FXBinder.bind(integerJavaFXProperty).to(integerDolphinProperty);
assertEquals(integerJavaFXProperty.get(), 47);
integerDolphinProperty.set(100);
assertEquals(integerJavaFXProperty.get(), 100);
integerDolphinProperty.set(null);
assertEquals(integerJavaFXProperty.get(), 0);
binding.unbind();
integerDolphinProperty.set(100);
assertEquals(integerJavaFXProperty.get(), 0);
numberDolphinProperty.set(12);
binding = FXBinder.bind(integerJavaFXProperty).to(numberDolphinProperty);
assertEquals(integerJavaFXProperty.get(), 12);
numberDolphinProperty.set(null);
assertEquals(integerJavaFXProperty.get(), 0);
binding.unbind();
numberDolphinProperty.set(100);
assertEquals(integerJavaFXProperty.get(), 0);
integerDolphinProperty.set(47);
binding = FXBinder.bind(writableIntegerValue).to(integerDolphinProperty);
assertEquals(writableIntegerValue.get(), 47);
integerDolphinProperty.set(100);
assertEquals(writableIntegerValue.get(), 100);
integerDolphinProperty.set(null);
assertEquals(writableIntegerValue.get(), 0);
binding.unbind();
integerDolphinProperty.set(100);
assertEquals(writableIntegerValue.get(), 0);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method severalBindings.
@Test
public void severalBindings() {
ObservableList<String> dolphinList1 = new ObservableArrayList<>();
ObservableList<String> dolphinList2 = new ObservableArrayList<>();
ObservableList<String> dolphinList3 = new ObservableArrayList<>();
ObservableList<String> dolphinList4 = new ObservableArrayList<>();
javafx.collections.ObservableList<String> javaFXList1 = FXCollections.observableArrayList();
javafx.collections.ObservableList<String> javaFXList2 = FXCollections.observableArrayList();
javafx.collections.ObservableList<String> javaFXList3 = FXCollections.observableArrayList();
javafx.collections.ObservableList<String> javaFXList4 = FXCollections.observableArrayList();
Binding binding1 = FXBinder.bind(javaFXList1).to(dolphinList1);
Binding binding2 = FXBinder.bind(javaFXList2).to(dolphinList2);
Binding binding3 = FXBinder.bind(javaFXList3).to(dolphinList3);
Binding binding4 = FXBinder.bind(javaFXList4).to(dolphinList4);
binding1.unbind();
binding2.unbind();
binding1 = FXBinder.bind(javaFXList1).to(dolphinList2);
binding2 = FXBinder.bind(javaFXList2).to(dolphinList1);
binding3.unbind();
binding4.unbind();
binding3 = FXBinder.bind(javaFXList3).to(dolphinList4);
binding4 = FXBinder.bind(javaFXList4).to(dolphinList3);
binding1.unbind();
binding2.unbind();
binding3.unbind();
binding4.unbind();
binding1 = FXBinder.bind(javaFXList1).to(dolphinList4);
binding2 = FXBinder.bind(javaFXList2).to(dolphinList3);
binding3 = FXBinder.bind(javaFXList3).to(dolphinList2);
binding4 = FXBinder.bind(javaFXList4).to(dolphinList1);
binding1.unbind();
binding2.unbind();
binding3.unbind();
binding4.unbind();
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXDoubleBidirectionalWithConverter.
@Test
public void testJavaFXDoubleBidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
DoubleProperty doubleJavaFXProperty = new SimpleDoubleProperty();
Converter<String, Double> stringDoubleConverter = s -> s == null ? null : Double.parseDouble(s);
Converter<Double, String> doubleStringConverter = d -> d == null ? null : d.toString();
BidirectionalConverter<String, Double> doubleBidirectionalConverter = new DefaultBidirectionalConverter<>(stringDoubleConverter, doubleStringConverter);
stringDolphinProperty.set("47.0");
assertNotEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
Binding binding = FXBinder.bind(doubleJavaFXProperty).bidirectionalToNumeric(stringDolphinProperty, doubleBidirectionalConverter);
assertEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 100.0, EPSILON);
stringDolphinProperty.set(null);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
doubleJavaFXProperty.set(12.0);
assertEquals(stringDolphinProperty.get(), "12.0");
doubleJavaFXProperty.setValue(null);
assertEquals(stringDolphinProperty.get(), "0.0");
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
}
Aggregations