]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
APIs for skipping state restoration for non-undo synchronization events 23/4123/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 16 Apr 2020 10:11:53 +0000 (13:11 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Thu, 16 Apr 2020 13:40:38 +0000 (13:40 +0000)
gitlab #520

Change-Id: I50491d4b514db05b8854bcbefff58e7bb9c3b13e
(cherry picked from commit 9ecf695514f0a6faaadf3f912e7a85ccec3d8865)

bundles/org.simantics.db.common/src/org/simantics/db/common/UndoMetadata.java
bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java

index f8026f59432c7701e2a134aa24dad97da447062e..0568b3103861ea64a28e6550e9dbd87cf11c381b 100644 (file)
@@ -116,4 +116,11 @@ public class UndoMetadata extends ACommentMetadata {
     public String getHeader() {
         return getType() + getRange();
     }
+    
+    /**
+     * Returns true when no change sets are included.
+     */
+    public boolean isEmpty() {
+        return begin == 0 && end == 0;
+    }
 }
index 095640c4aa1f0a2185da8bd6a92010421da6d63a..5f8334398fe9ba99d896b9798ef195f20c5c059a 100644 (file)
@@ -56,6 +56,13 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
      */
     THashSet<T> potentiallyUpdatedComponents = new THashSet<>();
 
+    /**
+     * Is this potentially an undo/redo-related synchronization?
+     * 
+     * Default is true for backwards compatibility.
+     */
+    protected boolean isUndo = true;
+
     public SynchronizationEventHandlerBase(Solver solver, ReferenceResolverBase<T> resolver, SolverNameUtil nameUtil,
             ComponentFactory<T> componentFactory, ModuleUpdaterFactoryBase<T> moduleUpdaterFactory, MappingBase<T> mapping) {
         this.solver = solver;
@@ -66,6 +73,19 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
         this.resolver = resolver;
     }
     
+    /**
+     * Mark the undo/redo status of this handler.
+     * 
+     * Set 'isUndo' to false when processing a normal synchronization and true when
+     * processing an undo/redo.
+     * 
+     * When 'isUndo' is false, loading of component solver state from the state undo context
+     * is skipped for added components.
+     */
+    public void setAsUndo(boolean isUndo) {
+        this.isUndo = isUndo;
+    }
+
     @Override
     public void beginSynchronization() {
         if(TRACE_EVENTS) {
@@ -311,14 +331,16 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                     else {
                         component.attached = false;
                         context.setModuleName(nameUtil.getFreshName(parentSolverComponentName, name));
-                        context.addPostUpdateAction(new Runnable() {
-                            @Override
-                            public void run() {
-                                context.stateLoadedFromUndo = mapping.undoContext.loadState(solver,
-                                        context.component.componentId, 
-                                        context.component.uid);
-                            }
-                        });
+                        if (isUndo) {
+                            context.addPostUpdateAction(new Runnable() {
+                                @Override
+                                public void run() {
+                                    context.stateLoadedFromUndo = mapping.undoContext.loadState(solver,
+                                            context.component.componentId, 
+                                            context.component.uid);
+                                }
+                            });
+                        }
                         updater.create(context, properties, connections);
                         solverComponentNameToComponent.put(context.getModuleName(), component);
                     }