mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 00:50:31 +00:00
Add utility method for mapped list bindings
This commit is contained in:
parent
2b300f32e0
commit
1b77a7cc81
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