Fix store editing and state handling

This commit is contained in:
crschnick 2024-07-31 22:41:20 +00:00
parent 734d4fdff8
commit 111c62da52
5 changed files with 13 additions and 4 deletions

View file

@ -170,7 +170,12 @@ public class StoreCreationComp extends DialogComp {
if (!DataStorage.get().getStoreEntries().contains(e)) {
DataStorage.get().addStoreEntryIfNotPresent(newE);
} else {
DataStorage.get().updateEntry(e, newE);
// We didn't change anything
if (e.getStore().equals(newE.getStore())) {
e.setName(newE.getName());
} else {
DataStorage.get().updateEntry(e, newE);
}
}
});
},

View file

@ -11,7 +11,7 @@ public interface EnabledStoreProvider extends DataStoreProvider {
@Override
default StoreEntryComp customEntryComp(StoreSection sec, boolean preferLarge) {
if (sec.getWrapper().getValidity().getValue() != DataStoreEntry.Validity.COMPLETE) {
if (sec.getWrapper().getValidity().getValue() == DataStoreEntry.Validity.LOAD_FAILED) {
return StoreEntryComp.create(sec, null, preferLarge);
}

View file

@ -53,7 +53,7 @@ public class DataStoreListChoiceComp<T extends DataStore> extends SimpleComp {
});
return new HorizontalComp(List.of(label, Comp.hspacer(), delete)).styleClass("entry");
},
true)
false)
.padding(new Insets(0))
.apply(struc -> struc.get().setMinHeight(0))
.apply(struc -> ((VBox) struc.get().getContent()).setSpacing(5));

View file

@ -273,6 +273,10 @@ public abstract class DataStorage {
}
public void updateEntry(DataStoreEntry entry, DataStoreEntry newEntry) {
var state = entry.getStorePersistentState();
var newState = state.mergeCopy(newEntry.getStorePersistentState());
newEntry.setStorePersistentState(newState);
var oldParent = DataStorage.get().getDefaultDisplayParent(entry);
var newParent = DataStorage.get().getDefaultDisplayParent(newEntry);
var sameParent = Objects.equals(oldParent, newParent);

View file

@ -19,6 +19,6 @@ public class EnabledStoreState extends DataStoreState {
@Override
public DataStoreState mergeCopy(DataStoreState newer) {
var n = (EnabledStoreState) newer;
return EnabledStoreState.builder().enabled(n.enabled).build();
return EnabledStoreState.builder().enabled(enabled || n.enabled).build();
}
}