From: Reino Ruusu Date: Mon, 24 Feb 2020 17:23:53 +0000 (+0200) Subject: Show busy cursor and block UI input while committing changes X-Git-Tag: v1.43.0~61 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=da945733caf267fed4cf28206cc99f4f57fbd1e9;p=simantics%2F3d.git Show busy cursor and block UI input while committing changes gitlab #89 Change-Id: I7caab1ef604c0024ab24dd34e2c52385e84dc10e --- diff --git a/org.simantics.g3d.vtk/META-INF/MANIFEST.MF b/org.simantics.g3d.vtk/META-INF/MANIFEST.MF index 79d987c6..1ba1aaf6 100644 --- a/org.simantics.g3d.vtk/META-INF/MANIFEST.MF +++ b/org.simantics.g3d.vtk/META-INF/MANIFEST.MF @@ -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, diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java index 4bcb5df2..a42c3672 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java @@ -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 implements VTKNodeMap, 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 mapping; @@ -288,27 +294,29 @@ public abstract class AbstractVTKNodeMap 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() { - - @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 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 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