From 5a40d4036107daff4b804056b52714392835df2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 6 Sep 2017 16:09:07 +0300 Subject: [PATCH] (refs #7470) SCL function for migrating all instances of component type Change-Id: I8b2e7252702bd0c7d938b74239f024f5d5ac088a --- .../scl/Simantics/UserComponent.scl | 5 ++++- .../org/simantics/modeling/MigrateModel.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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); + } + } + } -- 2.43.2