use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXBooleanBidirectionalWithConverter.
@Test
public void testJavaFXBooleanBidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
Converter<Boolean, String> booleanStringConverter = b -> b == null ? null : b.toString();
Converter<String, Boolean> stringBooleanConverter = s -> s == null ? null : Boolean.parseBoolean(s);
BidirectionalConverter<Boolean, String> booleanStringBidirectionalConverter = new DefaultBidirectionalConverter<>(booleanStringConverter, stringBooleanConverter);
stringDolphinProperty.set("true");
assertNotEquals(booleanJavaFXProperty.get(), true);
Binding binding = FXBinder.bind(booleanJavaFXProperty).bidirectionalTo(stringDolphinProperty, booleanStringBidirectionalConverter.invert());
assertEquals(booleanJavaFXProperty.get(), true);
stringDolphinProperty.set("false");
assertEquals(booleanJavaFXProperty.get(), false);
stringDolphinProperty.set(null);
assertEquals(booleanJavaFXProperty.get(), false);
booleanJavaFXProperty.set(true);
assertEquals(stringDolphinProperty.get(), "true");
booleanJavaFXProperty.setValue(null);
assertEquals(stringDolphinProperty.get(), "false");
binding.unbind();
stringDolphinProperty.set("true");
assertEquals(booleanJavaFXProperty.get(), false);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXStringBidirectional.
@Test
public void testJavaFXStringBidirectional() {
Property<String> stringDolphinProperty = new MockedProperty<>();
StringProperty stringJavaFXProperty = new SimpleStringProperty();
stringDolphinProperty.set("Hello");
assertNotEquals(stringJavaFXProperty.get(), "Hello");
Binding binding = FXBinder.bind(stringJavaFXProperty).bidirectionalTo(stringDolphinProperty);
assertEquals(stringJavaFXProperty.get(), "Hello");
stringDolphinProperty.set("Hello World");
assertEquals(stringJavaFXProperty.get(), "Hello World");
stringDolphinProperty.set(null);
assertEquals(stringJavaFXProperty.get(), null);
stringJavaFXProperty.set("Hello from JavaFX");
assertEquals(stringDolphinProperty.get(), "Hello from JavaFX");
stringJavaFXProperty.setValue(null);
assertEquals(stringDolphinProperty.get(), null);
binding.unbind();
stringDolphinProperty.set("Hello Dolphin");
assertEquals(stringJavaFXProperty.get(), null);
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testListBindingWithNonEmptyLists.
@Test
public void testListBindingWithNonEmptyLists() {
ObservableList<String> dolphinList = new ObservableArrayList<>();
javafx.collections.ObservableList<String> javaFXList = FXCollections.observableArrayList();
dolphinList.addAll(Arrays.asList("A", "B", "C"));
Binding binding1 = FXBinder.bind(javaFXList).to(dolphinList);
assertEquals(dolphinList.size(), 3);
assertEquals(javaFXList.size(), 3);
assertTrue(dolphinList.contains("A"));
assertTrue(dolphinList.contains("B"));
assertTrue(dolphinList.contains("C"));
assertTrue(javaFXList.contains("A"));
assertTrue(javaFXList.contains("B"));
assertTrue(javaFXList.contains("C"));
binding1.unbind();
dolphinList.clear();
javaFXList.clear();
javaFXList.addAll("A", "B", "C");
Binding binding2 = FXBinder.bind(javaFXList).to(dolphinList);
assertEquals(dolphinList.size(), 0);
assertEquals(javaFXList.size(), 0);
binding2.unbind();
dolphinList.clear();
javaFXList.clear();
dolphinList.addAll(Arrays.asList("A", "B", "C"));
javaFXList.addAll("D", "E", "F");
FXBinder.bind(javaFXList).to(dolphinList);
assertEquals(dolphinList.size(), 3);
assertEquals(javaFXList.size(), 3);
assertTrue(dolphinList.contains("A"));
assertTrue(dolphinList.contains("B"));
assertTrue(dolphinList.contains("C"));
assertTrue(javaFXList.contains("A"));
assertTrue(javaFXList.contains("B"));
assertTrue(javaFXList.contains("C"));
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testUnidirectionalChain.
@Test
public void testUnidirectionalChain() {
Property<String> stringDolphinProperty1 = new MockedProperty<>();
StringProperty stringJavaFXProperty1 = new SimpleStringProperty();
Property<String> stringDolphinProperty2 = new MockedProperty<>();
StringProperty stringJavaFXProperty2 = new SimpleStringProperty();
Binding binding1 = FXBinder.bind(stringDolphinProperty1).to(stringJavaFXProperty1);
Binding binding2 = FXBinder.bind(stringJavaFXProperty2).to(stringDolphinProperty1);
Binding binding3 = FXBinder.bind(stringDolphinProperty2).to(stringJavaFXProperty2);
stringJavaFXProperty1.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello");
binding2.unbind();
stringJavaFXProperty1.setValue("Hello World");
assertEquals(stringDolphinProperty1.get(), "Hello World");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello World");
assertEquals(stringJavaFXProperty2.get(), "Hello");
binding1.unbind();
binding3.unbind();
}
use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.
the class FXBinderTest method testBidirectionalChain.
@Test
public void testBidirectionalChain() {
Property<String> stringDolphinProperty1 = new MockedProperty<>();
StringProperty stringJavaFXProperty1 = new SimpleStringProperty();
Property<String> stringDolphinProperty2 = new MockedProperty<>();
StringProperty stringJavaFXProperty2 = new SimpleStringProperty();
Binding binding1 = FXBinder.bind(stringDolphinProperty1).bidirectionalTo(stringJavaFXProperty1);
Binding binding2 = FXBinder.bind(stringJavaFXProperty2).bidirectionalTo(stringDolphinProperty1);
Binding binding3 = FXBinder.bind(stringDolphinProperty2).bidirectionalTo(stringJavaFXProperty2);
stringJavaFXProperty1.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello");
stringDolphinProperty1.set("Hello World");
assertEquals(stringDolphinProperty1.get(), "Hello World");
assertEquals(stringDolphinProperty2.get(), "Hello World");
assertEquals(stringJavaFXProperty1.get(), "Hello World");
assertEquals(stringJavaFXProperty2.get(), "Hello World");
stringJavaFXProperty2.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello");
stringDolphinProperty2.set("Hello World");
assertEquals(stringDolphinProperty1.get(), "Hello World");
assertEquals(stringDolphinProperty2.get(), "Hello World");
assertEquals(stringJavaFXProperty1.get(), "Hello World");
assertEquals(stringJavaFXProperty2.get(), "Hello World");
binding2.unbind();
stringJavaFXProperty1.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello World");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello World");
binding1.unbind();
binding3.unbind();
}
Aggregations