Bug 581833 - [Robotics] Connect advice (and maybe others) break undo/redo
- Add missing "first = false" to DEfferedComposite
- Enhance documentation
- Fix implementation of ImportUtils
Change-Id: Id2e91e790aeaf02ca2b1eae6217ec8d32f9b8d39
Signed-off-by: aradermache <ansgar.radermacher@cea.fr>
diff --git a/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/commands/DeferredCompositeCommand.java b/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/commands/DeferredCompositeCommand.java
index 4dc239a..f4f76be 100644
--- a/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/commands/DeferredCompositeCommand.java
+++ b/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/commands/DeferredCompositeCommand.java
@@ -25,9 +25,11 @@
import org.eclipse.gmf.runtime.common.core.command.IdentityCommand;
/**
- * A composite command which replaces its first command when executed. It is
- * useful, if command arguments are not known at command creation time, for instance
- * in an advice.
+ * An abstract superclass for composite commands which need to include a command whose
+ * arguments are not known at command creation time, since the elements are only partly
+ * created or need to be created first by previous commands that are not yet executed.
+ * Technically, the composite command contains an IdentityCommand as first command. It
+ * replaces it the the composite command is executed for the first time.
*/
abstract public class DeferredCompositeCommand extends CompositeCommand {
@@ -38,9 +40,15 @@
add(IdentityCommand.INSTANCE);
}
+ /**
+ * Method that creates the deferred command. It is called at command execution
+ * time and needs to be implemented by subclasses
+ *
+ * @return the command that is be executed at first command of the composite
+ */
public abstract ICommand createDeferredCommand();
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked") // due to access to getChildren().
@Override
public IStatus execute(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
if (first) {
@@ -49,6 +57,7 @@
// replace Identity command
getChildren().set(0, command);
}
+ first = false;
}
return super.execute(progressMonitor, info);
}
diff --git a/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/utils/ImportUtils.java b/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/utils/ImportUtils.java
index eac9a96..ae7fdb9 100644
--- a/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/utils/ImportUtils.java
+++ b/plugins/customization/org.eclipse.papyrus.robotics.core/src/org/eclipse/papyrus/robotics/core/utils/ImportUtils.java
@@ -20,6 +20,7 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
@@ -72,12 +73,13 @@
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(root);
// execute both commands in a composite
+ CompositeCommand cc = new CompositeCommand("Create package import"); //$NON-NLS-1$
+
CreateElementRequest createPiReq = new CreateElementRequest(root, UMLElementTypes.PACKAGE_IMPORT);
ICommand createPiCmd = provider.getEditCommand(createPiReq);
- // use a wrapper composite for 2nd command
- // Use deferred command, since connector ends are not yet known.
- DeferredCompositeCommand cc = new DeferredCompositeCommand() {
+ // use a deferred composite for 2nd command
+ DeferredCompositeCommand wrapper = new DeferredCompositeCommand() {
@Override
public ICommand createDeferredCommand() {
@@ -93,6 +95,7 @@
};
cc.add(createPiCmd);
+ cc.add(wrapper);
stack.execute(GMFtoEMFCommandWrapper.wrap(cc));
}
}