Improve connection entry change listener

This commit is contained in:
crschnick 2023-05-03 17:13:31 +00:00
parent cd771d4039
commit 4152d6e1db
3 changed files with 14 additions and 15 deletions

View file

@ -22,19 +22,20 @@ public class StoreEntryFlatMiniSectionComp extends SimpleComp {
public static final ObservableList<StoreEntryFlatMiniSectionComp> ALL = FXCollections.observableArrayList();
static {
var topLevel = StoreSection.createTopLevels();
var topLevel = StoreSection.createTopLevel();
topLevel.addListener((ListChangeListener<? super StoreSection>) c -> {
// Listen for any entry list change, not only top level changes
StoreViewState.get().getAllEntries().addListener((ListChangeListener<? super StoreEntryWrapper>) 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);
}
}

View file

@ -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);

View file

@ -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<StoreSection> children;
StoreEntryWrapper wrapper;
ObservableList<StoreSection> children;
private static final Comparator<StoreSection> COMPARATOR = Comparator.<StoreSection, Instant>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<StoreSection> 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) {