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%2FGraphExplorerImpl.java;h=df736c1e6dc2603315bea23f47b46a2170a52f55;hp=3cf5f7478cd7af3dc23ff412db75eac0628f87c1;hb=97e8b055b8ad16f1d799c81898fee075780a5a83;hpb=72d52b5910e1ed0141b6768ef700e7321ac05553 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java index 3cf5f7478..df736c1e6 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java @@ -39,7 +39,6 @@ import org.eclipse.core.runtime.AssertionFailedException; 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.action.IStatusLineManager; @@ -145,6 +144,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; @@ -169,6 +169,7 @@ import org.simantics.utils.threads.IThreadWorkQueue; import org.simantics.utils.threads.SWTThread; import org.simantics.utils.threads.ThreadUtils; import org.simantics.utils.ui.ISelectionUtils; +import org.simantics.utils.ui.SWTUtils; import org.simantics.utils.ui.jface.BasePostSelectionProvider; import org.simantics.utils.ui.widgets.VetoingEventHandler; import org.simantics.utils.ui.workbench.WorkbenchUtils; @@ -1883,15 +1884,15 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph }); } } - + private void initializeState() { if (persistor == null) return; + ExplorerStates.scheduleRead(getRoot(), persistor) + .thenAccept(state -> SWTUtils.asyncExec(tree, () -> restoreState(state))); + } - ExplorerState state = persistor.deserialize( - Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(), - getRoot()); - + private void restoreState(ExplorerState state) { // topNodeToSet will be processed by #setData when it encounters a // NodeContext that matches this one. // topNodePath = state.topNodePath; @@ -1902,7 +1903,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph if (processor instanceof DefaultIsExpandedProcessor) { DefaultIsExpandedProcessor isExpandedProcessor = (DefaultIsExpandedProcessor)processor; for(NodeContext expanded : state.expandedNodes) { - isExpandedProcessor.setExpanded(expanded, true); + isExpandedProcessor.replaceExpanded(expanded, true); } } } @@ -1947,7 +1948,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph } persistor.serialize( - Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(), + ExplorerStates.explorerStateLocation(), getRoot(), new ExplorerState(topNodePath, topNodePathChildIndex, expandedNodes, columnWidths)); } @@ -3251,13 +3252,16 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph */ private void doSetColumns(Column[] cols, Consumer> callback) { // Attempt to keep previous column widths. - Map prevWidths = new HashMap(); + Map prevWidths = new HashMap<>(); for (TreeColumn column : tree.getColumns()) { - prevWidths.put(column.getText(), column.getWidth()); - column.dispose(); + Column c = (Column) column.getData(); + if (c != null) { + prevWidths.put(c.getKey(), column.getWidth()); + column.dispose(); + } } - HashMap keyToIndex = new HashMap(); + HashMap keyToIndex = new HashMap<>(); for (int i = 0; i < cols.length; ++i) { keyToIndex.put(cols[i].getKey(), i); } @@ -3268,7 +3272,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph this.columnImageArray = new Image[cols.length]; this.columnDescOrImageArray = new Object[cols.length]; - Map map = new HashMap(); + Map map = new HashMap<>(); tree.setHeaderVisible(columnsAreVisible); for (Column column : columns) { @@ -3281,7 +3285,7 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph 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) @@ -3306,13 +3310,9 @@ class GraphExplorerImpl extends GraphExplorerImplBase implements Listener, Graph if(callback != null) callback.accept(map); // Make sure the explorer fits the columns properly after initialization. - tree.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (tree.isDisposed()) - return; + SWTUtils.asyncExec(tree, () -> { + if (!tree.isDisposed()) refreshColumnSizes(); - } }); }