1 package org.simantics.modeling.tests.commands;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.Resource;
5 import org.simantics.db.WriteGraph;
6 import org.simantics.db.common.utils.OrderedSetUtils;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.diagram.stubs.DiagramResource;
9 import org.simantics.diagram.stubs.G2DResource;
10 import org.simantics.diagram.synchronization.graph.AddElement;
11 import org.simantics.layer0.Layer0;
12 import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
13 import org.simantics.modeling.tests.traits.SingleResourceTrait;
14 import org.simantics.modeling.tests.traits.SingleResourceTraitImpl;
17 public class AddModule extends ResourceWriteCommand<ModelingCommandSequenceTest> implements SingleResourceTrait {
19 private AddDiagram diagram;
20 private SingleResourceTrait type;
23 public AddModule(AddDiagram diagram, SingleResourceTrait type, double x, double y) {
24 this.diagram = diagram;
30 public AddModule(AddDiagram diagram, Resource type, double x, double y) {
31 this.diagram = diagram;
32 this.type = new SingleResourceTraitImpl(type);
38 protected Resource run(WriteGraph graph, ModelingCommandSequenceTest environment) throws DatabaseException {
40 Layer0 L0 = Layer0.getInstance(graph);
41 DiagramResource DIA = DiagramResource.getInstance(graph);
42 G2DResource G2D = G2DResource.getInstance(graph);
44 Resource diagramResource = diagram.getResource();
47 Resource resource = graph.newResource();
48 graph.claim(resource, L0.InstanceOf, null, type.getResource(graph));
49 graph.claimLiteral(resource, DIA.HasTransform, G2D.Transform, new double[] { 1, 0, 0, 1, x, y }, Bindings.DOUBLE_ARRAY);
50 graph.claim(resource, L0.PartOf, diagramResource);
52 AddElement.claimFreshElementName(graph, diagramResource, resource);
53 OrderedSetUtils.addFirst(graph, diagramResource, resource);