]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java
Progress Monitor support
[simantics/interop.git] / org.simantics.interop.update / src / org / simantics / interop / update / model / ModelUpdate.java
index f3fbdda5b13877a3705b55901e1057aab3bb726a..32da62bb523bcc67c72baaddf0fac74fe305687d 100644 (file)
@@ -7,6 +7,8 @@ import java.util.Deque;
 import java.util.List;
 import java.util.Map.Entry;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -60,9 +62,16 @@ public abstract class ModelUpdate {
         * @throws DatabaseException
         */
        public void setInput(Resource oldModel, Resource newModel, Resource originalModel, boolean newDistinct) throws DatabaseException{
+               this.setInput(oldModel, newModel, originalModel, newDistinct, null);
+       }
+       public void setInput(Resource oldModel, Resource newModel, Resource originalModel, boolean newDistinct, IProgressMonitor monitor) throws DatabaseException{
+               
                this.oldModel = oldModel;
                this.newModel = newModel;
                this.originalModel = originalModel;
+               
+               if (monitor == null)
+                       monitor = new NullProgressMonitor();
 //             addFilters(filters);
                if (originalModel != null) {
                        // tree way comparison
@@ -71,10 +80,12 @@ public abstract class ModelUpdate {
                        GraphComparator comparator2  = result2.first;
                        if (result2.second != null)
                                showWarning(result2.second);
-                       comparator2.test(getSession());
+                       comparator2.test(getSession(), monitor);
                        changes2 = comparator2.getChanges();
+                       if (monitor.isCanceled())
+                               return;
                        changes2 = getSession().syncRequest(createFilterRead(changes2, filters));
-                       Pair<UpdateTree, UpdateList> chg2 = createChangeObjects(changes2);
+                       Pair<UpdateTree, UpdateList> chg2 = createChangeObjects(changes2, null);
                        updateTree2 = chg2.first;
                        updateList2 = chg2.second;
                        
@@ -83,10 +94,12 @@ public abstract class ModelUpdate {
                        GraphComparator comparator3  = result3.first;
                        if (result3.second != null)
                                showWarning(result3.second);
-                       comparator3.test(getSession());
+                       comparator3.test(getSession(), monitor);
                        changes3 = comparator3.getChanges();
                        changes3 = getSession().syncRequest(createFilterRead(changes3, filters));
                }
+               if (monitor.isCanceled())
+                       return;
                
                Pair<GraphComparator,String> result = getChanges(oldModel,newModel);
                GraphComparator comparator  = result.first;
@@ -125,10 +138,14 @@ public abstract class ModelUpdate {
                                }
                        }
                }
-               comparator.test(getSession());
+               if (monitor.isCanceled())
+                       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);
+               Pair<UpdateTree, UpdateList> chg = createChangeObjects(changes, monitor);
         updateTree = chg.first;
         updateList = chg.second;
                if (userFilters.size() != 0) {
@@ -139,7 +156,6 @@ public abstract class ModelUpdate {
                if (originalModel != null) {
                        defaultSelections();
                }
-               
                init = true;
        }
        
@@ -253,9 +269,15 @@ public abstract class ModelUpdate {
        
        protected abstract Pair<GraphComparator,String> getChanges(Resource r1, Resource r2)  throws DatabaseException;
        
-       protected Pair<UpdateTree, UpdateList> createChangeObjects(GraphChanges changes) throws DatabaseException{
-           UpdateTree updateTree = getUpdateTree(changes);
+       protected Pair<UpdateTree, UpdateList> createChangeObjects(GraphChanges changes, IProgressMonitor monitor) throws DatabaseException{
+               if (monitor != null)
+                       monitor.subTask("Processing structural changes");
+               UpdateTree updateTree = getUpdateTree(changes);
+               if (monitor != null)
+                       monitor.subTask("Processing property changes");
         UpdateList updateList = getUpdateList(changes);
+        if (monitor != null)
+               monitor.subTask("Postprocessing changes");
         postProcess(updateTree, updateList);
         return new Pair<UpdateTree, UpdateList>(updateTree, updateList);
        }
@@ -312,7 +334,7 @@ public abstract class ModelUpdate {
        
        public UpdateTree getUpdateTree3() throws DatabaseException{
                if (updateTree3 == null && changes3 != null) {
-                   Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3);
+                   Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3, null);
             updateTree3 = chg3.first;
             updateList3 = chg3.second;
                }
@@ -320,7 +342,7 @@ public abstract class ModelUpdate {
        }
        public UpdateList getUpdateList3() throws DatabaseException {
                if (updateList3 == null && changes3 != null) {
-                   Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3);
+                   Pair<UpdateTree, UpdateList> chg3 = createChangeObjects(changes3, null);
             updateTree3 = chg3.first;
             updateList3 = chg3.second;
                }