Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2017-11-17 13:54:31 +0000
committerPatrick Tessier2018-01-10 16:00:49 +0000
commitc09f5b3d9dfd349e188960c7769565ee42ecf113 (patch)
treec44a53a5eecda84b1d5ec92d9b82682e091dd191
parentc8e5b1b89bea5d91c47437fa7f0c45c64edf8896 (diff)
downloadorg.eclipse.papyrus-c09f5b3d9dfd349e188960c7769565ee42ecf113.tar.gz
org.eclipse.papyrus-c09f5b3d9dfd349e188960c7769565ee42ecf113.tar.xz
org.eclipse.papyrus-c09f5b3d9dfd349e188960c7769565ee42ecf113.zip
Bug 527333 - [Sequence Diagram] Some error exist in event replacement
for execution specification https://bugs.eclipse.org/bugs/show_bug.cgi?id=527333 - event replacement for exec spec event at message reconnect Change-Id: I70d93aeaf759aff188011307a22db5188a2fcaa9 Signed-off-by: Mickael ADAM <mickael.adam@all4tec.net>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/ReplaceExecSpecEventAtReconnectCommand.java105
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java58
2 files changed, 161 insertions, 2 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/ReplaceExecSpecEventAtReconnectCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/ReplaceExecSpecEventAtReconnectCommand.java
new file mode 100644
index 00000000000..c730ebf09aa
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/command/ReplaceExecSpecEventAtReconnectCommand.java
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.sequence.command;
+
+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.emf.ecore.EReference;
+import org.eclipse.emf.edit.command.DeleteCommand;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.requests.ReconnectRequest;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
+import org.eclipse.uml2.uml.Message;
+import org.eclipse.uml2.uml.MessageEnd;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ * The command to replace execution specification start/finish event when a message is drag to it.
+ *
+ * @since 5.0.0
+ */
+public class ReplaceExecSpecEventAtReconnectCommand extends AbstractTransactionalCommand {
+ /**
+ * The reconnect message.
+ */
+ private final ReconnectRequest request;
+
+ /**
+ * The {@link OccurrenceSpecification} to be replaced.
+ */
+ private final OccurrenceSpecification os;
+
+ /**
+ * Set to true if it is a reconnect source, false for reconnect target.
+ */
+ private boolean source;
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * The {@link TransactionalEditingDomain}.
+ * @param request
+ * The {@link ReconnectRequest}.
+ * @param os
+ * the {@link OccurrenceSpecification}.
+ * @param source
+ * True if it is a reconnect source, false for reconnect target.
+ */
+ public ReplaceExecSpecEventAtReconnectCommand(final TransactionalEditingDomain domain, final ReconnectRequest request, final OccurrenceSpecification os, final boolean source) {
+ super(domain, "replace execution specification event command", null);
+ this.request = request;
+ this.os = os;
+ this.source = source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
+ // get the message
+ EObject message = ((View) request.getConnectionEditPart().getModel()).getElement();
+ if (message instanceof Message) {
+ // get the correct event to set
+ MessageEnd eventToSet = source ? ((Message) message).getSendEvent() : ((Message) message).getReceiveEvent();
+
+ // get the feature to set of the exec spec
+ EReference executionSpecificationFeatureToSet = null;
+ if (((ExecutionOccurrenceSpecification) os).getExecution().getStart().equals(os)) {
+ executionSpecificationFeatureToSet = UMLPackage.eINSTANCE.getExecutionSpecification_Start();
+ } else {
+ executionSpecificationFeatureToSet = UMLPackage.eINSTANCE.getExecutionSpecification_Finish();
+ }
+
+ // replace the os event by the message event
+ SetCommand setCommand = new SetCommand(getEditingDomain(), ((ExecutionOccurrenceSpecification) os).getExecution(), executionSpecificationFeatureToSet, eventToSet);
+ setCommand.execute();
+
+ // delete the old os event
+ org.eclipse.emf.common.command.Command deleteCommand = DeleteCommand.create(getEditingDomain(), os);
+ if (deleteCommand != null && deleteCommand.canExecute()) {
+ getEditingDomain().getCommandStack().execute(deleteCommand);
+ }
+ }
+ return CommandResult.newOKCommandResult();
+ }
+} \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java
index 31d33495f56..cbe223e2d5d 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java
@@ -8,7 +8,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 519621, 519756, 526191
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 519621, 519756, 526191, 527333
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling;
@@ -56,6 +56,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil;
import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
import org.eclipse.papyrus.uml.diagram.sequence.command.CreateExecutionSpecificationWithMessage;
import org.eclipse.papyrus.uml.diagram.sequence.command.DropDestructionOccurenceSpecification;
+import org.eclipse.papyrus.uml.diagram.sequence.command.ReplaceExecSpecEventAtReconnectCommand;
import org.eclipse.papyrus.uml.diagram.sequence.draw2d.routers.MessageRouter;
import org.eclipse.papyrus.uml.diagram.sequence.edit.helpers.AnchorHelper;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CLifeLineEditPart;
@@ -656,6 +657,10 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol
protected Command getReconnectSourceCommand(final ReconnectRequest request) {
// Snap to grid the request location
request.setLocation(SequenceUtil.getSnappedLocation(getHost(), request.getLocation()));
+
+ // Display event
+ displayEvent.addFigureEvent(getHostFigure(), request.getLocation());
+
// Check if the target is lower than the source
Point targetLocation = SequenceUtil.getAbsoluteEdgeExtremity((ConnectionNodeEditPart) request.getConnectionEditPart(), false, true);
if (!isTargetLowerThanSource(request.getLocation().getCopy(), targetLocation)) {
@@ -677,7 +682,28 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol
}
}
- return getBasicGraphicalNodeEditPolicy().getCommand(request);
+ // Get the reconnect command
+ Command command = null;
+ // Check if we are in a start/finish of an exec spec
+ OccurrenceSpecification os = displayEvent.getActionExecutionSpecificationEvent(getHostFigure(), ((ReconnectRequest) request).getLocation());
+
+ if (os instanceof ExecutionOccurrenceSpecification) {
+ CompoundCommand compoundCommand = new CompoundCommand();
+ if (request.getLocation() != displayEvent.getRealEventLocation(request.getLocation())) {
+ request.setLocation(displayEvent.getRealEventLocation(request.getLocation()));
+ }
+ compoundCommand.add(getBasicGraphicalNodeEditPolicy().getCommand(request));
+ ReplaceExecSpecEventAtReconnectCommand replaceExecSpecEventAtReconnectCommand = new ReplaceExecSpecEventAtReconnectCommand(getEditingDomain(), request, os, true);
+ compoundCommand.add(new GMFtoGEFCommandWrapper(replaceExecSpecEventAtReconnectCommand));
+ command = compoundCommand;
+
+
+ } else if (os instanceof MessageEnd) {
+ // Event of Exec Spec have been already replaced. Only one message can be related to start or finish.
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ return null != command ? command : getBasicGraphicalNodeEditPolicy().getCommand(request);
}
/**
@@ -688,9 +714,13 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol
@Override
protected Command getReconnectTargetCommand(final ReconnectRequest request) {
Command command = null;
+
// Snap to grid the request location
request.setLocation(SequenceUtil.getSnappedLocation(getHost(), request.getLocation()));
+ // Display event
+ displayEvent.addFigureEvent(getHostFigure(), request.getLocation());
+
// Check if the target is lower than the source
Point sourceLocation = SequenceUtil.getAbsoluteEdgeExtremity((ConnectionNodeEditPart) request.getConnectionEditPart(), true);
if (!isTargetLowerThanSource(sourceLocation, request.getLocation().getCopy())) {
@@ -712,6 +742,16 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol
}
}
+ // Check if we are in a start/finish of an exec spec
+ OccurrenceSpecification os = displayEvent.getActionExecutionSpecificationEvent(getHostFigure(), ((ReconnectRequest) request).getLocation());
+ if (os instanceof ExecutionOccurrenceSpecification) {
+ // If we reconnect to a exec spec event, we maj position to it
+ if (request.getLocation() != displayEvent.getRealEventLocation(request.getLocation())) {
+ request.setLocation(displayEvent.getRealEventLocation(request.getLocation()));
+ }
+ }
+
+ // Get the original reconnect command
Command reconnectTargetCommand = getBasicGraphicalNodeEditPolicy().getCommand(request);
// in case of reconnect target for message create it is need to move up the old target and move down the new target
@@ -764,6 +804,20 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol
} else {
command = reconnectTargetCommand;
}
+
+
+ // get the command to replace event
+ if (os instanceof ExecutionOccurrenceSpecification) {
+ CompoundCommand compoundCommand = new CompoundCommand();
+ compoundCommand.add(command);
+ ReplaceExecSpecEventAtReconnectCommand replaceExecSpecEventAtReconnectCommand = new ReplaceExecSpecEventAtReconnectCommand(getEditingDomain(), request, os, false);
+ compoundCommand.add(new GMFtoGEFCommandWrapper(replaceExecSpecEventAtReconnectCommand));
+ command = compoundCommand;
+ } else if (os instanceof MessageEnd) {
+ // Event of Exec Spec have been already replaced. Only one message can be related to start or finish.
+ return UnexecutableCommand.INSTANCE;
+ }
+
return command;
}

Back to the top