Search in sources :

Example 1 with WritableBooleanValue

use of javafx.beans.value.WritableBooleanValue in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXBooleanUnidirectionalWithConverter.

@Test
public void testJavaFXBooleanUnidirectionalWithConverter() {
    Property<String> stringDolphinProperty = new MockedProperty<>();
    BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
    WritableBooleanValue writableBooleanValue = new SimpleBooleanProperty();
    Converter<String, Boolean> stringBooleanConverter = s -> s == null ? null : Boolean.parseBoolean(s);
    stringDolphinProperty.set("Hello");
    assertEquals(booleanJavaFXProperty.get(), false);
    Binding binding = FXBinder.bind(booleanJavaFXProperty).to(stringDolphinProperty, stringBooleanConverter);
    assertEquals(booleanJavaFXProperty.get(), false);
    stringDolphinProperty.set("true");
    assertEquals(booleanJavaFXProperty.get(), true);
    stringDolphinProperty.set(null);
    assertEquals(booleanJavaFXProperty.get(), false);
    binding.unbind();
    stringDolphinProperty.set("true");
    assertEquals(booleanJavaFXProperty.get(), false);
    stringDolphinProperty.set("false");
    binding = FXBinder.bind(writableBooleanValue).to(stringDolphinProperty, stringBooleanConverter);
    assertEquals(writableBooleanValue.get(), false);
    stringDolphinProperty.set("true");
    assertEquals(writableBooleanValue.get(), true);
    stringDolphinProperty.set(null);
    assertEquals(writableBooleanValue.get(), false);
    binding.unbind();
    stringDolphinProperty.set("true");
    assertEquals(writableBooleanValue.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) WritableBooleanValue(javafx.beans.value.WritableBooleanValue) Test(org.testng.annotations.Test)

Example 2 with WritableBooleanValue

use of javafx.beans.value.WritableBooleanValue in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXBooleanUnidirectional.

@Test
public void testJavaFXBooleanUnidirectional() {
    Property<Boolean> booleanDolphinProperty = new MockedProperty<>();
    BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
    WritableBooleanValue writableBooleanValue = new SimpleBooleanProperty();
    booleanDolphinProperty.set(true);
    assertNotEquals(booleanJavaFXProperty.get(), true);
    Binding binding = FXBinder.bind(booleanJavaFXProperty).to(booleanDolphinProperty);
    assertEquals(booleanJavaFXProperty.get(), true);
    booleanDolphinProperty.set(false);
    assertEquals(booleanJavaFXProperty.get(), false);
    booleanDolphinProperty.set(null);
    assertEquals(booleanJavaFXProperty.get(), false);
    binding.unbind();
    booleanDolphinProperty.set(true);
    assertEquals(booleanJavaFXProperty.get(), false);
    binding = FXBinder.bind(writableBooleanValue).to(booleanDolphinProperty);
    assertEquals(writableBooleanValue.get(), true);
    booleanDolphinProperty.set(false);
    assertEquals(writableBooleanValue.get(), false);
    booleanDolphinProperty.set(null);
    assertEquals(writableBooleanValue.get(), false);
    binding.unbind();
    booleanDolphinProperty.set(true);
    assertEquals(writableBooleanValue.get(), false);
}
Also used : 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) WritableBooleanValue(javafx.beans.value.WritableBooleanValue) Test(org.testng.annotations.Test)

Aggregations

MockedProperty (com.canoo.dp.impl.remoting.MockedProperty)2 Binding (com.canoo.platform.core.functional.Binding)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 WritableBooleanValue (javafx.beans.value.WritableBooleanValue)2 Test (org.testng.annotations.Test)2 DefaultBidirectionalConverter (com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter)1 ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)1 ObservableList (com.canoo.platform.remoting.ObservableList)1 Property (com.canoo.platform.remoting.Property)1 BidirectionalConverter (com.canoo.platform.remoting.client.javafx.BidirectionalConverter)1 Converter (com.canoo.platform.remoting.client.javafx.Converter)1 FXBinder (com.canoo.platform.remoting.client.javafx.FXBinder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 IntegerProperty (javafx.beans.property.IntegerProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)1