*******************************************************************************/
package org.simantics.g3d.vtk.common;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
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;
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;
}
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 {
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")
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