Search in sources :

Example 26 with Binding

use of com.canoo.platform.core.functional.Binding 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 27 with Binding

use of com.canoo.platform.core.functional.Binding 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)

Example 28 with Binding

use of com.canoo.platform.core.functional.Binding in project dolphin-platform by canoo.

the class DefaultDolphinBinder method bidirectionalTo.

@Override
public <T> Binding bidirectionalTo(final javafx.beans.property.Property<T> javaFxProperty, final BidirectionalConverter<T, S> converter) {
    if (javaFxProperty == null) {
        throw new IllegalArgumentException("javaFxProperty must not be null");
    }
    if (converter == null) {
        throw new IllegalArgumentException("converter must not be null");
    }
    final Binding unidirectionalBinding = to(javaFxProperty, converter);
    final Subscription subscription = property.onChanged(e -> javaFxProperty.setValue(converter.convertBack(property.get())));
    return () -> {
        unidirectionalBinding.unbind();
        subscription.unsubscribe();
    };
}
Also used : Binding(com.canoo.platform.core.functional.Binding) Subscription(com.canoo.platform.core.functional.Subscription)

Aggregations

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