Improve view state initialization

This commit is contained in:
crschnick 2023-10-23 19:40:13 +00:00
parent d1c2cc27af
commit 656be93d44
3 changed files with 20 additions and 28 deletions

View file

@ -43,14 +43,13 @@ public class StoreCategoryWrapper {
this.root = last;
this.category = category;
this.name = new SimpleStringProperty();
this.lastAccess = new SimpleObjectProperty<>();
this.sortMode = new SimpleObjectProperty<>();
this.share = new SimpleObjectProperty<>();
this.name = new SimpleStringProperty(category.getName());
this.lastAccess = new SimpleObjectProperty<>(category.getLastAccess());
this.sortMode = new SimpleObjectProperty<>(category.getSortMode());
this.share = new SimpleObjectProperty<>(category.isShare());
this.children = FXCollections.observableArrayList();
this.containedEntries = FXCollections.observableArrayList();
setupListeners();
update();
}
public StoreCategoryWrapper getRoot() {
@ -117,20 +116,18 @@ public class StoreCategoryWrapper {
sortMode.setValue(category.getSortMode());
share.setValue(category.isShare());
if (StoreViewState.get() != null) {
containedEntries.setAll(StoreViewState.get().getAllEntries().stream()
.filter(entry -> contains(entry.getEntry()))
.toList());
children.setAll(StoreViewState.get().getCategories().stream()
.filter(storeCategoryWrapper -> getCategory()
.getUuid()
.equals(storeCategoryWrapper.getCategory().getParentCategory()))
.toList());
Optional.ofNullable(getParent())
.ifPresent(storeCategoryWrapper -> {
storeCategoryWrapper.update();
});
}
containedEntries.setAll(StoreViewState.get().getAllEntries().stream()
.filter(entry -> contains(entry.getEntry()))
.toList());
children.setAll(StoreViewState.get().getCategories().stream()
.filter(storeCategoryWrapper -> getCategory()
.getUuid()
.equals(storeCategoryWrapper.getCategory().getParentCategory()))
.toList());
Optional.ofNullable(getParent())
.ifPresent(storeCategoryWrapper -> {
storeCategoryWrapper.update();
});
}
public String getName() {

View file

@ -61,7 +61,6 @@ public class StoreEntryWrapper {
});
this.defaultActionProvider = new SimpleObjectProperty<>();
setupListeners();
update();
}
public void moveTo(DataStoreCategory category) {
@ -136,9 +135,7 @@ public class StoreEntryWrapper {
deletable.setValue(entry.getConfiguration().isDeletable()
|| AppPrefs.get().developerDisableGuiRestrictions().getValue());
if (StoreViewState.get() != null) {
category.setValue(StoreViewState.get().getCategoryWrapper(DataStorage.get().getStoreCategoryIfPresent(entry.getCategoryUuid()).orElseThrow()));
}
category.setValue(StoreViewState.get().getCategoryWrapper(DataStorage.get().getStoreCategoryIfPresent(entry.getCategoryUuid()).orElseThrow()));
actionProviders.keySet().forEach(dataStoreActionProvider -> {
if (!isInStorage()) {

View file

@ -131,7 +131,9 @@ public class StoreViewState {
return;
}
new StoreViewState();
INSTANCE = new StoreViewState();
INSTANCE.categories.forEach(storeCategoryWrapper -> storeCategoryWrapper.update());
INSTANCE.allEntries.forEach(storeCategoryWrapper -> storeCategoryWrapper.update());
}
public static void reset() {
@ -173,10 +175,6 @@ public class StoreViewState {
storeCategoryWrapper.getCategory().getUuid().equals(DataStorage.DEFAULT_CATEGORY_UUID))
.findFirst()
.orElseThrow()));
INSTANCE = this;
categories.forEach(storeCategoryWrapper -> storeCategoryWrapper.update());
allEntries.forEach(storeCategoryWrapper -> storeCategoryWrapper.update());
}
private void addStorageListeners() {