Search in sources :

Example 6 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty 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 7 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty 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 8 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty 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 9 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty 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)

Example 10 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXStringBidirectionalWithConverter.

@Test
public void testJavaFXStringBidirectionalWithConverter() {
    Property<Double> doubleDolphinProperty = new MockedProperty<>();
    StringProperty stringJavaFXProperty = new SimpleStringProperty();
    Converter<String, Double> doubleStringConverter = s -> s == null ? null : Double.parseDouble(s);
    Converter<Double, String> stringDoubleConverter = d -> d == null ? null : d.toString();
    BidirectionalConverter<Double, String> doubleStringBidirectionalConverter = new DefaultBidirectionalConverter<>(stringDoubleConverter, doubleStringConverter);
    doubleDolphinProperty.set(0.1);
    assertNotEquals(stringJavaFXProperty.get(), "0.1");
    Binding binding = FXBinder.bind(stringJavaFXProperty).bidirectionalTo(doubleDolphinProperty, doubleStringBidirectionalConverter);
    assertEquals(stringJavaFXProperty.get(), "0.1");
    doubleDolphinProperty.set(0.2);
    assertEquals(stringJavaFXProperty.get(), "0.2");
    doubleDolphinProperty.set(null);
    assertEquals(stringJavaFXProperty.get(), null);
    stringJavaFXProperty.set("0.1");
    assertEquals(doubleDolphinProperty.get(), 0.1);
    stringJavaFXProperty.setValue("0.2");
    assertEquals(doubleDolphinProperty.get(), 0.2);
    binding.unbind();
    doubleDolphinProperty.set(0.3);
    assertEquals(stringJavaFXProperty.get(), "0.2");
}
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) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) DefaultBidirectionalConverter(com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter) Test(org.testng.annotations.Test)

Aggregations

MockedProperty (com.canoo.dp.impl.remoting.MockedProperty)15 Binding (com.canoo.platform.core.functional.Binding)15 Test (org.testng.annotations.Test)15 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)9 StringProperty (javafx.beans.property.StringProperty)9 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 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 ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)5 ObservableList (com.canoo.platform.remoting.ObservableList)5 Property (com.canoo.platform.remoting.Property)5 BidirectionalConverter (com.canoo.platform.remoting.client.javafx.BidirectionalConverter)5