]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Progress Monitor support 95/4895/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 22 Feb 2022 14:41:58 +0000 (16:41 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 22 Feb 2022 14:41:58 +0000 (16:41 +0200)
Check monitor cancel status more often in ModelUpdate.

gitlab #35

Change-Id: I90ecfac649c6cea45ce95d9a32a3ee8774d79291

org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java

index 32da62bb523bcc67c72baaddf0fac74fe305687d..51cd1eb4c0c338655e0f8dbc4777e58786dedd43 100644 (file)
@@ -82,8 +82,10 @@ public abstract class ModelUpdate {
                                showWarning(result2.second);
                        comparator2.test(getSession(), monitor);
                        changes2 = comparator2.getChanges();
-                       if (monitor.isCanceled())
+                       if (monitor.isCanceled()) {
+                               dispose();
                                return;
+                       }
                        changes2 = getSession().syncRequest(createFilterRead(changes2, filters));
                        Pair<UpdateTree, UpdateList> chg2 = createChangeObjects(changes2, null);
                        updateTree2 = chg2.first;
@@ -98,8 +100,10 @@ public abstract class ModelUpdate {
                        changes3 = comparator3.getChanges();
                        changes3 = getSession().syncRequest(createFilterRead(changes3, filters));
                }
-               if (monitor.isCanceled())
+               if (monitor.isCanceled()) {
+                       dispose();
                        return;
+               }
                
                Pair<GraphComparator,String> result = getChanges(oldModel,newModel);
                GraphComparator comparator  = result.first;
@@ -138,14 +142,20 @@ public abstract class ModelUpdate {
                                }
                        }
                }
-               if (monitor.isCanceled())
+               if (monitor.isCanceled()) {
+                       dispose();
                        return;
+               }
                comparator.test(getSession(), monitor);
                monitor.setTaskName("Processing changes...");
                monitor.subTask("");
                changes = comparator.getChanges();
                changes = getSession().syncRequest(createFilterRead(changes, filters));
                Pair<UpdateTree, UpdateList> chg = createChangeObjects(changes, monitor);
+               if (chg == null) {
+                       dispose();
+                       return;
+               }
         updateTree = chg.first;
         updateList = chg.second;
                if (userFilters.size() != 0) {
@@ -270,14 +280,23 @@ public abstract class ModelUpdate {
        protected abstract Pair<GraphComparator,String> getChanges(Resource r1, Resource r2)  throws DatabaseException;
        
        protected Pair<UpdateTree, UpdateList> createChangeObjects(GraphChanges changes, IProgressMonitor monitor) throws DatabaseException{
-               if (monitor != null)
+               if (monitor != null) {
+                       if (monitor.isCanceled())
+                               return null;
                        monitor.subTask("Processing structural changes");
+               }
                UpdateTree updateTree = getUpdateTree(changes);
-               if (monitor != null)
+               if (monitor != null) {
+                       if (monitor.isCanceled())
+                               return null;
                        monitor.subTask("Processing property changes");
+               }
         UpdateList updateList = getUpdateList(changes);
-        if (monitor != null)
+        if (monitor != null) {
+               if (monitor.isCanceled())
+                               return null;
                monitor.subTask("Postprocessing changes");
+        }
         postProcess(updateTree, updateList);
         return new Pair<UpdateTree, UpdateList>(updateTree, updateList);
        }
@@ -342,9 +361,9 @@ public abstract class ModelUpdate {
        }
        public UpdateList getUpdateList3() throws DatabaseException {
                if (updateList3 == null && changes3 != null) {
-                   Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3, null);
-            updateTree3 = chg3.first;
-            updateList3 = chg3.second;
+                       Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3, null);
+                       updateTree3 = chg3.first;
+                       updateList3 = chg3.second;
                }
                return updateList3;
        }
@@ -622,5 +641,6 @@ public abstract class ModelUpdate {
                updateTree2 = null;
                updateTree3 = null;
                updateNode3 = null;
+               init = false;
        }
 }