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