From 1b77a7cc81169811b1e5bd15384d9f5679773cde Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Tue, 13 Dec 2022 23:52:15 +0100 Subject: [PATCH] Add utility method for mapped list bindings --- .../xpipe/extension/fxcomps/util/BindingsHelper.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/extension/src/main/java/io/xpipe/extension/fxcomps/util/BindingsHelper.java b/extension/src/main/java/io/xpipe/extension/fxcomps/util/BindingsHelper.java index ee5ada941..a5f174941 100644 --- a/extension/src/main/java/io/xpipe/extension/fxcomps/util/BindingsHelper.java +++ b/extension/src/main/java/io/xpipe/extension/fxcomps/util/BindingsHelper.java @@ -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 void bindMappedContent(ObservableList l1, ObservableList l2, Function map) { + Runnable runnable = () -> { + setContent(l1, l2.stream().map(map).toList()); + }; + runnable.run(); + l2.addListener((ListChangeListener) c -> { + runnable.run(); + }); + } + public static void setContent(ObservableList toSet, List newList) { if (toSet.equals(newList)) { return;