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%2FUserComponentMigration.java;h=9f7f486c8316835b065e5ee639537665470278f6;hp=6cb08ddfd8898dc20aaa5f324a6bcd7156bd4cb8;hb=a2a42428426818a7498d5a1705603fb8d3a8a95a;hpb=53059ca1a958697cc6235d27628614fbaa944d59 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/UserComponentMigration.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/UserComponentMigration.java index 6cb08ddfd..9f7f486c8 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/UserComponentMigration.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/UserComponentMigration.java @@ -19,6 +19,8 @@ import java.util.Collections; import java.util.Comparator; import java.util.Set; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.simantics.Simantics; import org.simantics.databoard.Bindings; import org.simantics.databoard.util.URIStringUtils; @@ -31,6 +33,7 @@ import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.VersionMap; import org.simantics.db.common.utils.Versions; +import org.simantics.db.exception.CancelTransactionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Instances; import org.simantics.db.layer0.request.ActiveModels; @@ -65,15 +68,21 @@ public class UserComponentMigration { } } if (!result.isEmpty()) - doMigration(graph, result); + doMigration(new NullProgressMonitor(), graph, result); } - public static String doMigration(WriteGraph graph, final ArrayList result) throws DatabaseException { + public static String doMigration(IProgressMonitor monitor, WriteGraph graph, final ArrayList operations) throws DatabaseException { graph.markUndoPoint(); StringBuilder b = new StringBuilder(); int success = 0; int problem = 0; - for(MigrationOperation op : result) { + int no = 1; + int count = operations.size(); + monitor.setTaskName("Migrating " + count + " User Components"); + for(MigrationOperation op : operations) { + if (monitor.isCanceled()) + throw new CancelTransactionException(); + monitor.subTask("(" + (no++) + "/" + count + ") " + op.toString()); String problems = op.perform(graph); if(problems != null) { b.insert(0, problems); @@ -98,17 +107,19 @@ public class UserComponentMigration { return b.toString(); } - public static void doPostMigration(WriteGraph graph, ArrayList result) throws DatabaseException { + public static void doPostMigration(IProgressMonitor monitor, WriteGraph graph, ArrayList result) throws DatabaseException { THashSet roots = new THashSet<>(); for(MigrationOperation op : result) { Resource root = graph.syncRequest(new PossibleIndexRoot(op.instanceToMigrate.getResource())); if(root != null) roots.add(root); } + if (monitor.isCanceled()) + throw new CancelTransactionException(); for(Resource root : roots) { UserComponentPostMigrationAction action = graph.getPossibleAdapter(root, UserComponentPostMigrationAction.class); if(action != null) - action.perform(graph); + action.perform(monitor, graph); } }