mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-10-02 18:17:27 +13:00
Improve connection entry change listener
This commit is contained in:
parent
cd771d4039
commit
4152d6e1db
3 changed files with 14 additions and 15 deletions
|
@ -22,19 +22,20 @@ public class StoreEntryFlatMiniSectionComp extends SimpleComp {
|
||||||
public static final ObservableList<StoreEntryFlatMiniSectionComp> ALL = FXCollections.observableArrayList();
|
public static final ObservableList<StoreEntryFlatMiniSectionComp> ALL = FXCollections.observableArrayList();
|
||||||
|
|
||||||
static {
|
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();
|
ALL.clear();
|
||||||
var depth = 0;
|
var depth = 0;
|
||||||
for (StoreSection v : topLevel) {
|
for (StoreSection v : topLevel.getChildren()) {
|
||||||
System.out.println(v.getWrapper().getEntry().getName() + " " + v.getChildren().size());
|
System.out.println(v.getWrapper().getEntry().getName() + " " + v.getChildren().size());
|
||||||
add(depth, v);
|
add(depth, v);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var depth = 0;
|
var depth = 0;
|
||||||
for (StoreSection v : topLevel) {
|
for (StoreSection v : topLevel.getChildren()) {
|
||||||
add(depth, v);
|
add(depth, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ import java.util.LinkedHashMap;
|
||||||
public class StoreEntryListComp extends SimpleComp {
|
public class StoreEntryListComp extends SimpleComp {
|
||||||
|
|
||||||
private Comp<?> createList() {
|
private Comp<?> createList() {
|
||||||
var topLevel = StoreSection.createTopLevels();
|
var topLevel = StoreSection.createTopLevel();
|
||||||
var filtered = BindingsHelper.filteredContentBinding(
|
var filtered = BindingsHelper.filteredContentBinding(
|
||||||
topLevel,
|
topLevel.getChildren(),
|
||||||
StoreViewState.get()
|
StoreViewState.get()
|
||||||
.getFilterString()
|
.getFilterString()
|
||||||
.map(s -> (storeEntrySection -> storeEntrySection.shouldShow(s))));
|
.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 new StoreEntrySection(e);
|
||||||
});
|
});
|
||||||
return content.styleClass("store-list-comp").styleClass(Styles.STRIPED);
|
return content.styleClass("store-list-comp").styleClass(Styles.STRIPED);
|
||||||
|
|
|
@ -6,18 +6,16 @@ import io.xpipe.app.storage.DataStorage;
|
||||||
import io.xpipe.app.storage.DataStoreEntry;
|
import io.xpipe.app.storage.DataStoreEntry;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.Value;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@Value
|
||||||
@Getter
|
|
||||||
public class StoreSection implements StorageFilter.Filterable {
|
public class StoreSection implements StorageFilter.Filterable {
|
||||||
|
|
||||||
private final StoreEntryWrapper wrapper;
|
StoreEntryWrapper wrapper;
|
||||||
private final ObservableList<StoreSection> children;
|
ObservableList<StoreSection> children;
|
||||||
|
|
||||||
private static final Comparator<StoreSection> COMPARATOR = Comparator.<StoreSection, Instant>comparing(
|
private static final Comparator<StoreSection> COMPARATOR = Comparator.<StoreSection, Instant>comparing(
|
||||||
o -> o.wrapper.getEntry().getState().equals(DataStoreEntry.State.COMPLETE_AND_VALID)
|
o -> o.wrapper.getEntry().getState().equals(DataStoreEntry.State.COMPLETE_AND_VALID)
|
||||||
|
@ -26,7 +24,7 @@ public class StoreSection implements StorageFilter.Filterable {
|
||||||
.thenComparing(
|
.thenComparing(
|
||||||
storeEntrySection -> storeEntrySection.wrapper.getEntry().getName());
|
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 topLevel = BindingsHelper.mappedContentBinding(StoreViewState.get().getAllEntries(), storeEntryWrapper -> create(storeEntryWrapper));
|
||||||
var filtered =
|
var filtered =
|
||||||
BindingsHelper.filteredContentBinding(topLevel, section -> {
|
BindingsHelper.filteredContentBinding(topLevel, section -> {
|
||||||
|
@ -44,7 +42,7 @@ public class StoreSection implements StorageFilter.Filterable {
|
||||||
var ordered = BindingsHelper.orderedContentBinding(
|
var ordered = BindingsHelper.orderedContentBinding(
|
||||||
filtered,
|
filtered,
|
||||||
COMPARATOR);
|
COMPARATOR);
|
||||||
return ordered;
|
return new StoreSection(null, ordered);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StoreSection create(StoreEntryWrapper e) {
|
private static StoreSection create(StoreEntryWrapper e) {
|
||||||
|
|
Loading…
Reference in a new issue