Search in sources :

Example 1 with Property

use of com.canoo.platform.remoting.Property in project dolphin-platform by canoo.

the class DefaultJavaFXBidirectionalBinder method bidirectionalTo.

@Override
public <T> Binding bidirectionalTo(final Property<T> property, final BidirectionalConverter<T, S> converter) {
    final Binding unidirectionalBinding = to(property, converter);
    final ChangeListener<S> listener = (obs, oldVal, newVal) -> property.set(converter.convertBack(newVal));
    javaFxProperty.addListener(listener);
    return () -> {
        javaFxProperty.removeListener(listener);
        unidirectionalBinding.unbind();
    };
}
Also used : Binding(com.canoo.platform.core.functional.Binding) BidirectionalConverter(com.canoo.platform.remoting.client.javafx.BidirectionalConverter) Binding(com.canoo.platform.core.functional.Binding) JavaFXBidirectionalBinder(com.canoo.platform.remoting.client.javafx.binding.JavaFXBidirectionalBinder) Property(com.canoo.platform.remoting.Property) API(org.apiguardian.api.API) ChangeListener(javafx.beans.value.ChangeListener) INTERNAL(org.apiguardian.api.API.Status.INTERNAL)

Example 2 with Property

use of com.canoo.platform.remoting.Property 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 3 with Property

use of com.canoo.platform.remoting.Property 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 4 with Property

use of com.canoo.platform.remoting.Property 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 5 with Property

use of com.canoo.platform.remoting.Property in project dolphin-platform by canoo.

the class GarbageCollector method gc.

/**
 * Calling this method triggers the garbage collection. For all dolphin beans (see {@link RemotingBean}) that
 * are not referenced by a root bean (see {@link RemotingModel}) the defined {@link GarbageCollectionCallback} (see constructor)
 * will be called.
 */
public synchronized void gc() {
    if (!configuration.isUseGc()) {
        LOG.trace("GC deactivated, no beans will be removed!");
        return;
    }
    LOG.trace("Garbage collection started! GC will remove {} beans!", removeOnGC.size());
    onRemoveCallback.onReject(removeOnGC.keySet());
    for (Map.Entry<Instance, Object> entry : removeOnGC.entrySet()) {
        Instance removedInstance = entry.getKey();
        for (Property property : removedInstance.getProperties()) {
            propertyToParent.remove(property);
        }
        for (ObservableList list : removedInstance.getLists()) {
            listToParent.remove(list);
        }
        allInstances.remove(entry.getValue());
    }
    removedBeansCount = removedBeansCount + removeOnGC.size();
    removeOnGC.clear();
    gcCalls = gcCalls + 1;
    LOG.trace("Garbage collection done! GC currently manages {} referenced beans!", allInstances.size());
}
Also used : ObservableList(com.canoo.platform.remoting.ObservableList) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map) Property(com.canoo.platform.remoting.Property)

Aggregations

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