Search in sources :

Example 11 with Binding

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);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) Arrays(java.util.Arrays) WritableBooleanValue(javafx.beans.value.WritableBooleanValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) Assert.assertEquals(org.testng.Assert.assertEquals) DoubleProperty(javafx.beans.property.DoubleProperty) Test(org.testng.annotations.Test) FXBinder(com.canoo.platform.remoting.client.javafx.FXBinder) DefaultBidirectionalConverter(com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter) Property(com.canoo.platform.remoting.Property) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) WritableStringValue(javafx.beans.value.WritableStringValue) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ObservableList(com.canoo.platform.remoting.ObservableList) Converter(com.canoo.platform.remoting.client.javafx.Converter) BidirectionalConverter(com.canoo.platform.remoting.client.javafx.BidirectionalConverter) BooleanProperty(javafx.beans.property.BooleanProperty) List(java.util.List) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) WritableIntegerValue(javafx.beans.value.WritableIntegerValue) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Assert.assertTrue(org.testng.Assert.assertTrue) StringProperty(javafx.beans.property.StringProperty) WritableDoubleValue(javafx.beans.value.WritableDoubleValue) Binding(com.canoo.platform.core.functional.Binding) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) DefaultBidirectionalConverter(com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter) Test(org.testng.annotations.Test)

Example 12 with Binding

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);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Test(org.testng.annotations.Test)

Example 13 with Binding

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"));
}
Also used : Binding(com.canoo.platform.core.functional.Binding) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Test(org.testng.annotations.Test)

Example 14 with Binding

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();
}
Also used : Binding(com.canoo.platform.core.functional.Binding) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Test(org.testng.annotations.Test)

Example 15 with Binding

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();
}
Also used : Binding(com.canoo.platform.core.functional.Binding) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Test(org.testng.annotations.Test)

Aggregations

Binding (com.canoo.platform.core.functional.Binding)28 Test (org.testng.annotations.Test)21 MockedProperty (com.canoo.dp.impl.remoting.MockedProperty)15 ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)11 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)9 StringProperty (javafx.beans.property.StringProperty)9 Property (com.canoo.platform.remoting.Property)8 BidirectionalConverter (com.canoo.platform.remoting.client.javafx.BidirectionalConverter)8 BooleanProperty (javafx.beans.property.BooleanProperty)7 DoubleProperty (javafx.beans.property.DoubleProperty)7 IntegerProperty (javafx.beans.property.IntegerProperty)7 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)7 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)7 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)7 ObservableList (com.canoo.platform.remoting.ObservableList)6 WritableBooleanValue (javafx.beans.value.WritableBooleanValue)6 WritableDoubleValue (javafx.beans.value.WritableDoubleValue)6 WritableIntegerValue (javafx.beans.value.WritableIntegerValue)6 WritableStringValue (javafx.beans.value.WritableStringValue)6 DefaultBidirectionalConverter (com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter)5