Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2018-05-24 16:41:29 +0000
committerNicolas FAUVERGUE2018-05-25 08:52:53 +0000
commitc361d453197982874f3d6e0145764583b83f9d8d (patch)
tree994818f37a0c837caa53051ef89d3183543ea043
parent533466f05b354e5c078d9e1cfea1b0101d4ca671 (diff)
downloadorg.eclipse.papyrus-c361d453197982874f3d6e0145764583b83f9d8d.tar.gz
org.eclipse.papyrus-c361d453197982874f3d6e0145764583b83f9d8d.tar.xz
org.eclipse.papyrus-c361d453197982874f3d6e0145764583b83f9d8d.zip
Bug 533683: [Sequence Diagram] Deletion of the last InteractionOperand
In the diagram, deletion of a multiple selection obtains a deletion command separately from each selected edit-part, entirely within its own context. There is no reasonable way to share a single InteractionContainerDeletionContext amongst these separate requests that will not break other situations, so instead of pre-computing the advice command that deletes the CombinedFragment when it will be left without any operands, this decision is deferred to the actual point of execution of an after advice. https://bugs.eclipse.org/bugs/show_bug.cgi?id=533683 Change-Id: I64b214df5540346c769c1ab769d914b279178e4c
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/InteractionOperandEditHelperAdvice.java41
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java26
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java34
3 files changed, 85 insertions, 16 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/InteractionOperandEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/InteractionOperandEditHelperAdvice.java
index c898ddf5592..f981a3c3bb3 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/InteractionOperandEditHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/InteractionOperandEditHelperAdvice.java
@@ -18,9 +18,17 @@ import static org.eclipse.gmf.runtime.common.core.command.CompositeCommand.compo
import java.util.Optional;
import java.util.Set;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.uml2.uml.CombinedFragment;
import org.eclipse.uml2.uml.InteractionOperand;
@@ -49,9 +57,36 @@ public class InteractionOperandEditHelperAdvice extends InteractionFragmentConta
// Are we deleting all of the operands of this combined fragment?
Optional<InteractionContainerDeletionContext> context = InteractionContainerDeletionContext.get(request);
- result = compose(context.filter(ctx -> deletingAllOperands(ctx, cfrag, request))
- .map(__ -> request.getDestroyDependentCommand(cfrag))
- .orElse(null), result);
+ // We won't know until the time comes, because in the diagrams, every edit-part
+ // selected is deleted in its own separate context
+ if (context.isPresent()) {
+ ICommand deferredCFragDeletion = new AbstractTransactionalCommand(request.getEditingDomain(), "Delete Combined Fragment", null) {
+ private IElementEditService edit = ElementEditServiceUtils.getCommandProvider(cfrag.eContainer(), request.getClientContext());
+ private DestroyElementRequest destroyCFrag = new DestroyElementRequest(request.getEditingDomain(), cfrag, false);
+
+ @Override
+ public boolean canExecute() {
+ return super.canExecute() && (edit != null);
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // Is it not already deleted by one of these commands but now should be?
+ if ((cfrag.eResource() != null) && cfrag.getOperands().isEmpty()) {
+ ICommand delegate = edit.getEditCommand(destroyCFrag);
+ if ((delegate == null) || !delegate.canExecute()) {
+ return CommandResult.newCancelledCommandResult();
+ }
+ delegate.execute(monitor, info);
+ return delegate.getCommandResult();
+ }
+
+ // Otherwise, there's nothing to do (yet)
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ result = compose(result, deferredCFragDeletion);
+ }
}
return result;
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
index 8753f5f3de8..d0f96b18492 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
@@ -61,7 +61,6 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.ui.palette.PaletteViewer;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
@@ -74,6 +73,7 @@ import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.notation.Diagram;
@@ -95,8 +95,6 @@ import org.eclipse.papyrus.infra.nattable.common.editor.AbstractEMFNattableEdito
import org.eclipse.papyrus.infra.nattable.common.modelresource.PapyrusNattableModel;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
import org.eclipse.papyrus.infra.tools.util.TypeUtils;
import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
@@ -1539,21 +1537,23 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
/**
- * Delete an edit-part from the diagram.
+ * Delete one or more edit-parts from the diagram.
*
* @param editPart
- * the edit-part to delete
+ * the edit-parts to delete
*
* @since 2.2
+ *
+ * @throws IllegalArgumentException
+ * if no edit-parts are specified
*/
- public void delete(EditPart editPart) {
- EObject toDestroy = editPart.getAdapter(EObject.class);
- EObject container = toDestroy.eContainer();
- DestroyElementRequest request = new DestroyElementRequest(toDestroy, false);
- IElementEditService edit = ElementEditServiceUtils.getCommandProvider(container);
- ICommand delete = edit.getEditCommand(request);
-
- assertThat("No delete command obtained", delete, notNullValue());
+ public void delete(EditPart... editPart) {
+ // In the diagram, deletion of a multiple selection is accomplished with separate
+ // requests to each edit-part, so do the same here
+ org.eclipse.gef.commands.Command delete = Stream.of(editPart).map(ep -> ep.getCommand(new EditCommandRequestWrapper(new DestroyElementRequest(false))))
+ .reduce(org.eclipse.gef.commands.Command::chain)
+ .orElseThrow(IllegalArgumentException::new);
+
execute(delete);
}
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
index 88adfd68049..cf1add4893b 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
@@ -319,6 +319,40 @@ public class CombinedFragmentRegressionTest extends AbstractPapyrusTest {
}
/**
+ * Verify that the simultaneous deletion of all interaction operands in a combined
+ * fragment deletes the combined fragment.
+ *
+ * @see <a href="http://eclip.se/533683">bug 533683</a>
+ */
+ @Test
+ @PluginResource("resource/bugs/bug533683.di")
+ public void deleteAllInteractionOperands() {
+ EditPart combinedFragmentEP = editor.findEditPart("cfrag", CombinedFragment.class);
+ CombinedFragment cfrag = (CombinedFragment) combinedFragmentEP.getAdapter(EObject.class);
+ Interaction interaction = cfrag.getEnclosingInteraction();
+ assumeThat("No interaction", interaction, notNullValue());
+
+ InteractionOperand operand0 = cfrag.getOperands().get(0);
+ InteractionOperand operand = cfrag.getOperands().get(1);
+ InteractionFragment deleteSend = operand.getFragment("delete-send");
+ assumeThat("Lost the delete send event on editor open", deleteSend, notNullValue());
+ InteractionFragment deleted = operand.getFragment("deleted");
+ assumeThat("Lost the deletion occurrence on editor open", deleted, notNullValue());
+
+ EditPart operand0EP = editor.requireEditPart(combinedFragmentEP, operand0);
+ EditPart operandEP = editor.requireEditPart(combinedFragmentEP, operand);
+
+ editor.delete(operand0EP, operandEP);
+
+ combinedFragmentEP = editor.findEditPart(cfrag);
+
+ assertThat("Combined fragment not deleted", cfrag, isDeleted());
+ assertThat("Combined fragment still presented in diagram", combinedFragmentEP, nullValue());
+
+ assertThat("Fragments of deleted operand not retained", interaction.getFragments(), hasItems(deleteSend, deleted));
+ }
+
+ /**
* Verify the creation of a combined fragment by just dropping the tool on a
* lifeline.
*/

Back to the top