Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2013-08-06 13:20:13 +0000
committerCamille Letavernier2013-08-06 13:20:13 +0000
commite1b47da134dd0430946f669b0586d28d0a41e235 (patch)
treebd31197946c054c74a188f2e7c47b80be1c36810
parente345c35bf9d7f31d98d10486a4983d0bc3b203be (diff)
downloadorg.eclipse.papyrus-e1b47da134dd0430946f669b0586d28d0a41e235.tar.gz
org.eclipse.papyrus-e1b47da134dd0430946f669b0586d28d0a41e235.tar.xz
org.eclipse.papyrus-e1b47da134dd0430946f669b0586d28d0a41e235.zip
389531: [Sequence Diagram] Graphical Presentation of Gate with In/Out
https://bugs.eclipse.org/bugs/show_bug.cgi?id=389531
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CustomMessage2CreateCommand.java13
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/GateCreationEditPolicy.java19
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java2
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/BugTest_m7.java2
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionEndsWithMessageOccurrenceSpecification.java266
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGateNameOnCombinedFragment.java158
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java5
8 files changed, 463 insertions, 4 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CustomMessage2CreateCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CustomMessage2CreateCommand.java
index 6ac14cb60ff..f03e7a90263 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CustomMessage2CreateCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/CustomMessage2CreateCommand.java
@@ -26,7 +26,10 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.commands.Message2CreateComm
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.UMLBaseItemSemanticEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.util.CommandHelper;
import org.eclipse.papyrus.uml.diagram.sequence.util.MessageConnectionHelper;
+import org.eclipse.papyrus.uml.diagram.sequence.util.OccurrenceSpecificationHelper;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
+import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.MessageSort;
@@ -107,6 +110,16 @@ public class CustomMessage2CreateCommand extends Message2CreateCommand {
return CommandResult.newErrorCommandResult("Failed to create message");
}
if(message != null) {
+ //Do reset message end to target ExecutionSpecification. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=402975
+ if(getTarget() instanceof ExecutionSpecification) {
+ OccurrenceSpecificationHelper.resetExecutionStart((ExecutionSpecification)getTarget(), message.getReceiveEvent());
+ }
+ if(getSource() instanceof ExecutionOccurrenceSpecification) {
+ ExecutionSpecification execution = ((ExecutionOccurrenceSpecification)getSource()).getExecution();
+ if(execution != null) {
+ OccurrenceSpecificationHelper.resetExecutionStart(execution, message.getSendEvent());
+ }
+ }
doConfigure(message, monitor, info);
((CreateElementRequest)getRequest()).setNewElement(message);
return CommandResult.newOKCommandResult(message);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/GateCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/GateCreationEditPolicy.java
index 9536a99bb1b..db87fa6bae2 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/GateCreationEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/GateCreationEditPolicy.java
@@ -13,6 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
+import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Point;
@@ -33,6 +34,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.GateEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.locator.GateLocator;
import org.eclipse.papyrus.uml.diagram.sequence.util.GateHelper;
+import org.eclipse.swt.widgets.Control;
/**
* @author Jin Liu (jin.liu@soyatec.com)
@@ -112,6 +114,23 @@ public class GateCreationEditPolicy extends LayoutEditPolicy {
Rectangle rect = locator.getValidLocation(proposedLocation, gateFeedback);
getHostFigure().translateToAbsolute(rect);
gateFeedback.translateToRelative(rect);
+ if(rect.x < 0 || rect.y < 0) {
+ // Try to fixed the bug about shaking when the feedback outside the viewer bounds.
+ // Now just display half-width of the normal rectangle.
+ Control control = getHost().getViewer().getControl();
+ if(control instanceof FigureCanvas) {
+ int hv = ((FigureCanvas)control).getViewport().getHorizontalRangeModel().getValue();
+ if(rect.x < 0 && hv >= 0) {
+ rect.x = 0;
+ rect.width = rect.width / 2;
+ }
+ int vv = ((FigureCanvas)control).getViewport().getVerticalRangeModel().getValue();
+ if(rect.y < 0 && vv >= 0) {
+ rect.y = 0;
+ rect.height = rect.height / 2;
+ }
+ }
+ }
gateFeedback.setBounds(rect);
Point location = rect.getLocation().getCopy();
gateFeedback.translateToAbsolute(location);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java
index 06c6fa43968..73eb786060b 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java
@@ -773,6 +773,8 @@ public class CommandHelper {
endMsg = doCreateMessageOccurrence(interactionFragment, event, lifeline);
} else if(element instanceof Interaction || element instanceof CombinedFragment || element instanceof InteractionUse) {
endMsg = doCreateGate(element, direction);
+ } else if(element instanceof ExecutionOccurrenceSpecification) {
+ endMsg = createMessageEnd(interactionFragment, event, ((ExecutionOccurrenceSpecification)element).getExecution(), direction);
}
return endMsg;
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java
index 23dc3c702eb..83e428f45c3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java
@@ -145,7 +145,7 @@ public class LifelineCoveredByUpdater {
}
int heightDelta = newHeight - height;
CommandHelper.executeCommandWithoutHistory(editingDomain, SetCommand.create(editingDomain, bounds, NotationPackage.Literals.SIZE__HEIGHT, newHeight), true);
- PreserveAnchorsPositionCommandEx preserveAnchorsCommand = new PreserveAnchorsPositionCommandEx(lifelineEditpart, new Dimension(0, heightDelta), PreserveAnchorsPositionCommandEx.PRESERVE_Y, lifelineEditpart.getPrimaryShape(), PositionConstants.SOUTH);
+ PreserveAnchorsPositionCommandEx preserveAnchorsCommand = new PreserveAnchorsPositionCommandEx(lifelineEditpart, new Dimension(0, heightDelta), PreserveAnchorsPositionCommandEx.PRESERVE_Y, lifelineEditpart.getPrimaryShape().getFigureLifelineDotLineFigure(), PositionConstants.SOUTH);
if(preserveAnchorsCommand.canExecute()) {
CommandHelper.executeCommandWithoutHistory(editingDomain, new GMFtoEMFCommandWrapper(preserveAnchorsCommand), true);
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/BugTest_m7.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/BugTest_m7.java
index 7d5e4501787..9412acafa0a 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/BugTest_m7.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/BugTest_m7.java
@@ -21,6 +21,6 @@ import org.junit.runners.Suite.SuiteClasses;
* @author Jin Liu (jin.liu@soyatec.com)
*/
@RunWith(Suite.class)
-@SuiteClasses({ TestDurationConstraint_402967.class, TestElementIcon_396799.class, TestExecutionSpecificationPosition_395462.class, TestGraphicalGate_389531.class, TestGuardVisibility_402966.class, TestInteractionUseInCombinedFragment_402971.class, TestMessageCreateWithLifeline_403134.class, TestResizeStateInvariant_395774.class, TestTooltip_402964.class, TestMessageOccurrenceSpecification_402975.class, TestMakeSameHeightForLifelines_402978.class, TestMoveAnchorInsideCoRegion_402970.class, TestMoveMessageLostFound_403138.class, TestOrderingFragments_403233.class, TestShiftEnclosingMessageInOperand_402969.class })
+@SuiteClasses({ TestDurationConstraint_402967.class, TestElementIcon_396799.class, TestExecutionSpecificationPosition_395462.class, TestGraphicalGate_389531.class, TestGuardVisibility_402966.class, TestInteractionUseInCombinedFragment_402971.class, TestMessageCreateWithLifeline_403134.class, TestResizeStateInvariant_395774.class, TestTooltip_402964.class, TestMessageOccurrenceSpecification_402975.class, TestMakeSameHeightForLifelines_402978.class, TestMoveAnchorInsideCoRegion_402970.class, TestMoveMessageLostFound_403138.class, TestOrderingFragments_403233.class, TestShiftEnclosingMessageInOperand_402969.class, TestGateNameOnCombinedFragment.class, TestExecutionEndsWithMessageOccurrenceSpecification.class })
public class BugTest_m7 {
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionEndsWithMessageOccurrenceSpecification.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionEndsWithMessageOccurrenceSpecification.java
new file mode 100644
index 00000000000..ecef169e85d
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionEndsWithMessageOccurrenceSpecification.java
@@ -0,0 +1,266 @@
+/*****************************************************************************
+ * Copyright (c) 2013 CEA
+ *
+ *
+ * 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:
+ * Soyatec - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
+
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractMessageEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ExecutionSpecificationEndEditPart;
+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.util.SequenceUtil;
+import org.eclipse.uml2.uml.ExecutionSpecification;
+import org.eclipse.uml2.uml.Message;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
+import org.junit.Test;
+
+
+/**
+ * Test Execution ends(one is MessageOccurrenceSpecification of linked message) when the message reconnected or deleted.
+ *
+ * @author Jin Liu (jin.liu@soyatec.com)
+ */
+public class TestExecutionEndsWithMessageOccurrenceSpecification extends AbstractNodeTest {
+
+ private AbstractExecutionSpecificationEditPart createExecutionSpecificationWithLifeline(Point lifelineLocation, Dimension executionSize) {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), lifelineLocation, null);
+ assertNotNull("create ExecutionSpecification's Lifeline", lifeline);
+ AbstractExecutionSpecificationEditPart es = (AbstractExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline, getAbsoluteBounds(lifeline).getCenter(), executionSize);
+ assertNotNull("create ExecutionSpecification", es);
+ return es;
+ }
+
+ @SuppressWarnings("rawtypes")
+ private ExecutionSpecificationEndEditPart findEndEditPart(AbstractExecutionSpecificationEditPart parent, boolean startEnd) {
+ if(parent == null) {
+ return null;
+ }
+ ExecutionSpecification execution = (ExecutionSpecification)parent.resolveSemanticElement();
+ OccurrenceSpecification end = startEnd ? execution.getStart() : execution.getFinish();
+ List children = parent.getChildren();
+ for(Object object : children) {
+ if(object instanceof ExecutionSpecificationEndEditPart && ((ExecutionSpecificationEndEditPart)object).resolveSemanticElement() == end) {
+ return (ExecutionSpecificationEndEditPart)object;
+ }
+ }
+ return null;
+ }
+
+ private void checkExecutionEnds(ExecutionSpecification execution, OccurrenceSpecification start, OccurrenceSpecification finish) {
+ checkExecutionValid(execution);
+ assertNotNull("start", start);
+ assertNotNull("finish", finish);
+ assertEquals("execution start", start, execution.getStart());
+ assertEquals("execution finish", finish, execution.getFinish());
+ }
+
+ private void checkExecutionValid(ExecutionSpecification execution) {
+ assertNotNull("execution", execution);
+ assertNotNull("start", execution.getStart());
+ assertNotNull("finish", execution.getFinish());
+ }
+
+ @Test
+ public void testReconnectSourceToExecution() {
+ AbstractExecutionSpecificationEditPart execution1 = createExecutionSpecificationWithLifeline(new Point(100, 100), null);
+ AbstractExecutionSpecificationEditPart execution2 = createExecutionSpecificationWithLifeline(new Point(300, 100), null);
+ //1. create message: execution1.start ----message----> execution2
+ ExecutionSpecificationEndEditPart source = findEndEditPart(execution1, true);
+ AbstractMessageEditPart message = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, execution1.getViewer(), SequenceUtil.getAbsoluteBounds(execution1).getTop(), source, SequenceUtil.getAbsoluteBounds(execution2).getCenter(), execution2);
+ assertNotNull("Message", message);
+ Message umlMsg = (Message)message.resolveSemanticElement();
+ ExecutionSpecification umlExecution = (ExecutionSpecification)execution1.resolveSemanticElement();
+ // result: execution1.start == message.sendEvent
+ checkExecutionEnds(umlExecution, (OccurrenceSpecification)umlMsg.getSendEvent(), umlExecution.getFinish());
+
+ //2. reconnect message: execution1 ----message----> execution2
+ reconnectSource(message, execution1, SequenceUtil.getAbsoluteBounds(execution1).getCenter().getTranslated(0, -5));
+ // result: execution1.start != message.sendEvent && execution1.start = executionOccurrenceSpecification
+ checkExecutionValid(umlExecution);
+ assertNotSame("should not same: execution start", umlMsg.getSendEvent(), umlExecution.getStart());
+ assertNotSame("should not same: execution finish", umlMsg.getSendEvent(), umlExecution.getFinish());
+
+ //3. reconnect message: execution1.finish ----message----> execution2
+ reconnectSource(message, findEndEditPart(execution1, false), SequenceUtil.getAbsoluteBounds(execution1).getBottom());
+ //result: execution1.finish = message.sendEvent
+ checkExecutionEnds(umlExecution, umlExecution.getStart(), (OccurrenceSpecification)umlMsg.getSendEvent());
+
+ //4. REPEAT: reconnect message : execution1 ----message----> execution2
+ reconnectSource(message, execution1, SequenceUtil.getAbsoluteBounds(execution1).getCenter().getTranslated(0, -5));
+ // result: execution1.start != message.sendEvent && execution1.start = executionOccurrenceSpecification
+ checkExecutionValid(umlExecution);
+ assertNotSame("should not same: execution start", umlMsg.getSendEvent(), umlExecution.getStart());
+ assertNotSame("should not same: execution finish", umlMsg.getSendEvent(), umlExecution.getFinish());
+ }
+
+ @Test
+ public void testReconnectTargetToExecution() {
+ AbstractExecutionSpecificationEditPart execution1 = createExecutionSpecificationWithLifeline(new Point(100, 100), null);
+ AbstractExecutionSpecificationEditPart execution2 = createExecutionSpecificationWithLifeline(new Point(300, 100), null);
+ //1. create message: execution1 ----message----> execution2.start
+ ExecutionSpecificationEndEditPart target = findEndEditPart(execution2, true);
+ AbstractMessageEditPart message = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, execution1.getViewer(), SequenceUtil.getAbsoluteBounds(execution1).getCenter(), execution1, SequenceUtil.getAbsoluteBounds(execution2).getTop(), target);
+ assertNotNull("Message", message);
+ Message umlMsg = (Message)message.resolveSemanticElement();
+ ExecutionSpecification umlExecution = (ExecutionSpecification)execution2.resolveSemanticElement();
+ // result: execution2.start == message.receiveEvent
+ checkExecutionEnds(umlExecution, (OccurrenceSpecification)umlMsg.getReceiveEvent(), umlExecution.getFinish());
+
+ //2. reconnect message: execution1 ----message----> execution2
+ reconnectTarget(message, execution2, SequenceUtil.getAbsoluteBounds(execution2).getCenter().getTranslated(0, 5));
+ // result: execution2.start != message.receiveEvent && execution2.start = executionOccurrenceSpecification
+ // result: execution2.finish != message.receiveEvent && execution2.finish = executionOccurrenceSpecification
+ checkExecutionValid(umlExecution);
+ assertNotSame("should not same: execution start", umlMsg.getReceiveEvent(), umlExecution.getStart());
+ assertNotSame("should not same: execution finish", umlMsg.getReceiveEvent(), umlExecution.getFinish());
+
+ //3. reconnect message: execution1 ----message----> execution2.finish
+ reconnectTarget(message, findEndEditPart(execution2, false), SequenceUtil.getAbsoluteBounds(execution2).getBottom());
+ //result: execution2.finish = message.receiveEvent
+ checkExecutionEnds(umlExecution, umlExecution.getStart(), (OccurrenceSpecification)umlMsg.getReceiveEvent());
+
+ //4. REPEAT: reconnect message : execution1 ----message----> execution2
+ reconnectTarget(message, execution2, SequenceUtil.getAbsoluteBounds(execution2).getCenter().getTranslated(0, 5));
+ // result: execution2.start != message.receiveEvent && execution2.start = executionOccurrenceSpecification
+ // result: execution2.finish != message.receiveEvent && execution2.finish = executionOccurrenceSpecification
+ checkExecutionValid(umlExecution);
+ assertNotSame("should not same: execution start", umlMsg.getReceiveEvent(), umlExecution.getStart());
+ assertNotSame("should not same: execution finish", umlMsg.getReceiveEvent(), umlExecution.getFinish());
+
+ }
+
+ @Test
+ public void testReconnectSourceToChildExecution() {
+ AbstractExecutionSpecificationEditPart execution1 = createExecutionSpecificationWithLifeline(new Point(100, 100), new Dimension(16, 80));
+ AbstractExecutionSpecificationEditPart execution2 = createExecutionSpecificationWithLifeline(new Point(300, 100), new Dimension(16, 150));
+ AbstractExecutionSpecificationEditPart execution3 = (AbstractExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, execution1.getParent(), SequenceUtil.getAbsoluteBounds(execution1).getCenter(), null);
+ //1. create message: execution1.start ----message----> execution2
+ ExecutionSpecificationEndEditPart source = findEndEditPart(execution1, true);
+ AbstractMessageEditPart message = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, execution1.getViewer(), SequenceUtil.getAbsoluteBounds(execution1).getTop(), source, SequenceUtil.getAbsoluteBounds(execution2).getCenter(), execution2);
+ assertNotNull("Message", message);
+ Message umlMsg = (Message)message.resolveSemanticElement();
+ ExecutionSpecification umlExecution = (ExecutionSpecification)execution1.resolveSemanticElement();
+ // result: execution1.start == message.sendEvent
+ checkExecutionEnds(umlExecution, (OccurrenceSpecification)umlMsg.getSendEvent(), umlExecution.getFinish());
+
+ //2. reconnect message: execution3 ----message----> execution2
+ reconnectSource(message, execution3, SequenceUtil.getAbsoluteBounds(execution3).getCenter());
+ //result: execution1.start != message.sendEvent
+ checkExecutionValid(umlExecution);
+ assertNotSame("should not same: execution start", umlMsg.getSendEvent(), umlExecution.getStart());
+ }
+
+ @Test
+ public void testReconnectTargetToChildExecution() {
+ AbstractExecutionSpecificationEditPart execution1 = createExecutionSpecificationWithLifeline(new Point(100, 100), new Dimension(16, 100));
+ AbstractExecutionSpecificationEditPart execution2 = createExecutionSpecificationWithLifeline(new Point(300, 100), new Dimension(16, 80));
+ AbstractExecutionSpecificationEditPart execution3 = (AbstractExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, execution1.getParent(), SequenceUtil.getAbsoluteBounds(execution1).getCenter(), null);
+ //1. create message: execution2 ----message----> execution1.start
+ ExecutionSpecificationEndEditPart target = findEndEditPart(execution1, true);
+ AbstractMessageEditPart message = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, execution1.getViewer(), SequenceUtil.getAbsoluteBounds(execution2).getCenter(), execution2, SequenceUtil.getAbsoluteBounds(execution1).getTop(), target);
+ assertNotNull("Message", message);
+ Message umlMsg = (Message)message.resolveSemanticElement();
+ ExecutionSpecification umlExecution = (ExecutionSpecification)execution1.resolveSemanticElement();
+ // result: execution1.start == message.receiveEvent
+ checkExecutionEnds(umlExecution, (OccurrenceSpecification)umlMsg.getReceiveEvent(), umlExecution.getFinish());
+
+ //2. reconnect message: execution2 ----message----> execution3
+ reconnectTarget(message, execution3, SequenceUtil.getAbsoluteBounds(execution3).getCenter());
+ //result: execution1.start != message.receiveEvent
+ checkExecutionValid(umlExecution);
+ assertNotSame("should not same: execution start", umlMsg.getReceiveEvent(), umlExecution.getStart());
+ }
+
+ @Test
+ public void testDeleteMessage() {
+ AbstractExecutionSpecificationEditPart execution1 = createExecutionSpecificationWithLifeline(new Point(100, 100), null);
+ AbstractExecutionSpecificationEditPart execution2 = createExecutionSpecificationWithLifeline(new Point(300, 100), null);
+ //1. create message: execution1.start ----message----> execution2.start
+ ExecutionSpecificationEndEditPart source = findEndEditPart(execution1, true);
+ ExecutionSpecificationEndEditPart target = findEndEditPart(execution2, true);
+ AbstractMessageEditPart message = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, execution1.getViewer(), SequenceUtil.getAbsoluteBounds(execution1).getTop(), source, SequenceUtil.getAbsoluteBounds(execution2).getTop(), target);
+ assertNotNull("Message", message);
+ Message umlMsg = (Message)message.resolveSemanticElement();
+ ExecutionSpecification umlExecution1 = (ExecutionSpecification)execution1.resolveSemanticElement();
+ ExecutionSpecification umlExecution2 = (ExecutionSpecification)execution2.resolveSemanticElement();
+ checkExecutionEnds(umlExecution1, (OccurrenceSpecification)umlMsg.getSendEvent(), umlExecution1.getFinish());
+ checkExecutionEnds(umlExecution2, (OccurrenceSpecification)umlMsg.getReceiveEvent(), umlExecution2.getFinish());
+
+ //2. delete the message
+ GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
+ deleteReq.setEditParts(message);
+ Command command = message.getCommand(deleteReq);
+ assertNotNull("delete command", command);
+ assertTrue("command can be executed", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ checkExecutionValid(umlExecution1);
+ checkExecutionValid(umlExecution2);
+ }
+
+ @Test
+ public void testDeleteSourceExecution() {
+ AbstractExecutionSpecificationEditPart execution1 = createExecutionSpecificationWithLifeline(new Point(100, 100), null);
+ AbstractExecutionSpecificationEditPart execution2 = createExecutionSpecificationWithLifeline(new Point(300, 100), null);
+ //1. create message: execution1.start ----message----> execution2.start
+ ExecutionSpecificationEndEditPart source = findEndEditPart(execution1, true);
+ ExecutionSpecificationEndEditPart target = findEndEditPart(execution2, true);
+ AbstractMessageEditPart message = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, execution1.getViewer(), SequenceUtil.getAbsoluteBounds(execution1).getTop(), source, SequenceUtil.getAbsoluteBounds(execution2).getTop(), target);
+ assertNotNull("Message", message);
+ Message umlMsg = (Message)message.resolveSemanticElement();
+ ExecutionSpecification umlExecution1 = (ExecutionSpecification)execution1.resolveSemanticElement();
+ ExecutionSpecification umlExecution2 = (ExecutionSpecification)execution2.resolveSemanticElement();
+ checkExecutionEnds(umlExecution1, (OccurrenceSpecification)umlMsg.getSendEvent(), umlExecution1.getFinish());
+ checkExecutionEnds(umlExecution2, (OccurrenceSpecification)umlMsg.getReceiveEvent(), umlExecution2.getFinish());
+
+ //2. delete execution1
+ GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
+ deleteReq.setEditParts(execution1);
+ Command command = execution1.getCommand(deleteReq);
+ assertNotNull("delete command", command);
+ assertTrue("command can be executed", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ checkExecutionValid(umlExecution2);
+ }
+
+ @Test
+ public void testDeleteTargetExecution() {
+ AbstractExecutionSpecificationEditPart execution1 = createExecutionSpecificationWithLifeline(new Point(100, 100), null);
+ AbstractExecutionSpecificationEditPart execution2 = createExecutionSpecificationWithLifeline(new Point(300, 100), null);
+ //1. create message: execution1.start ----message----> execution2.start
+ ExecutionSpecificationEndEditPart source = findEndEditPart(execution1, true);
+ ExecutionSpecificationEndEditPart target = findEndEditPart(execution2, true);
+ AbstractMessageEditPart message = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, execution1.getViewer(), SequenceUtil.getAbsoluteBounds(execution1).getTop(), source, SequenceUtil.getAbsoluteBounds(execution2).getTop(), target);
+ assertNotNull("Message", message);
+ Message umlMsg = (Message)message.resolveSemanticElement();
+ ExecutionSpecification umlExecution1 = (ExecutionSpecification)execution1.resolveSemanticElement();
+ ExecutionSpecification umlExecution2 = (ExecutionSpecification)execution2.resolveSemanticElement();
+ checkExecutionEnds(umlExecution1, (OccurrenceSpecification)umlMsg.getSendEvent(), umlExecution1.getFinish());
+ checkExecutionEnds(umlExecution2, (OccurrenceSpecification)umlMsg.getReceiveEvent(), umlExecution2.getFinish());
+
+ //2. delete execution2
+ GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
+ deleteReq.setEditParts(execution2);
+ Command command = execution2.getCommand(deleteReq);
+ assertNotNull("delete command", command);
+ assertTrue("command can be executed", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ checkExecutionValid(umlExecution1);
+ }
+}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGateNameOnCombinedFragment.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGateNameOnCombinedFragment.java
index 7edb464079d..b10eaec987f 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGateNameOnCombinedFragment.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGateNameOnCombinedFragment.java
@@ -13,15 +13,29 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
+import java.util.List;
+
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gef.requests.CreationFactory;
+import org.eclipse.gef.requests.DirectEditRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractMessageEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.GateEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.figures.MessageFigure;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.GateHelper;
+import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceRequestConstant;
import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
import org.eclipse.uml2.uml.CombinedFragment;
import org.eclipse.uml2.uml.Gate;
@@ -109,4 +123,148 @@ public class TestGateNameOnCombinedFragment extends AbstractNodeTest {
Message message = (Message)messageEditPart.resolveSemanticElement();
assertEquals("Gate name", gateNamePrefix + message.getLabel(), gate.getLabel());
}
+
+ @Test
+ public void testUncoveredLifeline2CombinedFragmentGate() {
+ testFixedGateName("Gate0", false, true);
+ }
+
+
+ @Test
+ public void testCoveredLifeline2CombinedFragmentGate() {
+ testFixedGateName("Gate1", true, true);
+ }
+
+ @Test
+ public void testCombinedFragmentGate2CoveredLifeline() {
+ testFixedGateName("Gate2", true, false);
+ }
+
+ @Test
+ public void testCombinedFragmentGate2UncoveredLifeline() {
+ testFixedGateName("Gate3", false, false);
+ }
+
+ private GateEditPart createGate(EditPart parent, Point location) {
+ CreateRequest request = new CreateRequest(RequestConstants.REQ_CREATE);
+ request.setFactory(new CreationFactory() {
+
+ public Object getObjectType() {
+ return GateEditPart.GATE_TYPE;
+ }
+
+ public Object getNewObject() {
+ return GateEditPart.GATE_TYPE;
+ }
+ });
+ request.setLocation(location);
+ Command command = parent.getCommand(request);
+ assertNotNull("create gate command", command);
+ assertTrue("executable of create gate command", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ GateEditPart gateEditPart = getPrimaryGateEditPart(parent);
+ assertNotNull("created gate", gateEditPart);
+ return gateEditPart;
+ }
+
+ protected GateEditPart getPrimaryGateEditPart(EditPart parent) {
+ @SuppressWarnings("rawtypes")
+ List children = parent.getChildren();
+ for(int i = children.size() - 1; i >= 0; i--) {
+ Object child = children.get(i);
+ if(child instanceof GateEditPart) {
+ GateEditPart gateEp = (GateEditPart)child;
+ Gate gate = (Gate)gateEp.resolveSemanticElement();
+ if(!(GateHelper.isInnerCFGate(gate))) {
+ return gateEp;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected EditPart createLink(IElementType elementType, EditPartViewer currentViewer, Point startLocation, EditPart sourceEditPart, Point endLocation, EditPart targetEditPart) {
+ final EditPart linkEditPart = super.createLink(elementType, currentViewer, startLocation, sourceEditPart, endLocation, targetEditPart);
+ if(linkEditPart instanceof AbstractMessageEditPart) {
+ currentViewer.setSelection(new StructuredSelection(linkEditPart));
+ waitForComplete();
+ performFirstDirectEdit((AbstractMessageEditPart)linkEditPart);
+ }
+ return linkEditPart;
+ }
+
+ /**
+ * Emulate a direct edit after creation like use the palette tool.
+ */
+ @SuppressWarnings({ "unchecked" })
+ private void performFirstDirectEdit(AbstractMessageEditPart messageEditPart) {
+ MessageFigure primaryShape = messageEditPart.getPrimaryShape();
+ WrappingLabel label = primaryShape.getMessageLabelFigure();
+ DirectEditRequest req = new DirectEditRequest();
+ Rectangle b = label.getBounds().getCopy();
+ label.translateToAbsolute(b);
+ req.setLocation(b.getCenter());
+ req.getExtendedData().put(SequenceRequestConstant.DIRECT_EDIT_AFTER_CREATION, true);
+ messageEditPart.performRequest(req);
+
+ waitForComplete();
+
+ //Deactive the Popup Editor.
+ messageEditPart.getViewer().getControl().setFocus();
+ waitForComplete();
+ }
+
+ private void testFixedGateName(String gateName, boolean lifelineCovered, boolean messageFromLifeline2Gate) {
+ //1. Create CombinedFragment
+ CombinedFragmentEditPart cfEditPart = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(100, 200), null);
+ assertNotNull("CombinedFragment creation", cfEditPart);
+ //1.1 Create Gate on CombinedFragment
+ Rectangle cfBounds = SequenceUtil.getAbsoluteBounds(cfEditPart);
+ GateEditPart gateEditPart = createGate(cfEditPart, new Point(cfBounds.right() - 1, cfBounds.y + cfBounds.height / 2));
+ assertNotNull("Gate on CombinedFragment creation", gateEditPart);
+
+ Gate gate = (Gate)((GateEditPart)gateEditPart).resolveSemanticElement();
+ changeName(getEditingDomain(), gate, gateName);
+ assertEquals("Check gate name when creation", gateName, gate.getLabel());
+ //2. Create Lifeline
+ //Create a Lifeline which is covered by the CombinedFragment
+ Point lifelineLocation = new Point(0, 100);
+ if(lifelineCovered) {
+ lifelineLocation.x = cfBounds.getCenter().x;
+ } else {
+ lifelineLocation.x = cfBounds.getRight().x + 100;
+ }
+ LifelineEditPart lifelineEp = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), lifelineLocation, null);
+ assertNotNull("Lifeline Creation", lifelineEp);
+
+ //3. Check covered.
+ CombinedFragment combinedFragment = (CombinedFragment)cfEditPart.resolveSemanticElement();
+ Lifeline lifeline = (Lifeline)lifelineEp.resolveSemanticElement();
+ if(lifelineCovered) {
+ assertTrue("lifeline is covered by combinedFragment", lifeline.getCoveredBys().contains(combinedFragment));
+ } else {
+ assertTrue("lifeline is not covered by combinedFragment", !lifeline.getCoveredBys().contains(combinedFragment));
+ }
+
+ //4. Create Message between Lifeline and CombinedFragment.
+ EditPart source = null, target = null;
+ Point startLocation = null, targetLocation = null;
+ if(messageFromLifeline2Gate) {
+ source = lifelineEp;
+ target = gateEditPart;
+ targetLocation = SequenceUtil.getAbsoluteBounds(gateEditPart).getRight().getCopy();
+ startLocation = SequenceUtil.getAbsoluteBounds(lifelineEp).getCenter().setY(targetLocation.y);
+ } else {
+ source = gateEditPart;
+ startLocation = SequenceUtil.getAbsoluteBounds(gateEditPart).getRight().getCopy();
+ target = lifelineEp;
+ targetLocation = SequenceUtil.getAbsoluteBounds(lifelineEp).getCenter().setY(startLocation.y);
+ }
+ AbstractMessageEditPart messageEditPart = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, cfEditPart.getViewer(), startLocation, source, targetLocation, target);
+ assertNotNull("Message creation between Lifeline and Gate of CombinedFragment", messageEditPart);
+
+ //5. Check Gate name
+ assertEquals("Check gate name after message creation", gateName, gate.getLabel());
+ }
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java
index 369340cd67d..76d4c0c65a9 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java
@@ -64,7 +64,7 @@ public class TestGraphicalGate_389531 extends AbstractNodeTest {
protected String getFileName() {
return ISequenceDiagramTestsConstants.FILE_NAME;
}
-
+
private GateEditPart createGate(EditPart parent, Point location) {
CreateRequest request = new CreateRequest(RequestConstants.REQ_CREATE);
request.setFactory(new CreationFactory() {
@@ -368,7 +368,8 @@ public class TestGraphicalGate_389531 extends AbstractNodeTest {
Gate gate2 = (Gate)message2.getReceiveEvent();
GateEditPart gate2EditPart = getGateEditPart(interaction, gate2);
assertNotNull("Gate created", gate2EditPart);
- assertEquals("Gate name", "out_" + message2.getName(), getGateName(gate2EditPart));
+ //the name of gate on Interaction will not be changed.
+ assertEquals("Gate name", gate2.getName(), getGateName(gate2EditPart));
}
/**

Back to the top