Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-08-06 08:27:26 -0400
committerCamille Letavernier2018-09-24 06:48:41 -0400
commit080aa4b85d5c47eed8e4f2e37dc44463932bb8fc (patch)
tree3ec8a65f3ee6f422118cee834aa7926b20c33967
parent08c6860edce7dd0decb923d92208ebdfe05a329a (diff)
downloadorg.eclipse.papyrus-080aa4b85d5c47eed8e4f2e37dc44463932bb8fc.tar.gz
org.eclipse.papyrus-080aa4b85d5c47eed8e4f2e37dc44463932bb8fc.tar.xz
org.eclipse.papyrus-080aa4b85d5c47eed8e4f2e37dc44463932bb8fc.zip
Bug 536639: [Sequence Diagram] Support reconnect on Duration edit parts
https://bugs.eclipse.org/bugs/show_bug.cgi?id=536639 Change-Id: I4e918a51ed6a1e27407780deb0b576cb768caa05 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/OccurenceSemanticEditPolicy.java84
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/SemanticOccurrenceEditPolicyProvider.java58
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationUtil.java91
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/plugin.xml6
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java46
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationObservationEditHelperAdvice.java46
6 files changed, 270 insertions, 61 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/OccurenceSemanticEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/OccurenceSemanticEditPolicy.java
index d66ae19ab8e..25d7c2faac3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/OccurenceSemanticEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/OccurenceSemanticEditPolicy.java
@@ -13,7 +13,6 @@
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
-import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
@@ -24,13 +23,10 @@ import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.SemanticEditPolicy;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
-import org.eclipse.gmf.runtime.notation.Anchor;
import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.IdentityAnchor;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy;
-import org.eclipse.papyrus.uml.diagram.sequence.anchors.AnchorConstants;
+import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
import org.eclipse.papyrus.uml.diagram.sequence.util.GeneralOrderingUtil;
import org.eclipse.papyrus.uml.diagram.sequence.util.OccurrenceSpecificationUtil;
import org.eclipse.uml2.uml.ExecutionSpecification;
@@ -80,20 +76,36 @@ public class OccurenceSemanticEditPolicy extends DefaultSemanticEditPolicy {
}
protected boolean relationshipSourceHasChanged(ReconnectRequest request) {
- return getSourceOccurrence((Edge) request.getConnectionEditPart().getModel()) != getOccurrence(request);
+ if (!request.getConnectionEditPart().getSource().equals(request.getTarget())) {
+ // Connecting different edit parts
+ return true;
+ } else if (request.getConnectionEditPart().getModel() instanceof Edge) {
+ // Connecting different occurrences on the same edit part (Source vs Target, Start vs Finish...)
+ Edge edge = (Edge) request.getConnectionEditPart().getModel();
+ return OccurrenceSpecificationUtil.getSourceOccurrence(edge) != OccurrenceSpecificationUtil.getOccurrence(request);
+ }
+ return false;
}
protected boolean relationshipTargetHasChanged(ReconnectRequest request) {
- return getTargetOccurrence((Edge) request.getConnectionEditPart().getModel()) != getOccurrence(request);
+ if (!request.getConnectionEditPart().getTarget().equals(request.getTarget())) {
+ // Connecting different edit parts
+ return true;
+ } else if (request.getConnectionEditPart().getModel() instanceof Edge) {
+ // Connecting different occurrences on the same edit part (Source vs Target, Start vs Finish...)
+ Edge edge = (Edge) request.getConnectionEditPart().getModel();
+ return OccurrenceSpecificationUtil.getTargetOccurrence(edge) != OccurrenceSpecificationUtil.getOccurrence(request);
+ }
+ return false;
}
@Override
protected Command getReorientRelationshipSourceCommand(ReconnectRequest request) {
- if (GeneralOrderingUtil.isGeneralOrderingLink(request)) {
+ if (GeneralOrderingUtil.isGeneralOrderingLink(request) || DurationLinkUtil.isDurationLink(request)) {
EObject connectionSemElement = ViewUtil.resolveSemanticElement(((View) request.getConnectionEditPart()
.getModel()));
- EObject targetSemElement = getOccurrence(request);
- EObject oldSemElement = getSourceOccurrence((Edge) request.getConnectionEditPart().getModel());
+ EObject targetSemElement = OccurrenceSpecificationUtil.getOccurrence(request);
+ EObject oldSemElement = OccurrenceSpecificationUtil.getSourceOccurrence((Edge) request.getConnectionEditPart().getModel());
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
.getEditingDomain();
@@ -111,10 +123,10 @@ public class OccurenceSemanticEditPolicy extends DefaultSemanticEditPolicy {
@Override
protected Command getReorientRelationshipTargetCommand(ReconnectRequest request) {
- if (GeneralOrderingUtil.isGeneralOrderingLink(request)) {
+ if (GeneralOrderingUtil.isGeneralOrderingLink(request) || DurationLinkUtil.isDurationLink(request)) {
EObject connectionSemElement = ViewUtil.resolveSemanticElement((View) request.getConnectionEditPart().getModel());
- EObject targetSemElement = getOccurrence(request);
- EObject oldSemElement = getTargetOccurrence((Edge) request.getConnectionEditPart().getModel());
+ EObject targetSemElement = OccurrenceSpecificationUtil.getOccurrence(request);
+ EObject oldSemElement = OccurrenceSpecificationUtil.getTargetOccurrence((Edge) request.getConnectionEditPart().getModel());
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
.getEditingDomain();
@@ -130,50 +142,4 @@ public class OccurenceSemanticEditPolicy extends DefaultSemanticEditPolicy {
return super.getReorientRelationshipTargetCommand(request);
}
- private EObject getOccurrence(ReconnectRequest request) {
- EObject element = EMFHelper.getEObject(request.getTarget());
- IFigure targetFigure = ((IGraphicalEditPart) request.getTarget()).getFigure();
- if (element instanceof Message) {
- if (OccurrenceSpecificationUtil.isSource(targetFigure, request.getLocation())) {
- return ((Message) element).getSendEvent();
- } else {
- return ((Message) element).getReceiveEvent();
- }
- } else if (element instanceof ExecutionSpecification) {
- if (OccurrenceSpecificationUtil.isStart(targetFigure, request.getLocation())) {
- return ((ExecutionSpecification) element).getStart();
- } else {
- return ((ExecutionSpecification) element).getFinish();
- }
- }
- return element;
- }
-
- private EObject getTargetOccurrence(Edge connection) {
- return getOccurrence(connection.getTargetAnchor(), connection.getTarget());
- }
-
- private EObject getSourceOccurrence(Edge connection) {
- return getOccurrence(connection.getSourceAnchor(), connection.getSource());
- }
-
- private EObject getOccurrence(Anchor anchor, View targetElement) {
- String anchorId = ((IdentityAnchor) anchor).getId();
- EObject element = targetElement.getElement();
- if (AnchorConstants.END_TERMINAL.equals(anchorId)) {
- if (element instanceof Message) {
- return ((Message) element).getReceiveEvent();
- } else if (element instanceof ExecutionSpecification) {
- return ((ExecutionSpecification) element).getFinish();
- }
- } else if (AnchorConstants.START_TERMINAL.equals(anchorId)) {
- if (element instanceof Message) {
- return ((Message) element).getSendEvent();
- } else if (element instanceof ExecutionSpecification) {
- return ((ExecutionSpecification) element).getStart();
- }
- }
- return null;
- }
-
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/SemanticOccurrenceEditPolicyProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/SemanticOccurrenceEditPolicyProvider.java
new file mode 100644
index 00000000000..6ae12c016d7
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/SemanticOccurrenceEditPolicyProvider.java
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * Copyright (c) 2018 CEA LIST, EclipseSource 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:
+ * EclipseSource - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.sequence.providers;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+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.policies.OccurenceSemanticEditPolicy;
+import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
+import org.eclipse.uml2.uml.ExecutionSpecification;
+import org.eclipse.uml2.uml.Message;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
+
+/**
+ * <p>
+ * An {@link IEditPolicyProvider} installing an {@link OccurenceSemanticEditPolicy} on
+ * {@link Message} and {@link ExecutionSpecification} edit parts.
+ * </p>
+ * <p>
+ * Note: it doesn't have to be installed on {@link DestructionOccurrenceSpecification}, because that
+ * edit part already directly represents a single {@link OccurrenceSpecification}.
+ * </p>
+ */
+public class SemanticOccurrenceEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
+
+ @Override
+ public boolean provides(IOperation operation) {
+ if (false == operation instanceof CreateEditPoliciesOperation) {
+ return false;
+ }
+
+ CreateEditPoliciesOperation op = (CreateEditPoliciesOperation) operation;
+ EditPart editPart = op.getEditPart();
+ return editPart instanceof AbstractExecutionSpecificationEditPart || editPart instanceof AbstractMessageEditPart;
+ }
+
+ @Override
+ public void createEditPolicies(EditPart editPart) {
+ editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new OccurenceSemanticEditPolicy());
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationUtil.java
index 64e288b16e5..e5bca16943e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationUtil.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationUtil.java
@@ -23,11 +23,17 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNodeEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.notation.Anchor;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.IdentityAnchor;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.uml.diagram.sequence.anchors.AnchorConstants;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.Message;
@@ -39,9 +45,24 @@ import org.eclipse.uml2.uml.OccurrenceSpecification;
* Util class related to the manipulation of Links targetting {@link OccurrenceSpecification}s,
* typically used by {@link GraphicalNodeEditPolicy} or {@link EditPart}.
* </p>
+ * <p>
+ * Most methods are meant to be used with Edges connecting some {@link OccurrenceSpecification}
+ * that are not necessarily displayed on the Diagram.
+ * </p>
+ * <p>
+ * To identify the right {@link OccurrenceSpecification}, the methods may rely either on the
+ * {@link IFigure} that is under the mouse cursor, by determining if the mouse is closer to
+ * the start or finish (Or source/target for edges) point representing an {@link OccurrenceSpecification}.
+ * </p>
+ * <p>
+ * When only the {@link Edge} view is available, the methods will rely on the current {@link Edge#getSourceAnchor()}
+ * and {@link Edge#getTargetAnchor()}. Anchors are expected to match one of the values defined in {@link AnchorConstants}.
+ * </p>
*
* @see DurationLinkUtil
* @see GeneralOrderingUtil
+ * @see AnchorConstants#START_TERMINAL
+ * @see AnchorConstants#END_TERMINAL
*/
public class OccurrenceSpecificationUtil {
@@ -139,10 +160,10 @@ public class OccurrenceSpecificationUtil {
/**
* Find the semantic {@link OccurrenceSpecification} represented by the given <code>connectorEnd</code>.
- * The connector should be the source or target of a DurationLink connector.
+ * The connector should be the source or target of a connector (e.g. DurationLink or GeneralOrdering).
*
* @param connectorEnd
- * the source or target of a DurationLink connector
+ * the source or target of a connector
* @param anchorTerminal
* The connection anchor corresponding to the given connector end.
* @return
@@ -176,4 +197,70 @@ public class OccurrenceSpecificationUtil {
}
return null;
}
+
+ /**
+ * <p>
+ * Return the target {@link OccurrenceSpecification} represented by this {@link ReconnectRequest}.
+ * </p>
+ * <p>
+ * If there is no {@link OccurrenceSpecification} at this request's location, the default EObject
+ * represented by {@link ReconnectRequest#getTarget()} is returned.
+ * </p>
+ *
+ * @param request
+ * @return
+ */
+ public static EObject getOccurrence(ReconnectRequest request) {
+ EObject element = EMFHelper.getEObject(request.getTarget());
+ IFigure targetFigure = ((IGraphicalEditPart) request.getTarget()).getFigure();
+ if (element instanceof Message) {
+ if (OccurrenceSpecificationUtil.isSource(targetFigure, request.getLocation())) {
+ return ((Message) element).getSendEvent();
+ } else {
+ return ((Message) element).getReceiveEvent();
+ }
+ } else if (element instanceof ExecutionSpecification) {
+ if (OccurrenceSpecificationUtil.isStart(targetFigure, request.getLocation())) {
+ return ((ExecutionSpecification) element).getStart();
+ } else {
+ return ((ExecutionSpecification) element).getFinish();
+ }
+ }
+ return element;
+ }
+
+ /**
+ * <p>
+ * Return the {@link OccurrenceSpecification} that is the {@link Edge#getSource() Source}
+ * of this Edge.
+ * </p>
+ *
+ * @param connection
+ * @return
+ */
+ public static EObject getSourceOccurrence(Edge connection) {
+ Anchor sourceAnchor = connection.getSourceAnchor();
+ if (sourceAnchor instanceof IdentityAnchor) {
+ return findSemanticOccurrence(connection.getSource(), ((IdentityAnchor) sourceAnchor).getId());
+ }
+ return connection.getSource().getElement();
+ }
+
+ /**
+ * <p>
+ * Return the {@link OccurrenceSpecification} that is the {@link Edge#getTarget() Target}
+ * of this Edge.
+ * </p>
+ *
+ * @param connection
+ * @return
+ */
+ public static EObject getTargetOccurrence(Edge connection) {
+ Anchor targetAnchor = connection.getTargetAnchor();
+ if (targetAnchor instanceof IdentityAnchor) {
+ return findSemanticOccurrence(connection.getTarget(), ((IdentityAnchor) targetAnchor).getId());
+ }
+ return connection.getTarget().getElement();
+ }
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/plugin.xml
index 58ae8e3db6a..d42dc01565c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/plugin.xml
@@ -378,6 +378,12 @@
name="Highest">
</Priority>
</editpolicyProvider>
+ <editpolicyProvider
+ class="org.eclipse.papyrus.uml.diagram.sequence.providers.SemanticOccurrenceEditPolicyProvider">
+ <Priority
+ name="Medium">
+ </Priority>
+ </editpolicyProvider>
</extension>
<extension point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders">
<editpartProvider class="org.eclipse.papyrus.uml.diagram.sequence.providers.CustomEditPartProvider">
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java
index 96d39855fbd..d4b658f6e17 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java
@@ -15,6 +15,9 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.service.types.helper.advice;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -23,14 +26,19 @@ import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
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.commands.SetValueCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.uml2.uml.Duration;
import org.eclipse.uml2.uml.DurationConstraint;
import org.eclipse.uml2.uml.DurationInterval;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Interaction;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage.Literals;
/**
* @since 3.0
@@ -125,6 +133,44 @@ public class DurationConstraintEditHelperAdvice extends AbstractOccurrenceLinkEd
return composite;
}
+ @Override
+ protected ICommand getAfterReorientRelationshipCommand(ReorientRelationshipRequest request) {
+ EObject relationship = request.getRelationship();
+ if (relationship instanceof DurationConstraint) {
+ DurationConstraint constraint = (DurationConstraint) relationship;
+ EObject newEnd = request.getNewRelationshipEnd();
+ if (newEnd instanceof OccurrenceSpecification) {
+ OccurrenceSpecification newOccurrence = (OccurrenceSpecification) newEnd;
+ List<Element> values = new ArrayList<>(constraint.getConstrainedElements());
+ if (request.getDirection() == ReorientRelationshipRequest.REORIENT_SOURCE) {
+ if (values.isEmpty()) {
+ values.add(newOccurrence);
+ } else if (values.size() == 1) {
+ values.add(0, newOccurrence);
+ } else if (values.get(0) == newOccurrence) {
+ return null;
+ } else {
+ values.set(0, newOccurrence);
+ }
+ } else { // Reorient Target
+ if (values.isEmpty()) {
+ values.add(newOccurrence);
+ } else if (values.size() == 1) {
+ values.add(newOccurrence);
+ } else if (values.get(1) == newOccurrence) {
+ return null;
+ } else {
+ values.set(1, newOccurrence);
+ }
+ }
+
+ SetRequest setRequest = new SetRequest(constraint, Literals.CONSTRAINT__CONSTRAINED_ELEMENT, values);
+ return new SetValueCommand(setRequest);
+ }
+ }
+ return super.getAfterReorientRelationshipCommand(request);
+ }
+
/**
* @see org.eclipse.papyrus.uml.service.types.helper.advice.AbstractDurationEditHelperAdvice#getCreationContainer(org.eclipse.uml2.uml.Element)
*
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationObservationEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationObservationEditHelperAdvice.java
index 1a7c94bba4e..6e448bcf446 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationObservationEditHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationObservationEditHelperAdvice.java
@@ -11,6 +11,9 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.service.types.helper.advice;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -19,11 +22,16 @@ import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
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.commands.SetValueCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.uml2.uml.DurationObservation;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
+import org.eclipse.uml2.uml.UMLPackage.Literals;
public class DurationObservationEditHelperAdvice extends AbstractOccurrenceLinkEditHelperAdvice {
@@ -66,6 +74,44 @@ public class DurationObservationEditHelperAdvice extends AbstractOccurrenceLinkE
}
@Override
+ protected ICommand getAfterReorientRelationshipCommand(ReorientRelationshipRequest request) {
+ EObject relationship = request.getRelationship();
+ if (relationship instanceof DurationObservation) {
+ DurationObservation observation = (DurationObservation) relationship;
+ EObject newEnd = request.getNewRelationshipEnd();
+ if (newEnd instanceof OccurrenceSpecification) {
+ OccurrenceSpecification newOccurrence = (OccurrenceSpecification) newEnd;
+ List<Element> values = new ArrayList<>(observation.getEvents());
+ if (request.getDirection() == ReorientRelationshipRequest.REORIENT_SOURCE) {
+ if (values.isEmpty()) {
+ values.add(newOccurrence);
+ } else if (values.size() == 1) {
+ values.add(0, newOccurrence);
+ } else if (values.get(0) == newOccurrence) {
+ return null;
+ } else {
+ values.set(0, newOccurrence);
+ }
+ } else { // Reorient Target
+ if (values.isEmpty()) {
+ values.add(newOccurrence);
+ } else if (values.size() == 1) {
+ values.add(newOccurrence);
+ } else if (values.get(1) == newOccurrence) {
+ return null;
+ } else {
+ values.set(1, newOccurrence);
+ }
+ }
+
+ SetRequest setRequest = new SetRequest(observation, Literals.DURATION_OBSERVATION__EVENT, values);
+ return new SetValueCommand(setRequest);
+ }
+ }
+ return super.getAfterReorientRelationshipCommand(request);
+ }
+
+ @Override
protected NamedElement getSourceElement(AbstractEditCommandRequest request) {
Element source = super.getSourceElement(request);
return source instanceof NamedElement ? (NamedElement) source : null;

Back to the top