]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5314
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Sep 2014 07:10:13 +0000 (07:10 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 16 Sep 2014 07:10:13 +0000 (07:10 +0000)
Modify the OpenDiagramFromComponentAdapter optimizations to obey the EditorAdapter API rules (don't cache the runnables between canHandle and openEditor)

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

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

index 20c7ab19f94cd81bc1382845debb5e5ebcc76690..1ff6f174eb24a5e4a00c95abe59a83ae356bde8f 100644 (file)
@@ -6,8 +6,10 @@ import java.util.Collections;
 \r
 import org.eclipse.swt.widgets.Display;\r
 import org.eclipse.ui.IEditorPart;\r
+import org.simantics.Simantics;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.UnaryRead;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.request.PossibleModel;\r
 import org.simantics.db.layer0.variable.RVI;\r
@@ -37,19 +39,13 @@ 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
 \r
     @Override\r
     public boolean canHandle(ReadGraph graph, Object input) throws DatabaseException {\r
-        Resource r = tryGetResource(graph, input);\r
-        if (r == null)\r
-            return false;\r
-        Variable v = AdaptionUtils.adaptToSingle(input, Variable.class);\r
-        rs = tryFindDiagram(graph, r, v);\r
+        Collection<Runnable> rs = graph.syncRequest(new DiagramFinderRequest(input));\r
         return !rs.isEmpty();\r
     }\r
 \r
@@ -77,7 +73,8 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
         final Display d = Display.getCurrent();\r
         if (d == null)\r
             return;\r
-\r
+        \r
+        Collection<Runnable> rs = Simantics.getSession().syncRequest(new DiagramFinderRequest(input));\r
         for (Runnable runnable : rs) {\r
             runnable.run();\r
         }\r
@@ -179,5 +176,21 @@ public class OpenDiagramFromComponentAdapter extends AbstractResourceEditorAdapt
         }\r
         return selectedObjects;\r
     }\r
+    \r
+    private class DiagramFinderRequest extends UnaryRead<Object, Collection<Runnable>> {\r
+\r
+        public DiagramFinderRequest(Object parameter) {\r
+            super(parameter);\r
+        }\r
+\r
+        @Override\r
+        public Collection<Runnable> perform(ReadGraph graph) throws DatabaseException {\r
+            Resource r = tryGetResource(graph, parameter);\r
+            if (r == null)\r
+                return Collections.emptyList();\r
+            Variable v = AdaptionUtils.adaptToSingle(parameter, Variable.class);\r
+            return tryFindDiagram(graph, r, v);\r
+        }\r
+    }\r
 \r
 }\r