]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7470) SCL function for migrating all instances of component type 27/927/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 6 Sep 2017 13:09:07 +0000 (16:09 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Wed, 6 Sep 2017 13:09:07 +0000 (16:09 +0300)
Change-Id: I8b2e7252702bd0c7d938b74239f024f5d5ac088a

bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl
bundles/org.simantics.modeling/src/org/simantics/modeling/MigrateModel.java

index ad62e1d6a3effcae29504af0ddab77c399cef685..d79db922229d5c9c2bfa114d0f27c41e9f471d3f 100644 (file)
@@ -158,4 +158,7 @@ navigateToSubstructureAction element = do
  match (syncRead (\x -> possibleSubstructureEditor element)) with
    Nothing -> ()
    Just (configuration,editor) -> openEditor editor configuration
-                
\ No newline at end of file
+
+importJava "org.simantics.modeling.MigrateModel" where
+    "changeAllComponentTypes model oldComponentType newComponentType"
+    changeAllComponentTypes :: Resource -> Resource -> Resource -> <WriteGraph> ()
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);
+           }
+       }
+
 }