]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Model browser enter and double-click handling
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 7 Oct 2010 12:13:44 +0000 (12:13 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 7 Oct 2010 12:13:44 +0000 (12:13 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18300 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/InputLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/VariableLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/ModuleNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/VariableNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java

index 9fdc3437f9cc3d6b7ebf818d3c515ceb09cc50ab..bcde8c4b1639a526aa2173fe6b4fae3396bcc069 100644 (file)
             label="System Dynamics ontology dependencies">\r
       </feature>\r
    </extension>\r
+   <extension\r
+         point="org.simantics.ui.doubleClick">\r
+      <doubleClickAction\r
+            class="org.simantics.sysdyn.ui.actions.ActivateExperimentAction"\r
+            name="Activate Sysdyn Experiment">\r
+      </doubleClickAction>\r
+      <doubleClickAction\r
+            class="org.simantics.sysdyn.ui.actions.ConsumeUnnecessaryEntersAction"\r
+            name="Consume unnecessary enters">\r
+      </doubleClickAction>\r
+      <doubleClickAction\r
+            class="org.simantics.sysdyn.ui.actions.ShowInstantiatedModuleAction">\r
+      </doubleClickAction>\r
+   </extension>\r
 </plugin>\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ActivateExperimentAction.java
new file mode 100644 (file)
index 0000000..6cd5168
--- /dev/null
@@ -0,0 +1,48 @@
+package org.simantics.sysdyn.ui.actions;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.project.IProject;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator;\r
+import org.simantics.ui.DoubleClickEvent;\r
+import org.simantics.ui.IDoubleClickAction;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+import org.simantics.utils.ui.action.PriorityAction;\r
+\r
+public class ActivateExperimentAction implements IDoubleClickAction {\r
+\r
+       @Override\r
+       public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {\r
+        ReadGraph g = e.getGraph();\r
+        final Resource experiment = ResourceAdaptionUtils.toSingleResource(e.getResource());\r
+        if (experiment == null)\r
+            return;\r
+\r
+        if (g.isInstanceOf(experiment, SimulationResource.getInstance(g).Experiment)) {\r
+            final IProject project = SimanticsUI.getProject();\r
+            if (project == null)\r
+                return;\r
+\r
+            final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+            if (experimentManager == null) {\r
+                ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception());\r
+                return;\r
+            }\r
+\r
+            e.add(new PriorityAction(PriorityAction.HIGH+20) {\r
+                @Override\r
+                public void run() {\r
+                       SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, experiment);\r
+                }\r
+            });\r
+            e.consume();\r
+        }\r
+               \r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConsumeUnnecessaryEntersAction.java
new file mode 100644 (file)
index 0000000..cff7e26
--- /dev/null
@@ -0,0 +1,44 @@
+package org.simantics.sysdyn.ui.actions;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.DoubleClickEvent;\r
+import org.simantics.ui.IDoubleClickAction;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.ui.action.PriorityAction;\r
+\r
+public class ConsumeUnnecessaryEntersAction implements IDoubleClickAction {\r
+\r
+       @Override\r
+       public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {\r
+        ReadGraph g = e.getGraph();\r
+        Layer0 l0 = Layer0.getInstance(g);\r
+        final Resource resource = ResourceAdaptionUtils.toSingleResource(e.getResource());\r
+        if(resource == null)\r
+               return;\r
+               SysdynResource sr = SysdynResource.getInstance(g);\r
+               \r
+               if(g.isInstanceOf(resource, sr.SysdynModel) || g.isInstanceOf(resource, sr.Variable)) {\r
+                       consume(e);\r
+               } else if(g.hasStatement(resource, l0.Represents)){\r
+                       Resource represents = g.getSingleObject(resource, l0.Represents);       \r
+                       if (g.isInstanceOf(represents, sr.Variable)) {\r
+                               consume(e);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private void consume(DoubleClickEvent e) {\r
+        e.add(new PriorityAction(PriorityAction.HIGH) {\r
+            @Override\r
+            public void run() {\r
+               \r
+            }\r
+        });\r
+               e.consume();\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ShowInstantiatedModuleAction.java
new file mode 100644 (file)
index 0000000..b3c8d6c
--- /dev/null
@@ -0,0 +1,94 @@
+package org.simantics.sysdyn.ui.actions;\r
+\r
+import java.util.Set;\r
+\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.ui.PartInitException;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.BrowserSelection;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
+import org.simantics.ui.DoubleClickEvent;\r
+import org.simantics.ui.IDoubleClickAction;\r
+import org.simantics.ui.workbench.ResourceEditorInput2;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+import org.simantics.utils.ui.action.PriorityAction;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+public class ShowInstantiatedModuleAction implements IDoubleClickAction {\r
+\r
+    private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer";\r
+    \r
+       @Override\r
+       public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException {\r
+               \r
+        ReadGraph g = e.getGraph();\r
+        \r
+        if(e.getResource() instanceof IStructuredSelection) {\r
+                       Set<BrowserSelection> bss = ISelectionUtils.filterSetSelection(e.getResource(), BrowserSelection.class);\r
+                       \r
+                       if(!bss.isEmpty()) {\r
+                               Layer0 l0 = Layer0.getInstance(g);\r
+                               for(BrowserSelection bs : bss) {\r
+                                       Resource instanceOf = g.getSingleObject((Resource)bs.getAdapter(Resource.class), l0.InstanceOf);\r
+                                       SysdynResource sr = SysdynResource.getInstance(g);\r
+                                       if(g.isInheritedFrom(instanceOf, sr.Module)) {\r
+                                               StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
+                                               Resource conf = g.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
+                                               addShowModuleAction(e, getResourceEditorInput(g, bs.getModel(), conf, bs.getURI()));\r
+                                       }\r
+                               }\r
+                       } else {\r
+                               ModuleNode moduleNode = ISelectionUtils.filterSingleSelection(e.getResource(), ModuleNode.class);\r
+                               if(moduleNode != null) {\r
+                                       Layer0 l0 = Layer0.getInstance(g);\r
+                                       StructuralResource2 sr2 = StructuralResource2.getInstance(g);\r
+                               String rvi = moduleNode.getURI(g);\r
+                               Resource instanceOf = g.getSingleObject(moduleNode.getResource() != null ? moduleNode.getResource() : moduleNode.data, l0.InstanceOf);\r
+                                       Resource conf = g.getSingleObject(instanceOf, sr2.IsDefinedBy);\r
+                                       addShowModuleAction(e, getResourceEditorInput(g, moduleNode.getModel(), conf, rvi));\r
+                       }\r
+                       }\r
+        } \r
+       }\r
+       \r
+       private ResourceEditorInput2 getResourceEditorInput(ReadGraph g, Resource model, Resource configuration, String rvi) throws DatabaseException {\r
+               Layer0 l0 = Layer0.getInstance(g);\r
+               SysdynResource sr = SysdynResource.getInstance(g);\r
+               \r
+               String modelURI;\r
+               if(model != null) {\r
+                       modelURI = g.getURI(model);\r
+               } else {\r
+                       Resource parent = configuration;\r
+                       do {\r
+                               parent = g.getPossibleObject(parent, l0.PartOf);\r
+                       } while (parent != null && !g.isInstanceOf(parent, sr.SysdynModel));\r
+                       modelURI = g.getURI(parent);\r
+                       rvi = null;\r
+               }\r
+               \r
+               Resource diagram = g.getSingleObject(configuration, ModelingResources.getInstance(g).CompositeToDiagram);\r
+               return new ResourceEditorInput2(EDITOR_ID, diagram, modelURI, rvi == null ? "" : "/" + rvi);\r
+       }\r
+       \r
+       private void addShowModuleAction(DoubleClickEvent e, final ResourceEditorInput2 editorInput) {\r
+        e.add(new PriorityAction(PriorityAction.HIGH) {\r
+            @Override\r
+            public void run() {\r
+               try {\r
+                                       WorkbenchUtils.openEditor(EDITOR_ID, editorInput);\r
+                               } catch (PartInitException e) {\r
+                                       e.printStackTrace();\r
+                               }\r
+            }\r
+        });\r
+               e.consume();\r
+       }\r
+\r
+}\r
index 286f57cbd72e167ef267e31cd656e846558eea89..b2d10d611683e01b620fe5650da71bced3b40dd8 100644 (file)
@@ -16,12 +16,14 @@ public class InputLabeler extends LabelerContributor<InputNode>{
         StringBuilder sb = new StringBuilder();\r
         for(Resource r : graph.getObjects(varres, l0.HasName))\r
             sb.append(graph.getValue(r));\r
-        sb.append(" : ");\r
-        Resource represents = graph.getPossibleObject(varres, l0.Represents);\r
-        if(represents == null) return sb.toString();\r
-        for(Resource t : graph.getObjects(represents, l0.InstanceOf))\r
-            for(Resource r : graph.getObjects(t, l0.HasName))\r
-                sb.append(graph.getValue(r));\r
+               if(graph.isInstanceOf(varres, l0.Realization)) {\r
+                       varres = graph.getPossibleObject(varres, l0.Represents);\r
+                       if(varres == null) return sb.toString();\r
+               }\r
+               sb.append(" : ");\r
+               for(Resource t : graph.getObjects(varres, l0.InstanceOf))\r
+                       for(Resource r : graph.getObjects(t, l0.HasName))\r
+                               sb.append(graph.getValue(r));\r
         return sb.toString();\r
     }\r
 \r
index 51f47eae36fae66d3fe9cf0da27b5d60162d7709..94cedeb8613d1cc9d6cceb2bfd8e5b633e81e9dc 100644 (file)
@@ -27,12 +27,14 @@ public class ModuleLabeler  extends LabelerContributor<ModuleNode>{
         StringBuilder sb = new StringBuilder();\r
         for(Resource r : graph.getObjects(resource, l0.HasName))\r
             sb.append(graph.getValue(r));\r
-        sb.append(" : ");\r
-        Resource represents = graph.getPossibleObject(resource, l0.Represents);\r
-        if(represents == null) return sb.toString();\r
-        for(Resource t : graph.getObjects(represents, l0.InstanceOf))\r
-            for(Resource r : graph.getObjects(t, l0.HasName))\r
-                sb.append(graph.getValue(r));\r
+               if(graph.isInstanceOf(resource, l0.Realization)) {\r
+                       resource = graph.getPossibleObject(resource, l0.Represents);\r
+                       if(resource == null) return sb.toString();\r
+               }\r
+               sb.append(" : ");\r
+               for(Resource t : graph.getObjects(resource, l0.InstanceOf))\r
+                       for(Resource r : graph.getObjects(t, l0.HasName))\r
+                               sb.append(graph.getValue(r));\r
         return sb.toString();\r
     }\r
 \r
index ac92c4b916c8f6a349600b244e2c76a6f463c27f..a75cfe49e7bed205f392f1115c8bdadd20306098 100644 (file)
@@ -20,20 +20,22 @@ import org.simantics.sysdyn.ui.browser.nodes.VariableNode;
 \r
 public class VariableLabeler  extends LabelerContributor<VariableNode<Resource>>{\r
 \r
-    @Override\r
-    public String getLabel(ReadGraph graph, VariableNode<Resource> var) throws DatabaseException {\r
-       Layer0 l0 = Layer0.getInstance(graph);\r
-        Resource varres = var.data;\r
-        StringBuilder sb = new StringBuilder();\r
-        for(Resource r : graph.getObjects(varres, l0.HasName))\r
-            sb.append(graph.getValue(r));\r
-        sb.append(" : ");\r
-        Resource represents = graph.getPossibleObject(varres, l0.Represents);\r
-        if(represents == null) return sb.toString();\r
-        for(Resource t : graph.getObjects(represents, l0.InstanceOf))\r
-            for(Resource r : graph.getObjects(t, l0.HasName))\r
-                sb.append(graph.getValue(r));\r
-        return sb.toString();\r
-    }\r
+       @Override\r
+       public String getLabel(ReadGraph graph, VariableNode<Resource> var) throws DatabaseException {\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               Resource varres = var.data;\r
+               StringBuilder sb = new StringBuilder();\r
+               for(Resource r : graph.getObjects(varres, l0.HasName))\r
+                       sb.append(graph.getValue(r));\r
+               if(graph.isInstanceOf(varres, l0.Realization)) {\r
+                       varres = graph.getPossibleObject(varres, l0.Represents);\r
+                       if(varres == null) return sb.toString();\r
+               }\r
+               sb.append(" : ");\r
+               for(Resource t : graph.getObjects(varres, l0.InstanceOf))\r
+                       for(Resource r : graph.getObjects(t, l0.HasName))\r
+                               sb.append(graph.getValue(r));\r
+               return sb.toString();\r
+       }\r
 \r
 }\r
index db67c36b345b0013cb8dd45c2d4142f99ab6f4ed..00117ddca9356bbe5fd1484da651784741d10388 100644 (file)
@@ -1,16 +1,10 @@
 package org.simantics.sysdyn.ui.browser.nodes;\r
 \r
-import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
 import org.simantics.db.Resource;\r
 \r
-public class ModuleNode extends ConfigurationNode<Resource> implements IDoubleClickableNode {\r
+public class ModuleNode extends ConfigurationNode<Resource> {\r
 \r
     public ModuleNode(Resource resource) {\r
         super(resource);\r
     }\r
-\r
-       @Override\r
-       public boolean handleDoubleClick() {\r
-               return true;\r
-       }\r
 }\r
index ce7b2d7785b335d0c863d7886c3be1d2fa378348..4d5b141de50506ea46c554276dd27fd2c5875b1d 100644 (file)
@@ -66,23 +66,7 @@ public class VariableNode<T> extends AbstractNode<Resource> {
 \r
                                @Override\r
                                public String perform(ReadGraph graph) throws DatabaseException {\r
-                                       Layer0 l0 = Layer0.getInstance(graph);\r
-                                       SysdynResource sr = SysdynResource.getInstance(graph);\r
-                                       String uri = getName(graph);\r
-                                       \r
-                                       // don't search for a parent if the resource is not part of a realization\r
-                                       if(!graph.isInheritedFrom(graph.getSingleObject(data, l0.InstanceOf), l0.Realization))\r
-                                               return "NOT PART OF REALIZATION";\r
-                                       \r
-                                       // search for the model parent and build the uri\r
-                                       Resource parent = graph.getSingleObject(data, l0.PartOf);\r
-                                       while (!graph.isInstanceOf(parent, sr.SysdynModel)) {\r
-                                               uri = graph.getRelatedValue(parent, l0.HasName) + "/" + uri;\r
-                                               parent = graph.getSingleObject(parent, l0.PartOf);\r
-                                       }\r
-                                       // cut out the realization name\r
-                                       uri = uri.substring(uri.indexOf("/") + 1);\r
-                                       return uri;\r
+                                       return getURI(graph);\r
                                }\r
                                \r
                        });\r
@@ -91,6 +75,26 @@ public class VariableNode<T> extends AbstractNode<Resource> {
                }\r
                return null;\r
        }\r
+       \r
+       public  String getURI(ReadGraph graph) throws DatabaseException {\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               String uri = getName(graph);\r
+               \r
+               // don't search for a parent if the resource is not part of a realization\r
+               if(!graph.isInheritedFrom(graph.getSingleObject(data, l0.InstanceOf), l0.Realization))\r
+                       return null;\r
+               \r
+               // search for the model parent and build the uri\r
+               Resource parent = graph.getSingleObject(data, l0.PartOf);\r
+               while (!graph.isInstanceOf(parent, sr.SysdynModel)) {\r
+                       uri = graph.getRelatedValue(parent, l0.HasName) + "/" + uri;\r
+                       parent = graph.getSingleObject(parent, l0.PartOf);\r
+               }\r
+               // cut out the realization name\r
+               uri = uri.substring(uri.indexOf("/") + 1);\r
+               return uri;\r
+       }\r
 \r
        public Resource getModel() {\r
                return model;\r
index 45d8d893aabf6d717b42fdca64cc19ebfe07b36e..90fff3aacf9a4260050b18c10117cca1e4cbd670 100644 (file)
@@ -85,8 +85,15 @@ public class ShowModuleHandler extends AbstractHandler {
                                        \r
                                        if(diagram == null) return;\r
                                        \r
-                                       final String rvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, l0.HasName, StringBindingDefault.INSTANCE);\r
-\r
+                                       String finalRvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, l0.HasName, StringBindingDefault.INSTANCE);\r
+                                       \r
+                                       Variable rootVariable = graph.adapt(model, Variable.class);\r
+                                       Variable var = rootVariable.browsePossible(graph, finalRvi);\r
+                                       if(var == null) {\r
+                                               finalRvi = "";\r
+                                       }\r
+                                       final String rvi = finalRvi;\r
+                                       \r
                                        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
 \r
                                                @Override\r
@@ -94,7 +101,7 @@ public class ShowModuleHandler extends AbstractHandler {
                                                        //                        for (Triple<Resource, String, String> in : ins) {\r
                                                        try {\r
                                                                String editorId = EDITOR_ID;\r
-                                                               System.out.println("Activating diagram: model=" + modelURI + " rvi='" + rvi + "'");\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