Bug 389380: Undo/Redo handling wrong Command executed by undo action
*A feature that did no changes is not added to the standard command
stack but to the additional steps command stack (for
ICustomUnduableFeatures)
* That causes the stacks to get out of sync and the wrong feature will
be undone for additional steps while the right one is undone for
standard changes
Change-Id: Ifcbdad99027324ec8866c601a23513ee587e24e8
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/GFWorkspaceCommandStackImpl.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/GFWorkspaceCommandStackImpl.java
index ea62fb6..5b374f1 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/GFWorkspaceCommandStackImpl.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/editor/GFWorkspaceCommandStackImpl.java
@@ -13,6 +13,7 @@
* mwenz - Bug 340627 - Features should be able to indicate cancellation
* mwenz - Bug 351053 - Remove the need for WorkspaceCommandStackImpl
* mwenz - Bug 371717 - IllegalStateException When updating cells on Diagram
+ * mwenz - Bug 389380 - Undo/Redo handling wrong Command executed by undo action
*
* </copyright>
*
@@ -94,7 +95,21 @@
GraphitiUiInternal.getCommandService().completeExecutionInfo((DefaultExecutionInfo) executionInfo,
GraphitiUiInternal.getCommandService().transformFromEmfToGefCommand(command));
}
- undoStackForExecutionInfo.push(executionInfo);
+
+ /*
+ * Remove the feature and context combinations from the
+ * execution list whose features did not do any changes. The
+ * commands for those features are not placed on the editor
+ * command stack and must also not appear in the stack for
+ * additional undo steps. See Bugzilla 389380 for details. In
+ * case no entry is left in the execution info, it must not be
+ * written to the stack in order to keep the standard and the
+ * additional undo stack in sync.
+ */
+ executionInfo = GraphitiUiInternal.getCommandService().removeFeaturesWithoutChanges(executionInfo);
+ if (executionInfo.getExecutionList().length > 0) {
+ undoStackForExecutionInfo.push(executionInfo);
+ }
} finally {
topLevelCommand = true;
}
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/ICommandService.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/ICommandService.java
index 0667da2..781d92a 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/ICommandService.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/ICommandService.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,12 +9,14 @@
*
* Contributors:
* mwenz - Bug 324859 - initial API, implementation and documentation
+ * mwenz - Bug 389380 - Undo/Redo handling wrong Command executed by undo action
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.graphiti.ui.internal.services;
+import org.eclipse.graphiti.IExecutionInfo;
import org.eclipse.graphiti.internal.command.DefaultExecutionInfo;
import org.eclipse.graphiti.internal.command.ICommand;
@@ -36,4 +38,6 @@
org.eclipse.emf.common.command.Command transformFromGefToEmfCommand(org.eclipse.gef.commands.Command gefCommand);
+ IExecutionInfo removeFeaturesWithoutChanges(IExecutionInfo executionInfo);
+
}
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/impl/CommandService.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/impl/CommandService.java
index aac3f44..7094728 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/impl/CommandService.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/services/impl/CommandService.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
*
* Contributors:
* mwenz - Bug 324859 - initial API, implementation and documentation
+ * mwenz - Bug 389380 - Undo/Redo handling wrong Command executed by undo action
*
* </copyright>
*
@@ -19,6 +20,7 @@
import org.eclipse.emf.common.command.Command;
import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.graphiti.IExecutionInfo;
import org.eclipse.graphiti.features.IContextHolder;
import org.eclipse.graphiti.features.IFeature;
import org.eclipse.graphiti.features.IFeatureAndContext;
@@ -131,4 +133,14 @@
return executionInfo;
}
+
+ public IExecutionInfo removeFeaturesWithoutChanges(IExecutionInfo executionInfo) {
+ DefaultExecutionInfo result = new DefaultExecutionInfo();
+ for (IFeatureAndContext featureAndContext : executionInfo.getExecutionList()) {
+ if (featureAndContext.getFeature().hasDoneChanges()) {
+ result.addFeatureAndContext(featureAndContext);
+ }
+ }
+ return result;
+ }
}