From: Reino Ruusu Date: Thu, 16 Apr 2020 10:11:53 +0000 (+0300) Subject: APIs for skipping state restoration for non-undo synchronization events X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=9ecf695514f0a6faaadf3f912e7a85ccec3d8865;ds=sidebyside APIs for skipping state restoration for non-undo synchronization events gitlab #520 Change-Id: I50491d4b514db05b8854bcbefff58e7bb9c3b13e --- diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/UndoMetadata.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/UndoMetadata.java index f8026f594..0568b3103 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/UndoMetadata.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/UndoMetadata.java @@ -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; + } } diff --git a/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java index 095640c4a..5f8334398 100644 --- a/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java +++ b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java @@ -56,6 +56,13 @@ public abstract class SynchronizationEventHandlerBase */ THashSet 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 resolver, SolverNameUtil nameUtil, ComponentFactory componentFactory, ModuleUpdaterFactoryBase moduleUpdaterFactory, MappingBase mapping) { this.solver = solver; @@ -66,6 +73,19 @@ public abstract class SynchronizationEventHandlerBase 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 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); }