summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsboyko2014-08-07 13:27:39 (EDT)
committerCamille Letavernier2014-08-08 09:32:59 (EDT)
commit63d60e51b963bd707d3de6559caa72c22becd4e4 (patch)
tree2fa4881536fa5096415e28b61a1f0e02fc130f4e
parent410531846a5da02b10a1654993c5913a5a9756b3 (diff)
downloadorg.eclipse.papyrus-63d60e51b963bd707d3de6559caa72c22becd4e4.zip
org.eclipse.papyrus-63d60e51b963bd707d3de6559caa72c22becd4e4.tar.gz
org.eclipse.papyrus-63d60e51b963bd707d3de6559caa72c22becd4e4.tar.bz2
Bug 430552 - [Sequence Diagram] Dependents of occurrence specificationsrefs/changes/07/31207/3
not deleted Change-Id: I5fbda29bc28afd777c6812900ec9ac26ac5ecea1 Signed-off-by: sboyko <serg.boyko2011@gmail.com>
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ExecutionSpecificationHelperAdvice.java32
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/OccurrenceSpecificationHelperAdvice.java56
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestOccurrenceSpecificationDeletion_430552.java152
3 files changed, 210 insertions, 30 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ExecutionSpecificationHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ExecutionSpecificationHelperAdvice.java
index 00fb088..6d1c820 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ExecutionSpecificationHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/ExecutionSpecificationHelperAdvice.java
@@ -26,6 +26,7 @@ import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.uml.diagram.common.helper.InteractionFragmentHelper;
+import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.Lifeline;
@@ -43,7 +44,7 @@ public class ExecutionSpecificationHelperAdvice extends AbstractEditHelperAdvice
* <pre>
* Add a command to associated {@link OccurrenceSpecification} and {@link Message}.
* This command is only added if the start - finish referenced {@link OccurrenceSpecification} is not
- * referenced by another element.
+ * referenced by another element or the start/finish references are of type {@link ExecutionOccurrenceSpecification}.
* </pre>
*
* @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeDestroyDependentsCommand(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest)
@@ -59,15 +60,14 @@ public class ExecutionSpecificationHelperAdvice extends AbstractEditHelperAdvice
ExecutionSpecification es = (ExecutionSpecification)request.getElementToDestroy();
- // Add start - finish referenced OccurrenceSpecification to the dependents list
- // if they are not used by another element.
+ // Check whether start - finish referenced OccurrenceSpecification should be added to the dependents list
OccurrenceSpecification osStart = es.getStart();
- if((osStart != null) && (EMFHelper.isOnlyUsage(osStart, es))) {
+ if(shouldDestroyOccurrenceSpecification(es, osStart)) {
dependentsToDestroy.add(osStart);
}
OccurrenceSpecification osFinish = es.getFinish();
- if((osFinish != null) && (EMFHelper.isOnlyUsage(osFinish, es))) {
+ if(shouldDestroyOccurrenceSpecification(es, osFinish)) {
dependentsToDestroy.add(osFinish);
}
@@ -107,4 +107,26 @@ public class ExecutionSpecificationHelperAdvice extends AbstractEditHelperAdvice
return null;
}
+
+ /**
+ * <pre>
+ * Check that given {@link OccurrenceSpecification} should be destroyed along with {@link ExecutionSpecification} which references it.
+ * It should be destroyed in case:
+ * It is of type {@link ExecutionOccurrenceSpecification} (since the opposite reference
+ * 'ExecutionOccurrenceSpecification::execution[1]' which designates given {@link ExecutionSpecification} is mandatory).
+ * or
+ * It is not used by another element.
+ * </pre>
+ *
+ * @param es
+ * {@link ExecutionSpecification} which references {@link OccurrenceSpecification} (by means of #start/#finish references)
+ * @param os
+ * start or finish {@link OccurrenceSpecification} which defines the duration of {@link ExecutionSpecification}
+ * @return true in case {@link OccurrenceSpecification} should be destroyed
+ */
+ private boolean shouldDestroyOccurrenceSpecification(ExecutionSpecification es, OccurrenceSpecification os) {
+ return os instanceof ExecutionOccurrenceSpecification
+ || (os != null && EMFHelper.isOnlyUsage(os, es));
+ }
+
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/OccurrenceSpecificationHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/OccurrenceSpecificationHelperAdvice.java
index b858c98..38201bd 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/OccurrenceSpecificationHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/OccurrenceSpecificationHelperAdvice.java
@@ -13,9 +13,18 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.service.types.helper.advice;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyDependentsRequest;
+import org.eclipse.papyrus.uml.diagram.common.helper.DurationConstraintHelper;
+import org.eclipse.papyrus.uml.diagram.common.helper.DurationObservationHelper;
+import org.eclipse.papyrus.uml.diagram.common.helper.TimeConstraintHelper;
+import org.eclipse.papyrus.uml.diagram.common.helper.TimeObservationHelper;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
/**
* Helper advice for all {@link OccurrenceSpecification} elements.
@@ -25,7 +34,6 @@ public class OccurrenceSpecificationHelperAdvice extends AbstractEditHelperAdvic
/**
* <pre>
* Add a command to destroy :
- * - {@link Event} referenced by the {@link OccurrenceSpecification} to delete if unused
* - related time elements
* - linked general ordering
* </pre>
@@ -38,30 +46,28 @@ public class OccurrenceSpecificationHelperAdvice extends AbstractEditHelperAdvic
*/
@Override
protected ICommand getBeforeDestroyDependentsCommand(DestroyDependentsRequest request) {
- //FIXME : change for UML 2.4
-// List<EObject> dependentsToDestroy = new ArrayList<EObject>();
-//
-// OccurrenceSpecification os = (OccurrenceSpecification)request.getElementToDestroy();
-// Event event = os.getEvent();
-//
-// // Delete referenced event if it is not referenced itself by another element.
-// if((event != null) && (PapyrusEcoreUtils.isOnlyUsage(event, os))) {
-// dependentsToDestroy.add(event);
-// }
-//
-// // delete linked time elements
-// dependentsToDestroy.addAll(TimeObservationHelper.getTimeObservations(os));
-// dependentsToDestroy.addAll(TimeConstraintHelper.getTimeConstraintsOn(os));
-// dependentsToDestroy.addAll(DurationObservationHelper.getDurationObservationsOn(os));
-// dependentsToDestroy.addAll(DurationConstraintHelper.getDurationConstraintsOn(os));
-//
-// // delete linked general ordering
-// dependentsToDestroy.addAll(os.getToBefores());
-// dependentsToDestroy.addAll(os.getToAfters());
-//
-// if(!dependentsToDestroy.isEmpty()) {
-// return request.getDestroyDependentsCommand(dependentsToDestroy);
-// }
+ List<EObject> dependentsToDestroy = new ArrayList<EObject>();
+
+ OccurrenceSpecification os = (OccurrenceSpecification)request.getElementToDestroy();
+
+ // delete linked time elements
+ dependentsToDestroy.addAll(TimeObservationHelper.getTimeObservations(os));
+ dependentsToDestroy.addAll(TimeConstraintHelper.getTimeConstraintsOn(os));
+ dependentsToDestroy.addAll(DurationObservationHelper.getDurationObservationsOn(os));
+ dependentsToDestroy.addAll(DurationConstraintHelper.getDurationConstraintsOn(os));
+
+ // delete linked general ordering
+ /**
+ * Note: GeneralOrdering should be necessarily removed because the opposite
+ * references 'GeneralOrdering::before[1]' and 'GeneralOrdering::after[1]' which designate
+ * this OccurrenceSpecification are mandatory
+ */
+ dependentsToDestroy.addAll(os.getToBefores());
+ dependentsToDestroy.addAll(os.getToAfters());
+
+ if(!dependentsToDestroy.isEmpty()) {
+ return request.getDestroyDependentsCommand(dependentsToDestroy);
+ }
return null;
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestOccurrenceSpecificationDeletion_430552.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestOccurrenceSpecificationDeletion_430552.java
new file mode 100644
index 0000000..a515989
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestOccurrenceSpecificationDeletion_430552.java
@@ -0,0 +1,152 @@
+/*****************************************************************************
+ * Copyright (c) 2012, 2014 CEA LIST and others.
+ *
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ * Sergey Boyko - bug 430552
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.sequence.tests.bug;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
+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.papyrus.commands.ICreationCommand;
+import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.tests.ISequenceDiagramTestsConstants;
+import org.eclipse.papyrus.uml.diagram.sequence.tests.canonical.CreateSequenceDiagramCommand;
+import org.eclipse.papyrus.uml.diagram.sequence.tests.canonical.TestLink;
+import org.eclipse.uml2.uml.BehaviorExecutionSpecification;
+import org.junit.Test;
+
+/**
+ * The deletion of an ExecutionSpecification (and consequently the deletion of OccurrenceSpecification(s))
+ * should involve the deletion of dependents that require its existence.
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=430552
+ *
+ */
+public class TestOccurrenceSpecificationDeletion_430552 extends TestLink {
+
+ @Override
+ protected ICreationCommand getDiagramCommandCreation() {
+ return new CreateSequenceDiagramCommand();
+ }
+
+ @Override
+ protected String getProjectName() {
+ return ISequenceDiagramTestsConstants.PROJECT_NAME;
+ }
+
+ @Override
+ protected String getFileName() {
+ return ISequenceDiagramTestsConstants.FILE_NAME;
+ }
+
+ @Test
+ public void testGeneralOrderingDeletion() {
+ createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), new Dimension(62, 200));
+ createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), new Dimension(62, 200));
+ final LifelineEditPart lifeline1 = (LifelineEditPart)getRootEditPart().getChildren().get(0);
+ final LifelineEditPart lifeline2 = (LifelineEditPart)getRootEditPart().getChildren().get(1);
+ waitForComplete();
+
+ createNode(UMLElementTypes.BehaviorExecutionSpecification_3003, lifeline1, new Point(131, 140), new Dimension(20, 60));
+ createNode(UMLElementTypes.BehaviorExecutionSpecification_3003, lifeline2, new Point(331, 200), new Dimension(20, 60));
+ createNode(UMLElementTypes.DestructionOccurrenceSpecification_3022, lifeline1, getAbsoluteBounds(lifeline1).getBottom(), null);
+ waitForComplete();
+
+ IGraphicalEditPart source = (IGraphicalEditPart)lifeline1.getChildren().get(1);
+ IGraphicalEditPart target = (IGraphicalEditPart)lifeline2.getChildren().get(1);
+ IGraphicalEditPart target2 = (IGraphicalEditPart)lifeline1.getChildren().get(2);
+
+ createLink(UMLElementTypes.GeneralOrdering_4012, source, target, getAbsoluteBounds(source).getTop(), getAbsoluteBounds(target).getTop());
+ createLink(UMLElementTypes.GeneralOrdering_4012, target, target2, getAbsoluteBounds(target).getBottom(), getAbsoluteBounds(target2).getTop());
+ waitForComplete();
+ assertTrue(CREATION + TEST_THE_EXECUTION, source.getSourceConnections().size() == 1);
+ assertTrue(CREATION + TEST_THE_EXECUTION, target.getSourceConnections().size() == 1);
+
+ BehaviorExecutionSpecification execSpec1 = (BehaviorExecutionSpecification)source.resolveSemanticElement();
+ BehaviorExecutionSpecification execSpec2 = (BehaviorExecutionSpecification)target.resolveSemanticElement();
+ assertTrue(CREATION + TEST_THE_EXECUTION, execSpec1.getGeneralOrderings().size() == 1);
+ assertTrue(CREATION + TEST_THE_EXECUTION, execSpec2.getGeneralOrderings().size() == 1);
+
+ Request deleteViewRequest = new EditCommandRequestWrapper(new DestroyElementRequest(false));
+ Command command = target.getCommand(deleteViewRequest);
+ assertNotNull(DESTROY_DELETION + COMMAND_NULL, command);
+ assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
+ assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
+ getEMFCommandStack().execute(new GEFtoEMFCommandWrapper(command));
+
+ assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, execSpec1.getGeneralOrderings().size() == 0);
+ assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, execSpec2.getGeneralOrderings().size() == 0);
+ }
+
+ public void createNode(IElementType type, GraphicalEditPart parent, Point location, Dimension size) {
+ //CREATION
+ CreateViewRequest requestcreation = CreateViewRequestFactory.getCreateShapeRequest(type, getRootEditPart().getDiagramPreferencesHint());
+ requestcreation.setLocation(location);
+ requestcreation.setSize(size);
+ Command command = parent.getCommand(requestcreation);
+ assertNotNull(CREATION + COMMAND_NULL, command);
+ assertTrue(CREATION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
+ assertTrue(CREATION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
+
+ getDiagramCommandStack().execute(command);
+ }
+
+ public void createLink(IElementType linkType, EditPart source, EditPart target, Point sourcePoint, Point targetPoint) {
+ CreateConnectionViewRequest req = createConnectionViewRequest(linkType, source, target, sourcePoint, targetPoint);
+ Command command = target.getCommand(req);
+ assertNotNull(CREATION + COMMAND_NULL, command);
+ assertTrue(CONTAINER_CREATION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
+
+ getDiagramCommandStack().execute(command);
+ }
+
+ CreateConnectionViewRequest createConnectionViewRequest(IElementType type, EditPart source, EditPart target, Point sourcePoint, Point targetPoint) {
+ CreateConnectionViewRequest connectionRequest = CreateViewRequestFactory.getCreateConnectionRequest(type, ((IGraphicalEditPart)getDiagramEditPart()).getDiagramPreferencesHint());
+ connectionRequest.setLocation(sourcePoint);
+
+ connectionRequest.setSourceEditPart(null);
+ connectionRequest.setTargetEditPart(source);
+ connectionRequest.setType(RequestConstants.REQ_CONNECTION_START);
+ Command cmd = source.getCommand(connectionRequest);
+
+ // get the connection end command
+ connectionRequest.setSourceEditPart(source);
+ connectionRequest.setTargetEditPart(target);
+ connectionRequest.setType(RequestConstants.REQ_CONNECTION_END);
+ connectionRequest.setLocation(targetPoint);
+
+ EObject container = getRootEditPart().resolveSemanticElement();
+ connectionRequest.getExtendedData().put(SOURCE_MODEL_CONTAINER, container);
+ connectionRequest.getExtendedData().put(TARGET_MODEL_CONTAINER, container);
+ return connectionRequest;
+ }
+
+}