mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Hook up update observables
This commit is contained in:
parent
ba7c83a1e8
commit
ae02fb3791
4 changed files with 31 additions and 12 deletions
|
@ -100,7 +100,8 @@ public class StoreSection {
|
|||
return comp.compare(o1, o2);
|
||||
}
|
||||
},
|
||||
mappedSortMode);
|
||||
mappedSortMode,
|
||||
StoreViewState.get().getEntriesOrderChangeObservable());
|
||||
}
|
||||
|
||||
public static StoreSection createTopLevel(
|
||||
|
@ -111,7 +112,8 @@ public class StoreSection {
|
|||
var topLevel = all.filtered(section -> {
|
||||
return DataStorage.get().isRootEntry(section.getEntry());
|
||||
},
|
||||
category);
|
||||
category,
|
||||
StoreViewState.get().getEntriesListChangeObservable());
|
||||
var cached = topLevel.mapped(
|
||||
storeEntryWrapper -> create(storeEntryWrapper, 1, all, entryFilter, filterString, category));
|
||||
var ordered = sorted(cached, category);
|
||||
|
@ -154,7 +156,7 @@ public class StoreSection {
|
|||
var showProvider = other.getEntry().getProvider() == null ||
|
||||
other.getEntry().getProvider().shouldShow(other);
|
||||
return isChildren && showProvider;
|
||||
}, e.getPersistentState(), e.getCache());
|
||||
}, e.getPersistentState(), e.getCache(), StoreViewState.get().getEntriesListChangeObservable());
|
||||
var cached = allChildren.mapped(
|
||||
entry1 -> create(entry1, depth + 1, all, entryFilter, filterString, category));
|
||||
var ordered = sorted(cached, category);
|
||||
|
|
|
@ -10,7 +10,6 @@ import io.xpipe.app.storage.DataStoreEntry;
|
|||
import io.xpipe.app.storage.StorageListener;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.beans.value.ObservableIntegerValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import lombok.Getter;
|
||||
|
||||
|
@ -31,7 +30,11 @@ public class StoreViewState {
|
|||
private final DerivedObservableList<StoreCategoryWrapper> categories =
|
||||
new DerivedObservableList<>(FXCollections.observableList(new CopyOnWriteArrayList<>()), true);
|
||||
|
||||
private final ObservableIntegerValue updateObservable = new SimpleIntegerProperty();
|
||||
@Getter
|
||||
private final IntegerProperty entriesOrderChangeObservable = new SimpleIntegerProperty();
|
||||
|
||||
@Getter
|
||||
private final IntegerProperty entriesListChangeObservable = new SimpleIntegerProperty();
|
||||
|
||||
@Getter
|
||||
private final Property<StoreCategoryWrapper> activeCategory = new SimpleObjectProperty<>();
|
||||
|
@ -130,6 +133,20 @@ public class StoreViewState {
|
|||
// Watch out for synchronizing all calls to the entries and categories list!
|
||||
DataStorage.get().addListener(new StorageListener() {
|
||||
|
||||
@Override
|
||||
public void onStoreOrderUpdate() {
|
||||
Platform.runLater(() -> {
|
||||
entriesOrderChangeObservable.set(entriesOrderChangeObservable.get() + 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoreListUpdate() {
|
||||
Platform.runLater(() -> {
|
||||
entriesListChangeObservable.set(entriesListChangeObservable.get() + 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoreAdd(DataStoreEntry... entry) {
|
||||
var l = Arrays.stream(entry)
|
||||
|
|
|
@ -328,20 +328,16 @@ public abstract class DataStorage {
|
|||
return;
|
||||
}
|
||||
|
||||
var children = getDeepStoreChildren(entry);
|
||||
entry.setCategoryUuid(newCategory.getUuid());
|
||||
var children = getDeepStoreChildren(entry);
|
||||
children.forEach(child -> child.setCategoryUuid(newCategory.getUuid()));
|
||||
listeners.forEach(storageListener -> storageListener.onStoreListUpdate());
|
||||
saveAsync();
|
||||
}
|
||||
|
||||
public void orderBefore(DataStoreEntry entry, DataStoreEntry reference) {
|
||||
var children = getDeepStoreChildren(entry);
|
||||
var arr = Stream.concat(Stream.of(entry), children.stream()).toArray(DataStoreEntry[]::new);
|
||||
listeners.forEach(storageListener -> storageListener.onStoreRemove(arr));
|
||||
|
||||
entry.setOrderBefore(reference != null ? reference.getUuid() : null);
|
||||
|
||||
listeners.forEach(storageListener -> storageListener.onStoreAdd(arr));
|
||||
listeners.forEach(storageListener -> storageListener.onStoreOrderUpdate());
|
||||
}
|
||||
|
||||
public boolean refreshChildren(DataStoreEntry e) {
|
||||
|
|
|
@ -2,6 +2,10 @@ package io.xpipe.app.storage;
|
|||
|
||||
public interface StorageListener {
|
||||
|
||||
void onStoreOrderUpdate();
|
||||
|
||||
void onStoreListUpdate();
|
||||
|
||||
void onStoreAdd(DataStoreEntry... entry);
|
||||
|
||||
void onStoreRemove(DataStoreEntry... entry);
|
||||
|
|
Loading…
Reference in a new issue