From 4152d6e1dba8f75bb7cb3972fbe94a60f54d8237 Mon Sep 17 00:00:00 2001 From: crschnick Date: Wed, 3 May 2023 17:13:31 +0000 Subject: [PATCH] Improve connection entry change listener --- .../store/StoreEntryFlatMiniSectionComp.java | 9 +++++---- .../app/comp/storage/store/StoreEntryListComp.java | 6 +++--- .../xpipe/app/comp/storage/store/StoreSection.java | 14 ++++++-------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryFlatMiniSectionComp.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryFlatMiniSectionComp.java index 7caa36485..f771ba85f 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryFlatMiniSectionComp.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryFlatMiniSectionComp.java @@ -22,19 +22,20 @@ public class StoreEntryFlatMiniSectionComp extends SimpleComp { public static final ObservableList ALL = FXCollections.observableArrayList(); static { - var topLevel = StoreSection.createTopLevels(); + var topLevel = StoreSection.createTopLevel(); - topLevel.addListener((ListChangeListener) c -> { + // Listen for any entry list change, not only top level changes + StoreViewState.get().getAllEntries().addListener((ListChangeListener) c -> { ALL.clear(); var depth = 0; - for (StoreSection v : topLevel) { + for (StoreSection v : topLevel.getChildren()) { System.out.println(v.getWrapper().getEntry().getName() + " " + v.getChildren().size()); add(depth, v); } }); var depth = 0; - for (StoreSection v : topLevel) { + for (StoreSection v : topLevel.getChildren()) { add(depth, v); } } diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryListComp.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryListComp.java index 5ea1076bd..b7648da5e 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryListComp.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreEntryListComp.java @@ -15,13 +15,13 @@ import java.util.LinkedHashMap; public class StoreEntryListComp extends SimpleComp { private Comp createList() { - var topLevel = StoreSection.createTopLevels(); + var topLevel = StoreSection.createTopLevel(); var filtered = BindingsHelper.filteredContentBinding( - topLevel, + topLevel.getChildren(), StoreViewState.get() .getFilterString() .map(s -> (storeEntrySection -> storeEntrySection.shouldShow(s)))); - var content = new ListBoxViewComp<>(filtered, topLevel, (StoreSection e) -> { + var content = new ListBoxViewComp<>(filtered, topLevel.getChildren(), (StoreSection e) -> { return new StoreEntrySection(e); }); return content.styleClass("store-list-comp").styleClass(Styles.STRIPED); diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSection.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSection.java index d077721a8..c25005e7f 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSection.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSection.java @@ -6,18 +6,16 @@ import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import lombok.AllArgsConstructor; -import lombok.Getter; +import lombok.Value; import java.time.Instant; import java.util.Comparator; -@AllArgsConstructor -@Getter +@Value public class StoreSection implements StorageFilter.Filterable { - private final StoreEntryWrapper wrapper; - private final ObservableList children; + StoreEntryWrapper wrapper; + ObservableList children; private static final Comparator COMPARATOR = Comparator.comparing( o -> o.wrapper.getEntry().getState().equals(DataStoreEntry.State.COMPLETE_AND_VALID) @@ -26,7 +24,7 @@ public class StoreSection implements StorageFilter.Filterable { .thenComparing( storeEntrySection -> storeEntrySection.wrapper.getEntry().getName()); - public static ObservableList createTopLevels() { + public static StoreSection createTopLevel() { var topLevel = BindingsHelper.mappedContentBinding(StoreViewState.get().getAllEntries(), storeEntryWrapper -> create(storeEntryWrapper)); var filtered = BindingsHelper.filteredContentBinding(topLevel, section -> { @@ -44,7 +42,7 @@ public class StoreSection implements StorageFilter.Filterable { var ordered = BindingsHelper.orderedContentBinding( filtered, COMPARATOR); - return ordered; + return new StoreSection(null, ordered); } private static StoreSection create(StoreEntryWrapper e) {