From: Hannu Niemistö Date: Wed, 6 Sep 2017 13:09:07 +0000 (+0300) Subject: (refs #7470) SCL function for migrating all instances of component type X-Git-Tag: v1.31.0~193 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=5a40d4036107daff4b804056b52714392835df2e;p=simantics%2Fplatform.git (refs #7470) SCL function for migrating all instances of component type Change-Id: I8b2e7252702bd0c7d938b74239f024f5d5ac088a --- diff --git a/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl b/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl index ad62e1d6a..d79db9222 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl @@ -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 -> () 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 dee74b0e1..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; @@ -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 instances = graph.adapt(oldComponentType, Instances.class).find(graph, model); + + for(Resource instance : instances) { + new MigrationOperation( + new NamedResource("", instance), + newComponentTypeN, + newSymbolN) + .perform(graph); + } + } + }