use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.
the class LogClientUtil method createObservableListFromLocalCache.
public static BoundLogList<LogMessage> createObservableListFromLocalCache() {
final ObservableList<LogMessage> list = FXCollections.observableArrayList(DolphinLoggerFactory.getLogCache());
final Subscription subscription = DolphinLoggerFactory.addListener(l -> {
final List<LogMessage> currentCache = Collections.unmodifiableList(DolphinLoggerFactory.getLogCache());
Platform.runLater(() -> {
final List<LogMessage> toRemove = list.stream().filter(e -> !currentCache.contains(l)).collect(Collectors.toList());
list.removeAll(toRemove);
final List<LogMessage> toAdd = currentCache.stream().filter(e -> !list.contains(e)).collect(Collectors.toList());
list.addAll(toAdd);
});
});
return new BoundLogList(subscription, list);
}
use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.
the class AbstractNumericDolphinBinder method bidirectionalToNumeric.
@Override
public Binding bidirectionalToNumeric(final javafx.beans.property.Property<Number> javaFxProperty) {
if (javaFxProperty == null) {
throw new IllegalArgumentException("javaFxProperty must not be null");
}
final Binding unidirectionalBinding = toNumeric(javaFxProperty);
final Subscription subscription = property.onChanged(e -> {
if (!equals(javaFxProperty.getValue(), property.get())) {
javaFxProperty.setValue(getConverter().convertBack(property.get()));
}
});
return () -> {
unidirectionalBinding.unbind();
subscription.unsubscribe();
};
}
use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.
the class DefaultJavaFXBinder method to.
@Override
public <T> Binding to(final Property<T> dolphinProperty, final Converter<? super T, ? extends S> converter) {
Assert.requireNonNull(dolphinProperty, "dolphinProperty");
Assert.requireNonNull(converter, "converter");
final Subscription subscription = dolphinProperty.onChanged(event -> javaFxValue.setValue(converter.convert(dolphinProperty.get())));
javaFxValue.setValue(converter.convert(dolphinProperty.get()));
return () -> subscription.unsubscribe();
}
use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.
the class DefaultJavaFXListBinder method to.
@Override
public <T> Binding to(final ObservableList<T> dolphinList, final Function<? super T, ? extends S> converter) {
Assert.requireNonNull(dolphinList, "dolphinList");
Assert.requireNonNull(converter, "converter");
if (boundLists.containsKey(list)) {
throw new UnsupportedOperationException("A JavaFX list can only be bound to one Dolphin Platform list!");
}
boundLists.put(list, list);
final InternalListChangeListener<T> listChangeListener = new InternalListChangeListener<>(converter);
final Subscription subscription = dolphinList.onChanged(listChangeListener);
list.setAll(dolphinList.stream().map(converter).collect(Collectors.toList()));
ListChangeListener<S> readOnlyListener = c -> {
if (!listChangeListener.onChange) {
throw new UnsupportedOperationException("A JavaFX list that is bound to a dolphin list can only be modified by the binding!");
}
};
list.addListener(readOnlyListener);
return () -> {
subscription.unsubscribe();
list.removeListener(readOnlyListener);
boundLists.remove(list);
};
}
use of com.canoo.platform.core.functional.Subscription in project dolphin-platform by canoo.
the class ContextManagerImplTests method testRemoveGlobalContext.
@Test
public void testRemoveGlobalContext() {
// given:
final ContextManager manager = new ContextManagerImpl();
// when:
final Subscription subscription = manager.addGlobalContext("KEY", "VALUE");
subscription.unsubscribe();
// then:
Assert.assertEquals(manager.getGlobalContexts().size(), 5);
checkForGlobalContextMissing(manager, "KEY");
}
Aggregations