Add utility method for mapped list bindings

This commit is contained in:
Christopher Schnick 2022-12-13 23:52:15 +01:00
parent 2b300f32e0
commit 1b77a7cc81

View file

@ -8,6 +8,7 @@ import javafx.collections.ObservableList;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
public class BindingsHelper {
@ -33,6 +34,16 @@ public class BindingsHelper {
});
}
public static <T, V> void bindMappedContent(ObservableList<T> l1, ObservableList<V> l2, Function<V, T> map) {
Runnable runnable = () -> {
setContent(l1, l2.stream().map(map).toList());
};
runnable.run();
l2.addListener((ListChangeListener<? super V>) c -> {
runnable.run();
});
}
public static <T> void setContent(ObservableList<T> toSet, List<? extends T> newList) {
if (toSet.equals(newList)) {
return;