]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerImpl.java
UI locking fixes for GraphExplorer implementations
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / GraphExplorerImpl.java
index 3cf5f7478cd7af3dc23ff412db75eac0628f87c1..df736c1e6dc2603315bea23f47b46a2170a52f55 100644 (file)
@@ -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<Map<Column, Object>> callback) {
         // Attempt to keep previous column widths.
-        Map<String, Integer> prevWidths = new HashMap<String, Integer>();
+        Map<String, Integer> 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<String, Integer> keyToIndex = new HashMap<String, Integer>();
+        HashMap<String, Integer> 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<Column, Object> map = new HashMap<Column, Object>();
+        Map<Column, Object> 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();
-            }
         });
     }