]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddDiagram.java
Added missing org.simantics.modeling.tests plug-ins.
[simantics/platform.git] / bundles / org.simantics.modeling.tests / src / org / simantics / modeling / tests / commands / AddDiagram.java
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddDiagram.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AddDiagram.java
new file mode 100644 (file)
index 0000000..021cb46
--- /dev/null
@@ -0,0 +1,42 @@
+package org.simantics.modeling.tests.commands;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.common.CommandSequenceEnvironment;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.tests.traits.SingleModelTrait;
+import org.simantics.modeling.tests.traits.SingleResourceTrait;
+import org.simantics.simulation.ontology.SimulationResource;
+import org.simantics.structural2.utils.StructuralUtils;
+
+public class AddDiagram extends ResourceWriteCommand<CommandSequenceEnvironment> implements SingleResourceTrait {
+
+       private SingleModelTrait model;
+       private Resource compositeType;
+       private String name;
+       
+       public AddDiagram(SingleModelTrait model, Resource compositeType, String name) {
+               this.model = model;
+               this.compositeType = compositeType;
+               this.name = name;
+       }
+       
+       @Override
+       protected Resource run(WriteGraph graph, CommandSequenceEnvironment environment) throws DatabaseException {
+               
+        SimulationResource SIMU = SimulationResource.getInstance(graph);
+        
+        Resource target = graph.getSingleObject(model.getResource(), SIMU.HasConfiguration);
+
+        Resource composite = StructuralUtils.newComponent(graph, target, name, compositeType);
+        
+               return graph.getSingleObject(composite, ModelingResources.getInstance(graph).CompositeToDiagram);
+               
+       }
+       
+       public String getName() {
+               return name;
+       }
+
+}
\ No newline at end of file