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();
};
}
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();
};
}
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();
};
}
Aggregations