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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
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
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
\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
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
\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
}\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
\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
// 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