Search in sources :

Example 6 with Binding

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

Example 7 with Binding

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

Example 8 with Binding

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

Example 9 with Binding

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

Example 10 with Binding

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);
}
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) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) DefaultBidirectionalConverter(com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter) DoubleProperty(javafx.beans.property.DoubleProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) 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