]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17791 ac1ea38d-2e2b...
authorjplaine <jplaine@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 3 Sep 2010 09:45:59 +0000 (09:45 +0000)
committerjplaine <jplaine@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 3 Sep 2010 09:45:59 +0000 (09:45 +0000)
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/OpenDiagramFromConfigurationAdapter.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryVariable.java

index e82c0b6b3988f06c772876ca4504940b97c73341..854a3410a5d38726719d918b68e0a29159c7aaf5 100644 (file)
@@ -1,32 +1,38 @@
 package org.simantics.sysdyn.ui.editor;\r
 \r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.PlatformUI;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.common.ResourceArray;\r
+import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ComponentUtils;\r
 import org.simantics.modeling.ModelingResources;\r
+import org.simantics.modeling.ui.Activator;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.structural2.StructuralVariables;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.workbench.ResourceEditorInput2;\r
+import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
 \r
-\r
-public class OpenDiagramFromConfigurationAdapter extends org.simantics.modeling.ui.diagramEditor.OpenDiagramFromConfigurationAdapter {\r
+public class OpenDiagramFromConfigurationAdapter extends AbstractResourceEditorAdapter {\r
 \r
        private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer";\r
 \r
-       public OpenDiagramFromConfigurationAdapter() {\r
-               super();\r
-       }\r
+    public OpenDiagramFromConfigurationAdapter() {\r
+        super("Diagram Editor", Activator.COMPOSITE_ICON);\r
+    }\r
 \r
-       @Override\r
-       protected String getEditorId() {\r
-               return EDITOR_ID;\r
-       }\r
+    protected String getEditorId() {\r
+        return EDITOR_ID;\r
+    }\r
 \r
-       @Override\r
-       public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {\r
+    @Override\r
+    public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {\r
                SysdynResource sr = SysdynResource.getInstance(g);\r
                if(g.isInheritedFrom(r, sr.ModuleSymbol)) {\r
                        ModelingResources mr = ModelingResources.getInstance(g);\r
@@ -42,41 +48,62 @@ public class OpenDiagramFromConfigurationAdapter extends org.simantics.modeling.
                        }\r
                }\r
                return ComponentUtils.compositeHasDiagram(g, r) /*|| ComponentUtils.componentHasDiagram(g, r)*/;\r
-       }\r
-\r
-       @Override\r
-       public void openEditor(final Resource r) throws Exception {\r
-               Resource configuration = null;\r
-               try {\r
-                       configuration = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
-\r
-                               @Override\r
-                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
-                                       Layer0 l0 = Layer0.getInstance(graph);\r
-                                       if(graph.isInheritedFrom(r, SysdynResource.getInstance(graph).ModuleSymbol)) {\r
-                                               ModelingResources mr = ModelingResources.getInstance(graph);\r
-                                               StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
-                                               Resource componentType = graph.getSingleObject(r, mr.SymbolToComponentType);\r
-                                               Resource configuration = graph.getSingleObject(componentType, sr2.IsDefinedBy);\r
-                                               return configuration;\r
-                                       } else {     \r
-                                               Resource represents = graph.getPossibleObject(r, l0.Represents);\r
-                                               if(represents != null && graph.isInstanceOf(represents, SysdynResource.getInstance(graph).Configuration)){\r
-                                                       return represents;\r
-                                               }\r
-                                               else {\r
-                                                       return null;\r
-                                               }\r
+    }\r
+\r
+    @Override\r
+    public void openEditor(final Resource r) throws Exception {\r
+\r
+        SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+\r
+            @Override\r
+            public void run(ReadGraph g) throws DatabaseException {\r
+               Resource cr = r;\r
+                               Layer0 l0 = Layer0.getInstance(g);\r
+                               if(g.isInheritedFrom(r, SysdynResource.getInstance(g).ModuleSymbol)) {\r
+                                       ModelingResources mr = ModelingResources.getInstance(g);\r
+                                       StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
+                                       Resource componentType = g.getSingleObject(r, mr.SymbolToComponentType);\r
+                                       Resource configuration = g.getSingleObject(componentType, sr2.IsDefinedBy);\r
+                                       cr = configuration;\r
+                               } else {     \r
+                                       Resource represents = g.getPossibleObject(r, l0.Represents);\r
+                                       if(represents != null && g.isInstanceOf(represents, SysdynResource.getInstance(g).Configuration)){\r
+                                               cr = represents;\r
+                                       } else {\r
+                                               cr = r;\r
                                        }\r
                                }\r
-                       });\r
-               } catch (DatabaseException e1) {\r
-                       e1.printStackTrace();\r
-               }\r
-               if (configuration != null)\r
-                       super.openEditor(configuration);\r
-               else\r
-                       super.openEditor(r);\r
-       }\r
 \r
+               \r
+                final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(g, r);\r
+                if(diagram == null) return;\r
+                final ResourceArray compositePath = StructuralVariables.getCompositeArray(g, r);\r
+                final ResourceArray variablePath = compositePath.removeFromBeginning(1);\r
+\r
+                Resource model = StructuralVariables.getModel(g, compositePath.head());\r
+                if(model == null) return;\r
+                final String modelURI = g.getURI(model);\r
+\r
+                final String rvi = StructuralVariables.getRVI(g, variablePath);\r
+                if(rvi == null) return;\r
+\r
+                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+                    @Override\r
+                    public void run() {\r
+                        try {\r
+                            String editorId = getEditorId();\r
+//                            System.out.println("Activating diagram: model=" + modelURI + " rvi='" + rvi + "'");\r
+                            WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, diagram, modelURI, rvi));\r
+                        } catch (PartInitException e) {\r
+                            // TODO Auto-generated catch block\r
+                            e.printStackTrace();\r
+                        }\r
+                    }\r
+                });\r
+\r
+            }\r
+\r
+        });\r
+\r
+    }\r
 }\r
index d0054c041458d904deb44c3c1e695c1491d03d80..427b19393deadc4525b32e87827cec7131f517b5 100644 (file)
@@ -65,7 +65,8 @@ public class HistoryVariable extends ResourceVariable {
                        System.out.println("HistoryVariable rvi='" + tmp + "'");\r
                        final String rvi = tmp.substring(1).replace("/", ".");\r
                        SysdynDataSet ds = sr.getDataSet(rvi);\r
-                       assert(ds != null);\r
+                       if(ds == null) return null;\r
+//                     assert(ds != null);\r
                        try {\r
                                final RecordAccessor ac = (RecordAccessor)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds);\r
                                \r