]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/MigrateModel.java
(refs #7470) SCL function for migrating all instances of component type
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / MigrateModel.java
index dee74b0e1d1b98bf9d499d48c84a0b43650774b3..eb0b80709b70094fcdfff1f5900a70f35d0dee2e 100644 (file)
@@ -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;
@@ -222,4 +223,22 @@ public class MigrateModel {
            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<Resource> instances = graph.adapt(oldComponentType, Instances.class).find(graph, model);
+           
+           for(Resource instance : instances) {
+               new MigrationOperation(
+                       new NamedResource("", instance),
+                       newComponentTypeN,
+                       newSymbolN)
+               .perform(graph);
+           }
+       }
+
 }