Jump to only filter result left

This commit is contained in:
crschnick 2024-08-30 02:49:20 +00:00
parent 9529dceb5c
commit 0c1f63d3c9
3 changed files with 28 additions and 6 deletions

View file

@ -28,7 +28,8 @@ public class StoreCategoryWrapper {
private final Property<StoreSortMode> sortMode; private final Property<StoreSortMode> sortMode;
private final Property<Boolean> sync; private final Property<Boolean> sync;
private final ObservableList<StoreCategoryWrapper> children; private final ObservableList<StoreCategoryWrapper> children;
private final ObservableList<StoreEntryWrapper> containedEntries; private final ObservableList<StoreEntryWrapper> directContainedEntries;
private final ObservableList<StoreEntryWrapper> allContainedEntries;
private final BooleanProperty expanded = new SimpleBooleanProperty(); private final BooleanProperty expanded = new SimpleBooleanProperty();
private final Property<DataColor> color = new SimpleObjectProperty<>(); private final Property<DataColor> color = new SimpleObjectProperty<>();
@ -52,7 +53,8 @@ public class StoreCategoryWrapper {
this.sortMode = new SimpleObjectProperty<>(category.getSortMode()); this.sortMode = new SimpleObjectProperty<>(category.getSortMode());
this.sync = new SimpleObjectProperty<>(category.isSync()); this.sync = new SimpleObjectProperty<>(category.isSync());
this.children = FXCollections.observableArrayList(); this.children = FXCollections.observableArrayList();
this.containedEntries = FXCollections.observableArrayList(); this.allContainedEntries = FXCollections.observableArrayList();
this.directContainedEntries = FXCollections.observableArrayList();
this.color.setValue(category.getColor()); this.color.setValue(category.getColor());
setupListeners(); setupListeners();
} }
@ -70,7 +72,7 @@ public class StoreCategoryWrapper {
} }
public boolean contains(StoreEntryWrapper entry) { public boolean contains(StoreEntryWrapper entry) {
return entry.getEntry().getCategoryUuid().equals(category.getUuid()) || containedEntries.contains(entry); return entry.getEntry().getCategoryUuid().equals(category.getUuid()) || allContainedEntries.contains(entry);
} }
public void select() { public void select() {
@ -135,7 +137,12 @@ public class StoreCategoryWrapper {
expanded.setValue(category.isExpanded()); expanded.setValue(category.isExpanded());
color.setValue(category.getColor()); color.setValue(category.getColor());
containedEntries.setAll(StoreViewState.get().getAllEntries().getList().stream() directContainedEntries.setAll(StoreViewState.get().getAllEntries().getList().stream()
.filter(entry -> {
return entry.getEntry().getCategoryUuid().equals(category.getUuid());
})
.toList());
allContainedEntries.setAll(StoreViewState.get().getAllEntries().getList().stream()
.filter(entry -> { .filter(entry -> {
return entry.getEntry().getCategoryUuid().equals(category.getUuid()) return entry.getEntry().getCategoryUuid().equals(category.getUuid())
|| (AppPrefs.get() || (AppPrefs.get()

View file

@ -55,6 +55,7 @@ public class StoreViewState {
INSTANCE = new StoreViewState(); INSTANCE = new StoreViewState();
INSTANCE.updateContent(); INSTANCE.updateContent();
INSTANCE.initSections(); INSTANCE.initSections();
INSTANCE.initFilterJump();
} }
public static void reset() { public static void reset() {
@ -94,6 +95,20 @@ public class StoreViewState {
} }
} }
private void initFilterJump() {
var all = getAllConnectionsCategory();
filter.addListener((observable, oldValue, newValue) -> {
var matchingCats = categories.getList().stream().filter(storeCategoryWrapper -> storeCategoryWrapper.getRoot().equals(all))
.filter(storeCategoryWrapper -> storeCategoryWrapper.getDirectContainedEntries()
.stream()
.anyMatch(wrapper -> wrapper.matchesFilter(newValue)))
.toList();
if (matchingCats.size() == 1) {
activeCategory.setValue(matchingCats.getFirst());
}
});
}
private void initContent() { private void initContent() {
allEntries allEntries
.getList() .getList()

View file

@ -109,7 +109,7 @@ public class StoreCategoryComp extends SimpleComp {
})) }))
.styleClass("status-button"); .styleClass("status-button");
var shownList = new DerivedObservableList<>(category.getContainedEntries(), true) var shownList = new DerivedObservableList<>(category.getAllContainedEntries(), true)
.filtered( .filtered(
storeEntryWrapper -> { storeEntryWrapper -> {
return storeEntryWrapper.matchesFilter( return storeEntryWrapper.matchesFilter(
@ -117,7 +117,7 @@ public class StoreCategoryComp extends SimpleComp {
}, },
StoreViewState.get().getFilterString()) StoreViewState.get().getFilterString())
.getList(); .getList();
var count = new CountComp<>(shownList, category.getContainedEntries(), string -> "(" + string + ")"); var count = new CountComp<>(shownList, category.getAllContainedEntries(), string -> "(" + string + ")");
var showStatus = hover.or(new SimpleBooleanProperty(DataStorage.get().supportsSharing())) var showStatus = hover.or(new SimpleBooleanProperty(DataStorage.get().supportsSharing()))
.or(showing); .or(showing);