mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-02 10:41:40 +12:00
Add utility method for mapped list bindings
This commit is contained in:
parent
0b910aa580
commit
eb4ec0ef2c
1 changed files with 11 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue