]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5314
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 15 Sep 2014 18:22:21 +0000 (18:22 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 15 Sep 2014 18:22:21 +0000 (18:22 +0000)
Optimize OpenDiagramFromComponentAdapter to speed up diagram opening when e.g. double clicking a component under configuration folder in model browser

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30282 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromComponentAdapter.java

index fb89ccc3c531824a406ff7ca4503c98a9fc770c5..20c7ab19f94cd81bc1382845debb5e5ebcc76690 100644 (file)
@@ -8,7 +8,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorPart;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.request.PossibleModel;\r
 import org.simantics.db.layer0.variable.RVI;\r
@@ -25,11 +24,9 @@ import org.simantics.modeling.ModelingResources;
 import org.simantics.modeling.actions.NavigateToTarget;\r
 import org.simantics.modeling.ui.Activator;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;\r
 import org.simantics.utils.datastructures.Callback;\r
-import org.simantics.utils.threads.SWTThread;\r
 import org.simantics.utils.threads.ThreadUtils;\r
 import org.simantics.utils.ui.AdaptionUtils;\r
 \r
@@ -40,6 +37,8 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
 \r
     private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer";\r
 \r
+    private static Collection<Runnable> rs;\r
+    \r
     public OpenDiagramFromComponentAdapter() {\r
         super("Diagram Editor", Activator.COMPOSITE_ICON);\r
     }\r
@@ -50,7 +49,7 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
         if (r == null)\r
             return false;\r
         Variable v = AdaptionUtils.adaptToSingle(input, Variable.class);\r
-        Collection<Runnable> rs = tryFindDiagram(graph, r, v);\r
+        rs = tryFindDiagram(graph, r, v);\r
         return !rs.isEmpty();\r
     }\r
 \r
@@ -79,29 +78,9 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
         if (d == null)\r
             return;\r
 \r
-        SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
-            @Override\r
-            public void run(ReadGraph graph) throws DatabaseException {\r
-                Resource r = tryGetResource(graph, input);\r
-                if (r == null)\r
-                    return;\r
-\r
-                Variable v = AdaptionUtils.adaptToSingle(input, Variable.class);\r
-\r
-                final Collection<Runnable> rs = tryFindDiagram(graph, r, v);\r
-                if (rs.isEmpty())\r
-                    return;\r
-\r
-                SWTThread.getThreadAccess(d).asyncExec(new Runnable() {\r
-                    @Override\r
-                    public void run() {\r
-                        for (Runnable runnable : rs) {\r
-                            runnable.run();\r
-                        }\r
-                    }\r
-                });\r
-            }\r
-        });\r
+        for (Runnable runnable : rs) {\r
+            runnable.run();\r
+        }\r
     }\r
 \r
     private Collection<Runnable> tryFindDiagram(ReadGraph g, Resource module, Variable variable) throws DatabaseException {\r