label="Module"\r
style="push">\r
</command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.newExperiment"\r
+ id="org.simantics.sysdyn.ui.browser.newExperiment"\r
+ label="Experiment"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
</menu>\r
</menuContribution>\r
<menuContribution\r
</state>\r
</command>\r
<command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.NewModuleNodeHandler"\r
id="org.simantics.sysdyn.ui.newModuleNode"\r
name="New Module">\r
</command>\r
<command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.NewModelHandler"\r
id="org.simantics.sysdyn.ui.newModel"\r
name="New Model">\r
</command>\r
id="org.simantics.sysdyn.ui.activateResult"\r
name="Activate Result">\r
</command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.NewExperimentNodeHandler"\r
+ id="org.simantics.sysdyn.ui.newExperiment"\r
+ name="New Experiment">\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
class="org.simantics.sysdyn.ui.handlers.UnlinkNodeHandler"\r
commandId="org.simantics.sysdyn.ui.removeNode">\r
<activeWhen>\r
- <with\r
- variable="selection">\r
- <test\r
- args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
- property="org.simantics.sysdyn.ui.nodeClass">\r
- </test>\r
- </with>\r
+ <or>\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </or>\r
</activeWhen>\r
</handler>\r
<handler\r
</with>\r
</activeWhen>\r
</handler>\r
- <handler\r
- class="org.simantics.sysdyn.ui.handlers.NewModuleNodeHandler"\r
- commandId="org.simantics.sysdyn.ui.newModuleNode">\r
- </handler>\r
- <handler\r
- class="org.simantics.sysdyn.ui.handlers.NewModelHandler"\r
- commandId="org.simantics.sysdyn.ui.newModel">\r
- </handler>\r
</extension>\r
<extension\r
point="org.eclipse.ui.cheatsheets.cheatSheetContent">\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+\r
+public class NewExperimentNodeHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ System.out.println("New Experiment");\r
+ \r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
+ if (resources.length != 1)\r
+ return null;\r
+ \r
+ final Resource model = resources[0];\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph g) throws DatabaseException {\r
+ Builtins b = g.getBuiltins();\r
+ Resource report = GraphUtils.create2(g, b.Report, b.HasDocumentation, "===Report===");\r
+ @SuppressWarnings("unused")\r
+ Resource experiment = GraphUtils.create2(g, b.Experiment,\r
+ b.HasName, "Experiment",\r
+ b.HasLabel, "Experiment",\r
+ b.HasReportFactory, report,\r
+ b.PartOf, model);\r
+ }\r
+ });\r
+ return null;\r
+ }\r
+\r
+}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.handlers;\r
\r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.exception.CancelTransactionException;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
}\r
\r
private void deleteItem(final Resource[] resources) {\r
+ final ArrayList<Resource> configurations = new ArrayList<Resource>();\r
try {\r
SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
- Builtins b = graph.getBuiltins();\r
- for (Resource r : resources)\r
- graph.deny(r, b.PartOf);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for (Resource r : resources) {\r
+ if (graph.isInstanceOf(r, sr.SysdynModel)) {\r
+ unlinkModel(graph, r);\r
+ configurations.add(graph.getSingleObject(r, graph.getBuiltins().HasConfiguration));\r
+ }\r
+ else if (graph.isInstanceOf(r, graph.getBuiltins().Experiment))\r
+ unlinkExperiment(graph, r);\r
+ else if (graph.isInstanceOf(r, sr.Result))\r
+ unlinkResult(graph, r);\r
+ }\r
}\r
});\r
} catch (DatabaseException e) {\r
ExceptionUtils.logAndShowError(e);\r
}\r
\r
- for (Resource r : resources) {\r
+ for (Resource r : configurations) {\r
IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();\r
for(IEditorReference er : editorReferences) {\r
if(er.getEditor(false) instanceof SysdynDiagramEditor) {\r
\r
}\r
\r
+ private void unlinkModel(WriteGraph graph, Resource model) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+\r
+ for(Resource r : graph.getObjects(model, b.ConsistsOf))\r
+ if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result))\r
+ deleteResultFiles(graph, r);\r
+\r
+ graph.deny(model, b.PartOf);\r
+ }\r
+\r
+ private void unlinkExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ Collection<Resource> results = graph.getObjects(experiment, SysdynResource.getInstance(graph).HasResult);\r
+ if(results != null)\r
+ for(Resource result : results) \r
+ unlinkResult(graph, result);\r
+ graph.deny(experiment, b.PartOf);\r
+\r
+ }\r
+\r
+ private void unlinkResult(WriteGraph graph, Resource result) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ deleteResultFiles(graph, result);\r
+ graph.deny(result, b.PartOf);\r
+ graph.deny(result, graph.getInverse(SysdynResource.getInstance(graph).HasResult));\r
+\r
+ }\r
+\r
+ private void deleteResultFiles(WriteGraph graph, Resource result) throws DatabaseException {\r
+ String path;\r
+ path = graph.getPossibleRelatedValue(result, SysdynResource.getInstance(graph).HasResultFile);\r
+ if(path != null) {\r
+ File file = new File(path);\r
+ file.delete();\r
+ }\r
+ }\r
+\r
}
\ No newline at end of file
public void saveState() {\r
// TODO Auto-generated method stub\r
System.out.println("saveState");\r
+ if(sysdynModel.getSimulationResult() == null) return;\r
\r
try {\r
session.syncRequest(new WriteRequest() {\r
Resource res = GraphUtils.create2(graph, sr.Result,\r
b.HasLabel, "Result x",\r
b.HasName, "Result x",\r
+ b.PartOf, model,\r
sr.HasResultFile, file.getAbsolutePath());\r
graph.claim(experiment, sr.HasResult, res);\r
result.saveToFile(file);\r
}\r
\r
public void saveToFile(File file) {\r
+ if(recordingSession == null) return;\r
try {\r
Binding binding = Bindings.getBinding( recordingSession.getClass() );\r
Accessors.createFile(file, binding, recordingSession);\r