]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Show busy cursor and block UI input while committing changes 07/3907/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Mon, 24 Feb 2020 17:23:53 +0000 (19:23 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Tue, 25 Feb 2020 14:10:29 +0000 (16:10 +0200)
gitlab #89

Change-Id: I7caab1ef604c0024ab24dd34e2c52385e84dc10e

org.simantics.g3d.vtk/META-INF/MANIFEST.MF
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java

index 79d987c6eb6302936ce523ce09ec8991bddf08a2..1ba1aaf62e4cc3e07c7ce0c8ab934df446ec188b 100644 (file)
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.core.runtime,
  org.simantics.utils.ui;bundle-version="1.1.0",
  org.simantics.ui;bundle-version="1.0.0",
  vtk.rendering;bundle-version="8.2.0",
- org.simantics.utils.thread.swt;bundle-version="1.1.0"
+ org.simantics.utils.thread.swt;bundle-version="1.1.0",
+ org.slf4j.api
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.g3d.vtk.action,
index 4bcb5df271b53f5c3b8f8651d5146b1096e54540..a42c367252fc0744a754cc22fbd9f9045f283275 100644 (file)
@@ -11,6 +11,7 @@
  *******************************************************************************/
 package org.simantics.g3d.vtk.common;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -22,8 +23,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
-import java.util.function.Consumer;
 
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Session;
 import org.simantics.db.UndoContext;
@@ -45,12 +47,16 @@ import org.simantics.utils.datastructures.MapList;
 import org.simantics.utils.datastructures.MapSet;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.ui.ExceptionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import vtk.vtkProp;
 
 public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VTKNodeMap<DBObject,E>, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{
 
-       private static final boolean DEBUG = false;
+       private static final boolean DEBUG = true;
+
+       private static final Logger LOGGER = LoggerFactory.getLogger(AbstractVTKNodeMap.class);
        
        protected Session session;
        protected IMapping<DBObject, INode> mapping;
@@ -288,27 +294,29 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
        }
        
        protected void doCommit() {
-               session.asyncRequest(new WriteRequest() {
-                       
-                       @Override
-                       public void perform(WriteGraph graph) throws DatabaseException {
-                               if (DEBUG) System.out.println("Commit " + commitMessage);
-                               if (commitMessage != null) {
-                                       Layer0Utils.addCommentMetadata(graph, commitMessage);
-                                       graph.markUndoPoint();
-                                       commitMessage = null;
+               IProgressService service = PlatformUI.getWorkbench().getProgressService();
+               try {
+                       service.busyCursorWhile(monitor -> {
+                               try {
+                                       session.syncRequest(new WriteRequest() {
+                                               @Override
+                                               public void perform(WriteGraph graph) throws DatabaseException {
+                                                       if (DEBUG) System.out.println("Commit " + commitMessage);
+                                                       if (commitMessage != null) {
+                                                               Layer0Utils.addCommentMetadata(graph, commitMessage);
+                                                               graph.markUndoPoint();
+                                                               commitMessage = null;
+                                                       }
+                                                       commit(graph);
+                                               }
+                                       });
+                               } catch (DatabaseException e) {
+                                       ExceptionUtils.logAndShowError("Cannot commit editor changes", e);
                                }
-                               commit(graph);
-                       }
-                       
-               }, new Consumer<DatabaseException>() {
-                       
-                       @Override
-                       public void accept(DatabaseException parameter) {
-                               if (parameter != null)
-                                       ExceptionUtils.logAndShowError("Cannot commit editor changes", parameter);
-                       }
-               });
+                       });
+               } catch (InvocationTargetException | InterruptedException e) {
+                       LOGGER.error("Unexpected exception", e);
+               }
        }
        
        protected void commit(WriteGraph graph) throws DatabaseException {
@@ -342,25 +350,24 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
        protected void reset(ReadGraph graph) throws MappingException {
                if (DEBUG) System.out.println("Reset");
                
-               synchronized (syncMutex) {
-                       graphUpdates = true;
-                       mapping.getRangeModified().clear();
-                       for (DBObject o : mapping.getDomain())
-                               mapping.domainModified(o);
-                       mapping.updateRange(graph);
-                       graphModified.clear();
-                       graphUpdates = false;
-               }
+               graphUpdates = true;
+               mapping.getRangeModified().clear();
+               for (DBObject o : mapping.getDomain())
+                       mapping.domainModified(o);
+               mapping.updateRange(graph);
+               graphModified.clear();
+               graphUpdates = false;
        }
        
        private boolean useFullSyncWithUndo = false;
        
        protected void update(ReadGraph graph) throws DatabaseException {
-               if (DEBUG) System.out.println("Graph update start");
-               if (runUndo && useFullSyncWithUndo) {
-                       reset(graph);
-               } else {
-                   synchronized (syncMutex) {
+               synchronized (syncMutex) {
+                       if (DEBUG) System.out.println("Graph update start");
+                       
+                       if (runUndo && useFullSyncWithUndo) {
+                               reset(graph);
+                       } else {
                                graphUpdates = true;
                                for (DBObject domainObject : mapping.getDomainModified()) {
                                        @SuppressWarnings("unchecked")
@@ -374,11 +381,12 @@ public abstract class AbstractVTKNodeMap<DBObject,E extends INode> implements VT
                                clearDeletes();
                                graphUpdates = false;
                }
+                       
+                       if (mapping.isRangeModified() && !runUndo && !runRedo)
+                               commit((String)null);
+                       
+                       if (DEBUG) System.out.println("Graph update done");
                }
-               
-               if (mapping.isRangeModified() && !runUndo && !runRedo)
-                       commit((String)null);
-               if (DEBUG) System.out.println("Graph update done");
        }
        
        @Override