X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerImpl2.java;fp=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FGraphExplorerImpl2.java;h=c21158e31a65785d8a9dd5d7df728871af63a785;hp=af0fa25a355019468aecd5a89f6a6f950e69833e;hb=97e8b055b8ad16f1d799c81898fee075780a5a83;hpb=72d52b5910e1ed0141b6768ef700e7321ac05553 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java index af0fa25a3..c21158e31 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl2.java @@ -38,7 +38,6 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.layout.GridDataFactory; @@ -154,6 +153,7 @@ import org.simantics.browsing.ui.common.processors.DefaultViewpointProcessor; import org.simantics.browsing.ui.common.processors.IsExpandedProcessor; import org.simantics.browsing.ui.common.processors.NoSelectionRequestProcessor; import org.simantics.browsing.ui.common.processors.ProcessorLifecycle; +import org.simantics.browsing.ui.common.state.ExplorerStates; import org.simantics.browsing.ui.content.ImageDecorator; import org.simantics.browsing.ui.content.Imager; import org.simantics.browsing.ui.content.LabelDecorator; @@ -174,6 +174,7 @@ import org.simantics.utils.threads.SWTThread; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.AdaptionUtils; import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.SWTUtils; import org.simantics.utils.ui.jface.BasePostSelectionProvider; import gnu.trove.map.hash.THashMap; @@ -574,17 +575,16 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx private void initializeState() { if (persistor == null) return; + ExplorerStates.scheduleRead(getRoot(), persistor) + .thenAccept(state -> SWTUtils.asyncExec(viewer.getTree(), () -> restoreState(state))); + } - ExplorerState state = persistor.deserialize( - Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(), - getRoot()); - - + private void restoreState(ExplorerState state) { Object processor = getPrimitiveProcessor(BuiltinKeys.IS_EXPANDED); if (processor instanceof DefaultIsExpandedProcessor) { DefaultIsExpandedProcessor isExpandedProcessor = (DefaultIsExpandedProcessor)processor; for(NodeContext expanded : state.expandedNodes) { - isExpandedProcessor.setExpanded(expanded, true); + isExpandedProcessor.replaceExpanded(expanded, true); } } } @@ -717,13 +717,14 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx private void doSetColumns(Column[] cols, Consumer> callback) { // Attempt to keep previous column widths. - Map prevWidths = new HashMap(); - + Map prevWidths = new HashMap<>(); for (TreeViewerColumn c : treeViewerColumns) { - prevWidths.put(c.getColumn().getText(), c.getColumn().getWidth()); - c.getColumn().dispose(); + Column col = (Column) (c.getColumn().getData()); + if (col != null) + prevWidths.put(col.getKey(), c.getColumn().getWidth()); + c.getColumn().dispose(); } - + treeViewerColumns.clear(); HashMap keyToIndex = new HashMap(); @@ -765,7 +766,7 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx int cw = column.getWidth(); // Try to keep previous widths - Integer w = prevWidths.get(column); + Integer w = prevWidths.get(column.getKey()); if (w != null) c.setWidth(w); else if (cw != Column.DEFAULT_CONTROL_WIDTH) @@ -2487,11 +2488,11 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx return context == null; } - @SuppressWarnings("rawtypes") + @SuppressWarnings("unchecked") @Override - public Object getAdapter(Class adapter) { + public T getAdapter(Class adapter) { if (adapter == NodeContext.class) - return context; + return (T) context; return context.getAdapter(adapter); } @@ -2712,9 +2713,8 @@ public class GraphExplorerImpl2 extends GraphExplorerImplBase implements GraphEx * store the key, this is not used. */ NodeContext getNC = new NodeContext() { - @SuppressWarnings("rawtypes") - @Override - public Object getAdapter(Class adapter) { + @Override + public T getAdapter(Class adapter) { return null; }