Search in sources :

Example 11 with Property

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

the class GarbageCollector method onBeanCreated.

/**
 * This method must be called for each new Dolphin bean (see {@link RemotingBean}).
 * Normally beans are created by {@link BeanManager#create(Class)}
 *
 * @param bean     the bean that was created
 * @param rootBean if this is true the bean is handled as a root bean. This bean don't need a reference.
 */
public synchronized void onBeanCreated(Object bean, boolean rootBean) {
    if (!configuration.isUseGc()) {
        return;
    }
    Assert.requireNonNull(bean, "bean");
    if (allInstances.containsKey(bean)) {
        throw new IllegalArgumentException("Bean instance is already managed!");
    }
    IdentitySet<Property> properties = getAllProperties(bean);
    IdentitySet<ObservableList> lists = getAllLists(bean);
    Instance instance = new Instance(bean, rootBean, properties, lists);
    allInstances.put(bean, instance);
    for (Property property : properties) {
        propertyToParent.put(property, instance);
    }
    for (ObservableList list : lists) {
        listToParent.put(list, instance);
    }
    if (!rootBean) {
        // Until the bean isn't referenced in another bean it will be removed at gc
        addToGC(instance, bean);
    }
}
Also used : ObservableList(com.canoo.platform.remoting.ObservableList) Property(com.canoo.platform.remoting.Property)

Example 12 with Property

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

Example 13 with Property

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

the class FXBinderTest method testJavaFXDoubleUnidirectionalWithConverter.

@Test
public void testJavaFXDoubleUnidirectionalWithConverter() {
    Property<String> stringDolphinProperty = new MockedProperty<>();
    DoubleProperty doubleJavaFXProperty = new SimpleDoubleProperty();
    WritableDoubleValue writableDoubleValue = new SimpleDoubleProperty();
    Converter<String, Double> stringDoubleConverter = s -> s == null ? null : Double.parseDouble(s);
    stringDolphinProperty.set("47.0");
    assertNotEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
    Binding binding = FXBinder.bind(doubleJavaFXProperty).to(stringDolphinProperty, stringDoubleConverter);
    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);
    binding.unbind();
    stringDolphinProperty.set("100.0");
    assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
    stringDolphinProperty.set("12.0");
    binding = FXBinder.bind(doubleJavaFXProperty).to(stringDolphinProperty, stringDoubleConverter);
    assertEquals(doubleJavaFXProperty.doubleValue(), 12.0, EPSILON);
    stringDolphinProperty.set(null);
    assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
    binding.unbind();
    stringDolphinProperty.set("100.0");
    assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
    stringDolphinProperty.set("47.0");
    binding = FXBinder.bind(writableDoubleValue).to(stringDolphinProperty, stringDoubleConverter);
    assertEquals(writableDoubleValue.get(), 47.0, EPSILON);
    stringDolphinProperty.set("100.0");
    assertEquals(writableDoubleValue.get(), 100.0, EPSILON);
    stringDolphinProperty.set(null);
    assertEquals(writableDoubleValue.get(), 0.0, EPSILON);
    binding.unbind();
    stringDolphinProperty.set("100.0");
    assertEquals(writableDoubleValue.get(), 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) DoubleProperty(javafx.beans.property.DoubleProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) WritableDoubleValue(javafx.beans.value.WritableDoubleValue) Test(org.testng.annotations.Test)

Example 14 with Property

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

the class AbstractNumericJavaFXBidirectionalBinder method bidirectionalToNumeric.

@Override
public <T> Binding bidirectionalToNumeric(final Property<T> property, final BidirectionalConverter<T, S> converter) {
    final Binding unidirectionalBinding = to(property, converter);
    final ChangeListener<Number> listener = (obs, oldVal, newVal) -> property.set(converter.convertBack(convertNumber(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) Property(com.canoo.platform.remoting.Property) API(org.apiguardian.api.API) NumericJavaFXBidirectionaBinder(com.canoo.platform.remoting.client.javafx.binding.NumericJavaFXBidirectionaBinder) ChangeListener(javafx.beans.value.ChangeListener) INTERNAL(org.apiguardian.api.API.Status.INTERNAL)

Example 15 with Property

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

the class AbstractNumericJavaFXBidirectionalBinder method bidirectionalTo.

@Override
public <T> Binding bidirectionalTo(final Property<T> property, BidirectionalConverter<T, Number> converter) {
    final Binding unidirectionalBinding = to(property, converter);
    final ChangeListener<Number> 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) Property(com.canoo.platform.remoting.Property) API(org.apiguardian.api.API) NumericJavaFXBidirectionaBinder(com.canoo.platform.remoting.client.javafx.binding.NumericJavaFXBidirectionaBinder) ChangeListener(javafx.beans.value.ChangeListener) INTERNAL(org.apiguardian.api.API.Status.INTERNAL)

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