X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.common%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fcommon%2Fstate%2FExplorerStates.java;fp=bundles%2Forg.simantics.browsing.ui.common%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fcommon%2Fstate%2FExplorerStates.java;h=380968bed8c8c31852216353d1bbcc0e313c13e4;hp=0000000000000000000000000000000000000000;hb=97e8b055b8ad16f1d799c81898fee075780a5a83;hpb=72d52b5910e1ed0141b6768ef700e7321ac05553 diff --git a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/state/ExplorerStates.java b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/state/ExplorerStates.java new file mode 100644 index 000000000..380968bed --- /dev/null +++ b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/state/ExplorerStates.java @@ -0,0 +1,60 @@ +package org.simantics.browsing.ui.common.state; + +import java.io.File; +import java.util.concurrent.CompletableFuture; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.simantics.DatabaseJob; +import org.simantics.browsing.ui.ExplorerState; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.StatePersistor; +import org.simantics.browsing.ui.common.Activator; + +/** + * @author Tuukka Lehtonen + * @since 1.36.0 + */ +public class ExplorerStates { + + public static File explorerStateLocation() { + return Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(); + } + + public static CompletableFuture scheduleRead(NodeContext root, StatePersistor persistor) { + CompletableFuture result = new CompletableFuture<>(); + new ReaderJob(root, persistor, result).schedule(); + return result; + } + + private static class ReaderJob extends DatabaseJob { + + private NodeContext root; + private StatePersistor persistor; + private CompletableFuture consumer; + + public ReaderJob(NodeContext root, StatePersistor persistor, CompletableFuture consumer) { + super("Reading previous graph explorer state"); + this.root = root; + this.persistor = persistor; + this.consumer = consumer; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + monitor.beginTask("Loading persisted data", 1); + ExplorerState state = persistor.deserialize(explorerStateLocation(), root); + monitor.worked(1); + consumer.complete(state); + return Status.OK_STATUS; + } finally { + monitor.done(); + } + } + + } + +}