use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXDoubleBidirectional.
@Test
public void testJavaFXDoubleBidirectional() {
Property<Double> doubleDolphinProperty = new MockedProperty<>();
Property<Number> numberDolphinProperty = new MockedProperty<>();
DoubleProperty doubleJavaFXProperty = new SimpleDoubleProperty();
doubleDolphinProperty.set(47.0);
assertNotEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
Binding binding = FXBinder.bind(doubleJavaFXProperty).bidirectionalToNumeric(doubleDolphinProperty);
assertEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
doubleDolphinProperty.set(100.0);
assertEquals(doubleJavaFXProperty.doubleValue(), 100.0, EPSILON);
doubleDolphinProperty.set(null);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
doubleJavaFXProperty.set(12.0);
assertEquals(doubleDolphinProperty.get().doubleValue(), 12.0, EPSILON);
doubleJavaFXProperty.setValue(null);
assertEquals(doubleDolphinProperty.get().doubleValue(), 0.0, EPSILON);
binding.unbind();
doubleDolphinProperty.set(100.0);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
numberDolphinProperty.set(12.0);
binding = FXBinder.bind(doubleJavaFXProperty).bidirectionalTo(numberDolphinProperty);
assertEquals(doubleJavaFXProperty.doubleValue(), 12.0, EPSILON);
numberDolphinProperty.set(null);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
doubleJavaFXProperty.set(12.0);
assertEquals(numberDolphinProperty.get().doubleValue(), 12.0, EPSILON);
doubleJavaFXProperty.setValue(null);
assertEquals(numberDolphinProperty.get().doubleValue(), 0.0, EPSILON);
binding.unbind();
numberDolphinProperty.set(100.0);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXDoubleUnidirectionalWithConverter.
@Test
public void testJavaFXDoubleUnidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
DoubleProperty doubleJavaFXProperty = new SimpleDoubleProperty();
WritableDoubleValue writableDoubleValue = new SimpleDoubleProperty();
Converter<String, Double> stringDoubleConverter = s -> s == null ? null : Double.parseDouble(s);
stringDolphinProperty.set("47.0");
assertNotEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
Binding binding = FXBinder.bind(doubleJavaFXProperty).to(stringDolphinProperty, stringDoubleConverter);
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);
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
stringDolphinProperty.set("12.0");
binding = FXBinder.bind(doubleJavaFXProperty).to(stringDolphinProperty, stringDoubleConverter);
assertEquals(doubleJavaFXProperty.doubleValue(), 12.0, EPSILON);
stringDolphinProperty.set(null);
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
stringDolphinProperty.set("47.0");
binding = FXBinder.bind(writableDoubleValue).to(stringDolphinProperty, stringDoubleConverter);
assertEquals(writableDoubleValue.get(), 47.0, EPSILON);
stringDolphinProperty.set("100.0");
assertEquals(writableDoubleValue.get(), 100.0, EPSILON);
stringDolphinProperty.set(null);
assertEquals(writableDoubleValue.get(), 0.0, EPSILON);
binding.unbind();
stringDolphinProperty.set("100.0");
assertEquals(writableDoubleValue.get(), 0.0, EPSILON);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testListBinding.
@Test
public void testListBinding() {
ObservableList<String> dolphinList = new ObservableArrayList<>();
javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
Binding binding = FXBinder.bind(javaFXList).to(dolphinList);
assertEquals(dolphinList.size(), 0);
assertEquals(javaFXList.size(), 0);
dolphinList.add("Hello");
assertEquals(dolphinList.size(), 1);
assertEquals(javaFXList.size(), 1);
assertTrue(dolphinList.contains("Hello"));
assertTrue(javaFXList.contains("Hello"));
dolphinList.add("World");
dolphinList.add("Dolphin");
assertEquals(dolphinList.size(), 3);
assertEquals(javaFXList.size(), 3);
assertEquals(dolphinList.indexOf("Hello"), 0);
assertEquals(dolphinList.indexOf("World"), 1);
assertEquals(dolphinList.indexOf("Dolphin"), 2);
assertEquals(javaFXList.indexOf("Hello"), 0);
assertEquals(javaFXList.indexOf("World"), 1);
assertEquals(javaFXList.indexOf("Dolphin"), 2);
dolphinList.clear();
assertEquals(dolphinList.size(), 0);
assertEquals(javaFXList.size(), 0);
dolphinList.add("Java");
assertEquals(dolphinList.size(), 1);
assertEquals(javaFXList.size(), 1);
assertTrue(dolphinList.contains("Java"));
assertTrue(javaFXList.contains("Java"));
binding.unbind();
assertEquals(dolphinList.size(), 1);
assertEquals(javaFXList.size(), 1);
assertTrue(dolphinList.contains("Java"));
assertTrue(javaFXList.contains("Java"));
dolphinList.add("Duke");
assertEquals(dolphinList.size(), 2);
assertEquals(javaFXList.size(), 1);
assertTrue(dolphinList.contains("Java"));
assertTrue(dolphinList.contains("Duke"));
assertTrue(javaFXList.contains("Java"));
FXBinder.bind(javaFXList).to(dolphinList);
dolphinList.clear();
assertEquals(dolphinList.size(), 0);
assertEquals(javaFXList.size(), 0);
Runnable check = () -> {
assertEquals(dolphinList.size(), 4);
assertEquals(javaFXList.size(), 4);
assertEquals(dolphinList.indexOf("A"), 0);
assertEquals(dolphinList.indexOf("B"), 1);
assertEquals(dolphinList.indexOf("C"), 2);
assertEquals(dolphinList.indexOf("D"), 3);
assertEquals(javaFXList.indexOf("A"), 0);
assertEquals(javaFXList.indexOf("B"), 1);
assertEquals(javaFXList.indexOf("C"), 2);
assertEquals(javaFXList.indexOf("D"), 3);
};
// add first
dolphinList.clear();
dolphinList.addAll(Arrays.asList("B", "C", "D"));
dolphinList.add(0, "A");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("C", "D"));
dolphinList.add(0, "A");
dolphinList.add(1, "B");
check.run();
// add any
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "D"));
dolphinList.add(2, "C");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "D"));
dolphinList.add(1, "B");
dolphinList.add(2, "C");
check.run();
// add last
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C"));
dolphinList.add(3, "D");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B"));
dolphinList.add(2, "C");
dolphinList.add(3, "D");
check.run();
// removePresentationModel first
dolphinList.clear();
dolphinList.addAll(Arrays.asList("X", "A", "B", "C", "D"));
dolphinList.remove(0);
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("X", "A", "B", "C", "D"));
dolphinList.remove("X");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("X1", "X2", "A", "B", "C", "D"));
dolphinList.remove(0);
dolphinList.remove(0);
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("X1", "X2", "A", "B", "C", "D"));
dolphinList.remove("X1");
dolphinList.remove("X2");
check.run();
// removePresentationModel any
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "X", "C", "D"));
dolphinList.remove(2);
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "X", "C", "D"));
dolphinList.remove("X");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "X1", "X2", "C", "D"));
dolphinList.remove(2);
dolphinList.remove(2);
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "X1", "X2", "C", "D"));
dolphinList.remove("X1");
dolphinList.remove("X2");
check.run();
// removePresentationModel last
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X"));
dolphinList.remove(4);
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X"));
dolphinList.remove("X");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X1", "X2"));
dolphinList.remove(5);
dolphinList.remove(4);
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C", "D", "X1", "X2"));
dolphinList.remove("X1");
dolphinList.remove("X2");
check.run();
// set first
dolphinList.clear();
dolphinList.addAll(Arrays.asList("X", "B", "C", "D"));
dolphinList.set(0, "A");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("X1", "X2", "C", "D"));
dolphinList.set(0, "A");
dolphinList.set(1, "B");
check.run();
// set any
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "X", "D"));
dolphinList.set(2, "C");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "X1", "X2", "D"));
dolphinList.set(1, "B");
dolphinList.set(2, "C");
check.run();
// set last
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C", "X"));
dolphinList.set(3, "D");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "X1", "X2"));
dolphinList.set(2, "C");
dolphinList.set(3, "D");
check.run();
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C", "X1", "X2", "X3", "D"));
dolphinList.remove("X1");
dolphinList.remove("X2");
dolphinList.remove("X3");
assertEquals(dolphinList.size(), 4);
assertEquals(javaFXList.size(), 4);
assertEquals(dolphinList.indexOf("A"), 0);
assertEquals(dolphinList.indexOf("B"), 1);
assertEquals(dolphinList.indexOf("C"), 2);
assertEquals(dolphinList.indexOf("D"), 3);
assertEquals(javaFXList.indexOf("A"), 0);
assertEquals(javaFXList.indexOf("B"), 1);
assertEquals(javaFXList.indexOf("C"), 2);
assertEquals(javaFXList.indexOf("D"), 3);
dolphinList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "F", "D"));
dolphinList.set(2, "C");
assertEquals(dolphinList.size(), 4);
assertEquals(javaFXList.size(), 4);
assertEquals(dolphinList.indexOf("A"), 0);
assertEquals(dolphinList.indexOf("B"), 1);
assertEquals(dolphinList.indexOf("C"), 2);
assertEquals(dolphinList.indexOf("D"), 3);
assertEquals(javaFXList.indexOf("A"), 0);
assertEquals(javaFXList.indexOf("B"), 1);
assertEquals(javaFXList.indexOf("C"), 2);
assertEquals(javaFXList.indexOf("D"), 3);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testConvertedListBinding.
@Test
public void testConvertedListBinding() {
ObservableList<Boolean> dolphinList = new ObservableArrayList<>();
javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
Binding binding = FXBinder.bind(javaFXList).to(dolphinList, value -> value.toString());
dolphinList.add(true);
assertEquals(dolphinList.size(), 1);
assertEquals(javaFXList.size(), 1);
assertEquals(javaFXList.get(0), "true");
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXBooleanUnidirectional.
@Test
public void testJavaFXBooleanUnidirectional() {
Property<Boolean> booleanDolphinProperty = new MockedProperty<>();
BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
WritableBooleanValue writableBooleanValue = new SimpleBooleanProperty();
booleanDolphinProperty.set(true);
assertNotEquals(booleanJavaFXProperty.get(), true);
Binding binding = FXBinder.bind(booleanJavaFXProperty).to(booleanDolphinProperty);
assertEquals(booleanJavaFXProperty.get(), true);
booleanDolphinProperty.set(false);
assertEquals(booleanJavaFXProperty.get(), false);
booleanDolphinProperty.set(null);
assertEquals(booleanJavaFXProperty.get(), false);
binding.unbind();
booleanDolphinProperty.set(true);
assertEquals(booleanJavaFXProperty.get(), false);
binding = FXBinder.bind(writableBooleanValue).to(booleanDolphinProperty);
assertEquals(writableBooleanValue.get(), true);
booleanDolphinProperty.set(false);
assertEquals(writableBooleanValue.get(), false);
booleanDolphinProperty.set(null);
assertEquals(writableBooleanValue.get(), false);
binding.unbind();
booleanDolphinProperty.set(true);
assertEquals(writableBooleanValue.get(), false);
}
Aggregations