X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FMigrateModel.java;h=eb0b80709b70094fcdfff1f5900a70f35d0dee2e;hp=16b8ae92aeca27e2e407f3e0bf911a5fc7c4e2ba;hb=92ad7da377109c556029f64566e3a2ab67ac57c6;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/MigrateModel.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/MigrateModel.java index 16b8ae92a..eb0b80709 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/MigrateModel.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/MigrateModel.java @@ -28,6 +28,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.NamedResource; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.Instances; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; @@ -216,4 +217,28 @@ public class MigrateModel { public List>> instances = new ArrayList<>(); public List sortedShownInstances = Collections.emptyList(); + public static void changeComponentType(WriteGraph graph, Resource instance, Resource newComponentType) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + Resource newSymbol = graph.getSingleObject(newComponentType, MOD.ComponentTypeToSymbol); + new MigrationOperation(new NamedResource("", instance), new NamedResource("", newComponentType), new NamedResource("", newSymbol)) + .perform(graph); + } + + public static void changeAllComponentTypes(WriteGraph graph, Resource model, Resource oldComponentType, Resource newComponentType) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + NamedResource newComponentTypeN = new NamedResource("", newComponentType); + Resource newSymbol = graph.getSingleObject(newComponentType, MOD.ComponentTypeToSymbol); + NamedResource newSymbolN = new NamedResource("", newSymbol); + + Collection instances = graph.adapt(oldComponentType, Instances.class).find(graph, model); + + for(Resource instance : instances) { + new MigrationOperation( + new NamedResource("", instance), + newComponentTypeN, + newSymbolN) + .perform(graph); + } + } + }