Search in sources :

Example 1 with DefaultBidirectionalConverter

use of com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter 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)

Example 2 with DefaultBidirectionalConverter

use of com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter 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 3 with DefaultBidirectionalConverter

use of com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter 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

DefaultBidirectionalConverter (com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter)3 MockedProperty (com.canoo.dp.impl.remoting.MockedProperty)3 ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)3 Binding (com.canoo.platform.core.functional.Binding)3 ObservableList (com.canoo.platform.remoting.ObservableList)3 Property (com.canoo.platform.remoting.Property)3 BidirectionalConverter (com.canoo.platform.remoting.client.javafx.BidirectionalConverter)3 Converter (com.canoo.platform.remoting.client.javafx.Converter)3 FXBinder (com.canoo.platform.remoting.client.javafx.FXBinder)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 List (java.util.List)3 BooleanProperty (javafx.beans.property.BooleanProperty)3 DoubleProperty (javafx.beans.property.DoubleProperty)3 IntegerProperty (javafx.beans.property.IntegerProperty)3 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)3 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)3 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)3 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)3 StringProperty (javafx.beans.property.StringProperty)3