Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-07-30 08:19:56 -0400
committerCamille Letavernier2018-07-30 08:55:19 -0400
commit78a564067d676695afb081339d2c686b42ed8cb0 (patch)
treebd5d1fa118f0af8bc13e6c192563f5b711ae881a
parenta97121f5a3d6135cdcb7c9242ea1712591275342 (diff)
downloadorg.eclipse.papyrus-78a564067d676695afb081339d2c686b42ed8cb0.tar.gz
org.eclipse.papyrus-78a564067d676695afb081339d2c686b42ed8cb0.tar.xz
org.eclipse.papyrus-78a564067d676695afb081339d2c686b42ed8cb0.zip
Bug 536641 [Sequence Diagram] Durations can only be created on
OccurrenceSpecifications - Move the code shared by GraphicalNodeEditPolicies and EditParts to a new DurationLinkUtil utility class Change-Id: I5a6e180e88afcc48ce83ecc8d93e30c12d624970 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/parts/AbstractExecutionSpecificationEditPart.java51
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractMessageEditPart.java58
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CDestructionOccurrenceSpecificationEditPart.java14
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/DestructionOccurrenceGraphicalNodeEditPolicy.java41
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExecutionSpecificationGraphicalNodeEditPolicy.java72
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/MessageGraphicalNodeEditPolicy.java83
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DurationLinkUtil.java153
7 files changed, 193 insertions, 279 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java
index 43109a13113..794cfe688c7 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java
@@ -30,7 +30,6 @@ import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.Request;
import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.gmf.runtime.common.core.util.Log;
import org.eclipse.gmf.runtime.common.core.util.Trace;
@@ -69,6 +68,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.BoundForEdit
import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectExecutionToGridEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectYCoordinateToGrillingEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.util.CoordinateReferentialUtils;
+import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
import org.eclipse.swt.graphics.Color;
@@ -77,6 +77,7 @@ import org.eclipse.swt.graphics.Color;
*
* @author Jin Liu (jin.liu@soyatec.com)
*/
+@SuppressWarnings("restriction")
public abstract class AbstractExecutionSpecificationEditPart extends RoundedCompartmentEditPart {
/**
@@ -322,7 +323,7 @@ public abstract class AbstractExecutionSpecificationEditPart extends RoundedComp
}
// otherwise, this is a recursive call, let destination free
} else if (UMLElementTypes.DurationConstraint_Edge.equals(type) || UMLElementTypes.DurationObservation_Edge.equals(type)) {
- return isStart(createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
+ return DurationLinkUtil.isStart(getFigure(), createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
}
}
} else if (request instanceof ReconnectRequest) {
@@ -343,32 +344,14 @@ public abstract class AbstractExecutionSpecificationEditPart extends RoundedComp
return new AnchorHelper.FixedAnchorEx(getFigure(), PositionConstants.TOP);
}
}
- if (isDurationLink(createRequest)) {
- return isStart(createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
+ if (DurationLinkUtil.isDurationLink(createRequest)) {
+ return DurationLinkUtil.isStart(getFigure(), createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
}
}
return super.getTargetConnectionAnchor(request);
}
/**
- * Test whether the given request is closer to the start (top) or to the finish (bottom) point of the execution specification
- *
- * @param createRequest
- * The create request
- * @return
- * <code>true</code> if the given request is closer to the top of the figure; false if it is closer to the bottom
- */
- private boolean isStart(CreateRequest createRequest) {
- Point location = createRequest.getLocation();
- Rectangle bounds = getFigure().getBounds().getCopy();
- getFigure().translateToAbsolute(bounds);
-
- double distanceToTop = location.getDistance(bounds.getTop());
- double distanceToBottom = location.getDistance(bounds.getBottom());
- return distanceToTop < distanceToBottom;
- }
-
- /**
* @see org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
*
* @param connEditPart
@@ -384,7 +367,7 @@ public abstract class AbstractExecutionSpecificationEditPart extends RoundedComp
final org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connection = (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) connEditPart;
String t = null;
try {
- t = (String) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
+ t = (String) getEditingDomain().runExclusive(new RunnableWithResult.Impl<String>() {
@Override
public void run() {
@@ -426,7 +409,7 @@ public abstract class AbstractExecutionSpecificationEditPart extends RoundedComp
// Reply Message
return new AnchorHelper.FixedAnchorEx(getFigure(), PositionConstants.BOTTOM);
} else if (UMLElementTypes.DurationConstraint_Edge.equals(type) || UMLElementTypes.DurationObservation_Edge.equals(type)) {
- return isStart(createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
+ return DurationLinkUtil.isStart(getFigure(), createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
}
}
} else if (request instanceof ReconnectRequest) {
@@ -438,28 +421,14 @@ public abstract class AbstractExecutionSpecificationEditPart extends RoundedComp
}
} else if (request instanceof CreateConnectionViewRequest) {
CreateConnectionViewRequest createRequest = (CreateConnectionViewRequest) request;
- if (isDurationLink(createRequest)) {
- return isStart(createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
+ if (DurationLinkUtil.isDurationLink(createRequest)) {
+ return DurationLinkUtil.isStart(getFigure(), createRequest) ? new NodeTopAnchor(getFigure()) : new NodeBottomAnchor(getFigure());
}
}
return super.getSourceConnectionAnchor(request);
}
/**
- * @param createRequest
- * @return
- */
- private boolean isDurationLink(CreateConnectionViewRequest createRequest) {
- String semanticHint = createRequest.getConnectionViewDescriptor().getSemanticHint();
- switch (semanticHint) {
- case DurationConstraintLinkEditPart.VISUAL_ID:
- case DurationObservationLinkEditPart.VISUAL_ID:
- return true;
- }
- return false;
- }
-
- /**
* @see org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
*
* @param connEditPart
@@ -475,7 +444,7 @@ public abstract class AbstractExecutionSpecificationEditPart extends RoundedComp
final org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connection = (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) connEditPart;
String t = null;
try {
- t = (String) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
+ t = (String) getEditingDomain().runExclusive(new RunnableWithResult.Impl<String>() {
@Override
public void run() {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractMessageEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractMessageEditPart.java
index 3a5f7d134b8..003581ef642 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractMessageEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractMessageEditPart.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2017 CEA LIST, EclipseSource and others.
+ * Copyright (c) 2017, 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
@@ -16,10 +16,8 @@ package org.eclipse.papyrus.uml.diagram.sequence.edit.parts;
import java.util.List;
-import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.Cursors;
-import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.emf.common.notify.Notification;
@@ -29,7 +27,6 @@ import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
-import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
@@ -57,6 +54,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectMessageToGridEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.ConnectRectangleToGridEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.LifeLineGraphicalNodeEditPolicy;
+import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
import org.eclipse.papyrus.uml.diagram.sequence.util.SelectMessagesEditPartTracker;
import org.eclipse.papyrus.uml.diagram.sequence.util.SelfMessageHelper;
import org.eclipse.swt.SWT;
@@ -411,13 +409,13 @@ public abstract class AbstractMessageEditPart extends UMLConnectionNodeEditPart
List<?> relationshipTypes = createRequest.getElementTypes();
for (Object type : relationshipTypes) {
if (UMLElementTypes.DurationConstraint_Edge.equals(type) || UMLElementTypes.DurationObservation_Edge.equals(type)) {
- return isSource(createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
+ return DurationLinkUtil.isSource(getConnectionFigure(), createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
}
}
} else if (request instanceof CreateConnectionViewRequest) {
CreateConnectionViewRequest createRequest = (CreateConnectionViewRequest) request;
- if (isDurationLink(createRequest)) {
- return isSource(createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
+ if (DurationLinkUtil.isDurationLink(createRequest)) {
+ return DurationLinkUtil.isSource(getConnectionFigure(), createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
}
}
return super.getSourceConnectionAnchor(request);
@@ -430,57 +428,17 @@ public abstract class AbstractMessageEditPart extends UMLConnectionNodeEditPart
List<?> relationshipTypes = createRequest.getElementTypes();
for (Object type : relationshipTypes) {
if (UMLElementTypes.DurationConstraint_Edge.equals(type) || UMLElementTypes.DurationObservation_Edge.equals(type)) {
- return isSource(createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
+ return DurationLinkUtil.isSource(getConnectionFigure(), createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
}
}
} else if (request instanceof CreateConnectionViewRequest) {
CreateConnectionViewRequest createRequest = (CreateConnectionViewRequest) request;
- if (isDurationLink(createRequest)) {
- return isSource(createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
+ if (DurationLinkUtil.isDurationLink(createRequest)) {
+ return DurationLinkUtil.isSource(getConnectionFigure(), createRequest) ? new ConnectionSourceAnchor(getPrimaryShape()) : new ConnectionTargetAnchor(getPrimaryShape());
}
}
return super.getTargetConnectionAnchor(request);
}
- /**
- * Test whether the given request is closer to the source or to the target point of the message
- *
- * @param createRequest
- * The create request
- * @return
- * <code>true</code> if the given request is closer to the source of the connection; false if it is closer to the target
- */
- private boolean isSource(CreateRequest createRequest) {
- Point location = createRequest.getLocation();
- IFigure connection = getPrimaryShape();
- if (connection != null) {
- PointList points = ((Connection) connection).getPoints();
- if (points.size() >= 2) {
- Point source = points.getFirstPoint();
- Point target = points.getLastPoint();
- double distanceToSource = location.getDistance(source);
- double distanceToTarget = location.getDistance(target);
- return distanceToSource < distanceToTarget;
- }
- }
-
- // Default; shouldn't happen, unless the Message figure is invalid,
- // in which case we can't determine the source/target).
- return true;
- }
-
- /**
- * @param createRequest
- * @return
- */
- private boolean isDurationLink(CreateConnectionViewRequest createRequest) {
- String semanticHint = createRequest.getConnectionViewDescriptor().getSemanticHint();
- switch (semanticHint) {
- case DurationConstraintLinkEditPart.VISUAL_ID:
- case DurationObservationLinkEditPart.VISUAL_ID:
- return true;
- }
- return false;
- }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CDestructionOccurrenceSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CDestructionOccurrenceSpecificationEditPart.java
index e42e292e62b..f2e3c642a4e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CDestructionOccurrenceSpecificationEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CDestructionOccurrenceSpecificationEditPart.java
@@ -25,6 +25,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.anchors.CenterAnchor;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.DestructionOccurrenceGraphicalNodeEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.figures.DestructionEventNodePlate;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
public class CDestructionOccurrenceSpecificationEditPart extends DestructionOccurrenceSpecificationEditPart {
@@ -50,7 +51,7 @@ public class CDestructionOccurrenceSpecificationEditPart extends DestructionOccu
}
} else if (request instanceof CreateConnectionViewRequest) {
CreateConnectionViewRequest createRequest = (CreateConnectionViewRequest) request;
- if (isDurationLink(createRequest)) {
+ if (DurationLinkUtil.isDurationLink(createRequest)) {
return new CenterAnchor(getFigure());
}
}
@@ -69,7 +70,7 @@ public class CDestructionOccurrenceSpecificationEditPart extends DestructionOccu
}
} else if (request instanceof CreateConnectionViewRequest) {
CreateConnectionViewRequest createRequest = (CreateConnectionViewRequest) request;
- if (isDurationLink(createRequest)) {
+ if (DurationLinkUtil.isDurationLink(createRequest)) {
return new CenterAnchor(getFigure());
}
}
@@ -83,13 +84,4 @@ public class CDestructionOccurrenceSpecificationEditPart extends DestructionOccu
return nodePlate;
}
- private boolean isDurationLink(CreateConnectionViewRequest createRequest) {
- String semanticHint = createRequest.getConnectionViewDescriptor().getSemanticHint();
- switch (semanticHint) {
- case DurationConstraintLinkEditPart.VISUAL_ID:
- case DurationObservationLinkEditPart.VISUAL_ID:
- return true;
- }
- return false;
- }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/DestructionOccurrenceGraphicalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/DestructionOccurrenceGraphicalNodeEditPolicy.java
index 9b71ae794b2..16167d4838a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/DestructionOccurrenceGraphicalNodeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/DestructionOccurrenceGraphicalNodeEditPolicy.java
@@ -13,22 +13,16 @@
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
-import java.util.List;
-
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.Request;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultGraphicalNodeEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest;
import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure;
-import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
/**
* An extended {@link DefaultGraphicalNodeEditPolicy} which supports creation of DurationLinks
@@ -37,7 +31,7 @@ public class DestructionOccurrenceGraphicalNodeEditPolicy extends DefaultGraphic
@Override
protected ICommand getAfterConnectionCompleteCommand(CreateConnectionViewAndElementRequest request, final TransactionalEditingDomain editingDomain) {
- if (isCreateDurationLink(request)) {
+ if (DurationLinkUtil.isCreateDurationLink(request)) {
return null; // Prevent the superclass from "Fixing" the anchors
}
return super.getAfterConnectionCompleteCommand(request, editingDomain);
@@ -45,40 +39,11 @@ public class DestructionOccurrenceGraphicalNodeEditPolicy extends DefaultGraphic
@Override
protected Connection createDummyConnection(Request req) {
- if (req instanceof CreateConnectionRequest && isCreateDurationLink((CreateConnectionRequest) req)) {
+ if (req instanceof CreateConnectionRequest && DurationLinkUtil.isCreateDurationLink((CreateConnectionRequest) req)) {
return new DurationLinkFigure();
}
return new PolylineConnection();
}
- private boolean isCreateDurationLink(CreateConnectionRequest request) {
- CreateRelationshipRequest createElementRequest = getCreateRelationshipRequest(request);
- if (createElementRequest == null) {
- if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) {
- CreateAspectUnspecifiedTypeConnectionRequest createRequest = (CreateAspectUnspecifiedTypeConnectionRequest) request;
- List<?> types = createRequest.getElementTypes();
- if (types.stream().allMatch(
- type -> type == UMLElementTypes.DurationConstraint_Edge ||
- type == UMLElementTypes.DurationObservation_Edge)) {
- return true;
- }
- }
- } else {
- IElementType type = createElementRequest.getElementType();
- return type == UMLElementTypes.DurationConstraint_Edge || type == UMLElementTypes.DurationObservation_Edge;
- }
- return false;
- }
- private CreateRelationshipRequest getCreateRelationshipRequest(CreateConnectionRequest request) {
- if (false == request instanceof CreateConnectionViewAndElementRequest) {
- return null;
- }
- CreateElementRequestAdapter requestAdapter = ((CreateConnectionViewAndElementRequest) request).getConnectionViewAndElementDescriptor().getCreateElementRequestAdapter();
- if (requestAdapter == null) {
- return null;
- }
- CreateRelationshipRequest createElementRequest = (CreateRelationshipRequest) requestAdapter.getAdapter(CreateRelationshipRequest.class);
- return createElementRequest;
- }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExecutionSpecificationGraphicalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExecutionSpecificationGraphicalNodeEditPolicy.java
index 5ebddd4714d..19b20d395d1 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExecutionSpecificationGraphicalNodeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/ExecutionSpecificationGraphicalNodeEditPolicy.java
@@ -12,25 +12,17 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
-import java.util.List;
-
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.PolylineConnection;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
import org.eclipse.gef.requests.CreateConnectionRequest;
-import org.eclipse.gef.requests.CreateRequest;
-import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest;
import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure;
-import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
import org.eclipse.papyrus.uml.service.types.utils.SequenceRequestConstant;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.OccurrenceSpecification;
@@ -46,13 +38,13 @@ public class ExecutionSpecificationGraphicalNodeEditPolicy extends ElementCreati
// Source (First half of the request)
@Override
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
- if (isCreateDurationLink(request)) {
- CreateRelationshipRequest createRequest = getCreateRelationshipRequest(request);
+ if (DurationLinkUtil.isCreateDurationLink(request)) {
+ CreateRelationshipRequest createRequest = DurationLinkUtil.getCreateRelationshipRequest(request);
if (createRequest != null) {
OccurrenceSpecification sourceOccurrence;
ExecutionSpecification execSpec = getExecutionSpecification();
if (execSpec != null) {
- if (isStart(request)) {
+ if (DurationLinkUtil.isStart(getHostFigure(), request)) {
sourceOccurrence = execSpec.getStart();
} else {
sourceOccurrence = execSpec.getFinish();
@@ -73,33 +65,16 @@ public class ExecutionSpecificationGraphicalNodeEditPolicy extends ElementCreati
return null;
}
- /**
- * Test whether the given request is closer to the start (top) or to the finish (bottom) point of the execution specification
- *
- * @param createRequest
- * The create request
- * @return
- * <code>true</code> if the given request is closer to the top of the figure; false if it is closer to the bottom
- */
- private boolean isStart(CreateRequest createRequest) {
- Point location = createRequest.getLocation();
- Rectangle bounds = getHostFigure().getBounds();
-
- double distanceToTop = location.getDistance(bounds.getTop());
- double distanceToBottom = location.getDistance(bounds.getBottom());
- return distanceToTop < distanceToBottom;
- }
-
// Target (Second half of the request)
@Override
protected Command getConnectionAndRelationshipCompleteCommand(CreateConnectionViewAndElementRequest request) {
- if (isCreateDurationLink(request)) {
- CreateRelationshipRequest createRequest = getCreateRelationshipRequest(request);
+ if (DurationLinkUtil.isCreateDurationLink(request)) {
+ CreateRelationshipRequest createRequest = DurationLinkUtil.getCreateRelationshipRequest(request);
if (createRequest != null) {
OccurrenceSpecification targetOccurrence;
ExecutionSpecification execSpec = getExecutionSpecification();
if (execSpec != null) {
- if (isStart(request)) {
+ if (DurationLinkUtil.isStart(getHostFigure(), request)) {
targetOccurrence = execSpec.getStart();
} else {
targetOccurrence = execSpec.getFinish();
@@ -112,40 +87,9 @@ public class ExecutionSpecificationGraphicalNodeEditPolicy extends ElementCreati
return super.getConnectionAndRelationshipCompleteCommand(request);
}
- private boolean isCreateDurationLink(CreateConnectionRequest request) {
- CreateRelationshipRequest createElementRequest = getCreateRelationshipRequest(request);
- if (createElementRequest == null) {
- if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) {
- CreateAspectUnspecifiedTypeConnectionRequest createRequest = (CreateAspectUnspecifiedTypeConnectionRequest) request;
- List<?> types = createRequest.getElementTypes();
- if (types.stream().allMatch(
- type -> type == UMLElementTypes.DurationConstraint_Edge ||
- type == UMLElementTypes.DurationObservation_Edge)) {
- return true;
- }
- }
- } else {
- IElementType type = createElementRequest.getElementType();
- return type == UMLElementTypes.DurationConstraint_Edge || type == UMLElementTypes.DurationObservation_Edge;
- }
- return false;
- }
-
- private CreateRelationshipRequest getCreateRelationshipRequest(CreateConnectionRequest request) {
- if (false == request instanceof CreateConnectionViewAndElementRequest) {
- return null;
- }
- CreateElementRequestAdapter requestAdapter = ((CreateConnectionViewAndElementRequest) request).getConnectionViewAndElementDescriptor().getCreateElementRequestAdapter();
- if (requestAdapter == null) {
- return null;
- }
- CreateRelationshipRequest createElementRequest = (CreateRelationshipRequest) requestAdapter.getAdapter(CreateRelationshipRequest.class);
- return createElementRequest;
- }
-
@Override
protected Connection createDummyConnection(Request req) {
- if (req instanceof CreateConnectionRequest && isCreateDurationLink((CreateConnectionRequest) req)) {
+ if (req instanceof CreateConnectionRequest && DurationLinkUtil.isCreateDurationLink((CreateConnectionRequest) req)) {
return new DurationLinkFigure();
}
return new PolylineConnection();
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/MessageGraphicalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/MessageGraphicalNodeEditPolicy.java
index 6e1c8ca2a94..3639bc05476 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/MessageGraphicalNodeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/MessageGraphicalNodeEditPolicy.java
@@ -12,27 +12,18 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
-import java.util.List;
-
import org.eclipse.draw2d.Connection;
-import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolylineConnection;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.CreateConnectionRequest;
-import org.eclipse.gef.requests.CreateRequest;
-import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
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.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest;
import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure;
-import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
import org.eclipse.papyrus.uml.service.types.utils.SequenceRequestConstant;
import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.MessageEnd;
@@ -42,13 +33,13 @@ public class MessageGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {
// Source (First half of the request)
@Override
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
- if (isCreateDurationLink(request)) {
- CreateRelationshipRequest createRequest = getCreateRelationshipRequest(request);
+ if (DurationLinkUtil.isCreateDurationLink(request)) {
+ CreateRelationshipRequest createRequest = DurationLinkUtil.getCreateRelationshipRequest(request);
if (createRequest != null) {
MessageEnd sourceOccurrence;
Message message = getMessage();
if (message != null) {
- sourceOccurrence = isSource(request) ? message.getSendEvent() : message.getReceiveEvent();
+ sourceOccurrence = DurationLinkUtil.isSource(getHostFigure(), request) ? message.getSendEvent() : message.getReceiveEvent();
if (sourceOccurrence instanceof OccurrenceSpecification) {
request.getExtendedData().put(SequenceRequestConstant.SOURCE_OCCURRENCE, sourceOccurrence);
createRequest.setParameter(SequenceRequestConstant.SOURCE_OCCURRENCE, sourceOccurrence);
@@ -62,13 +53,13 @@ public class MessageGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {
// Target (Second half of the request)
@Override
protected Command getConnectionAndRelationshipCompleteCommand(CreateConnectionViewAndElementRequest request) {
- if (isCreateDurationLink(request)) {
- CreateRelationshipRequest createRequest = getCreateRelationshipRequest(request);
+ if (DurationLinkUtil.isCreateDurationLink(request)) {
+ CreateRelationshipRequest createRequest = DurationLinkUtil.getCreateRelationshipRequest(request);
if (createRequest != null) {
MessageEnd targetOccurrence;
Message message = getMessage();
if (message != null) {
- targetOccurrence = isSource(request) ? message.getSendEvent() : message.getReceiveEvent();
+ targetOccurrence = DurationLinkUtil.isSource(getHostFigure(), request) ? message.getSendEvent() : message.getReceiveEvent();
if (targetOccurrence instanceof OccurrenceSpecification) {
request.getExtendedData().put(SequenceRequestConstant.TARGET_OCCURRENCE, targetOccurrence);
createRequest.setParameter(SequenceRequestConstant.TARGET_OCCURRENCE, targetOccurrence);
@@ -79,72 +70,14 @@ public class MessageGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {
return super.getConnectionAndRelationshipCompleteCommand(request);
}
- /**
- * Test whether the given request is closer to the source or to the target point of the message
- *
- * @param createRequest
- * The create request
- * @return
- * <code>true</code> if the given request is closer to the source of the connection; false if it is closer to the target
- */
- private boolean isSource(CreateRequest createRequest) {
- Point location = createRequest.getLocation();
- IFigure connection = getHostFigure();
- if (connection instanceof Connection) {
- PointList points = ((Connection) connection).getPoints();
- if (points.size() >= 2) {
- Point source = points.getFirstPoint();
- Point target = points.getLastPoint();
- double distanceToSource = location.getDistance(source);
- double distanceToTarget = location.getDistance(target);
- return distanceToSource < distanceToTarget;
- }
- }
-
- // Default; shouldn't happen, unless the Message figure is invalid,
- // in which case we can't determine the source/target).
- return true;
- }
-
private Message getMessage() {
EObject model = EMFHelper.getEObject(getHost());
return model instanceof Message ? (Message) model : null;
}
- private boolean isCreateDurationLink(CreateConnectionRequest request) {
- CreateRelationshipRequest createElementRequest = getCreateRelationshipRequest(request);
- if (createElementRequest == null) {
- if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) {
- CreateAspectUnspecifiedTypeConnectionRequest createRequest = (CreateAspectUnspecifiedTypeConnectionRequest) request;
- List<?> types = createRequest.getElementTypes();
- if (types.stream().allMatch(
- type -> type == UMLElementTypes.DurationConstraint_Edge ||
- type == UMLElementTypes.DurationObservation_Edge)) {
- return true;
- }
- }
- } else {
- IElementType type = createElementRequest.getElementType();
- return type == UMLElementTypes.DurationConstraint_Edge || type == UMLElementTypes.DurationObservation_Edge;
- }
- return false;
- }
-
- private CreateRelationshipRequest getCreateRelationshipRequest(CreateConnectionRequest request) {
- if (false == request instanceof CreateConnectionViewAndElementRequest) {
- return null;
- }
- CreateElementRequestAdapter requestAdapter = ((CreateConnectionViewAndElementRequest) request).getConnectionViewAndElementDescriptor().getCreateElementRequestAdapter();
- if (requestAdapter == null) {
- return null;
- }
- CreateRelationshipRequest createElementRequest = (CreateRelationshipRequest) requestAdapter.getAdapter(CreateRelationshipRequest.class);
- return createElementRequest;
- }
-
@Override
protected Connection createDummyConnection(Request req) {
- if (req instanceof CreateConnectionRequest && isCreateDurationLink((CreateConnectionRequest) req)) {
+ if (req instanceof CreateConnectionRequest && DurationLinkUtil.isCreateDurationLink((CreateConnectionRequest) req)) {
return new DurationLinkFigure();
}
return new PolylineConnection();
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DurationLinkUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DurationLinkUtil.java
new file mode 100644
index 00000000000..47d186427ac
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DurationLinkUtil.java
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.sequence.util;
+
+import java.util.List;
+
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.requests.CreateConnectionRequest;
+import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNodeEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.DurationConstraintLinkEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.DurationObservationLinkEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+
+/**
+ * <p>
+ * Util class related to the manipulation of DurationLinks, typically used by
+ * {@link GraphicalNodeEditPolicy} or {@link EditPart}
+ * </p>
+ */
+public class DurationLinkUtil {
+
+ /**
+ * Test if the given {@link CreateConnectionRequest} is creating a DurationLink
+ *
+ * @param request
+ * @return
+ */
+ public static boolean isCreateDurationLink(CreateConnectionRequest request) {
+ CreateRelationshipRequest createElementRequest = getCreateRelationshipRequest(request);
+ if (createElementRequest == null) {
+ if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) {
+ CreateAspectUnspecifiedTypeConnectionRequest createRequest = (CreateAspectUnspecifiedTypeConnectionRequest) request;
+ List<?> types = createRequest.getElementTypes();
+ if (types.stream().allMatch(
+ type -> type == UMLElementTypes.DurationConstraint_Edge ||
+ type == UMLElementTypes.DurationObservation_Edge)) {
+ return true;
+ }
+ }
+ } else {
+ IElementType type = createElementRequest.getElementType();
+ return type == UMLElementTypes.DurationConstraint_Edge || type == UMLElementTypes.DurationObservation_Edge;
+ }
+ return false;
+ }
+
+
+ /**
+ * Test if the given {@link CreateConnectionViewRequest} is creating a DurationLink
+ *
+ * @param createRequest
+ * @return
+ */
+ public static boolean isDurationLink(CreateConnectionViewRequest createRequest) {
+ String semanticHint = createRequest.getConnectionViewDescriptor().getSemanticHint();
+ switch (semanticHint) {
+ case DurationConstraintLinkEditPart.VISUAL_ID:
+ case DurationObservationLinkEditPart.VISUAL_ID:
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Retrieve the semantic {@link CreateRelationshipRequest} from the given GEF {@link CreateConnectionRequest},
+ * or <code>null</code>.
+ *
+ * @param request
+ * @return
+ */
+ public static CreateRelationshipRequest getCreateRelationshipRequest(CreateConnectionRequest request) {
+ if (false == request instanceof CreateConnectionViewAndElementRequest) {
+ return null;
+ }
+ CreateElementRequestAdapter requestAdapter = ((CreateConnectionViewAndElementRequest) request).getConnectionViewAndElementDescriptor().getCreateElementRequestAdapter();
+ if (requestAdapter == null) {
+ return null;
+ }
+ CreateRelationshipRequest createElementRequest = (CreateRelationshipRequest) requestAdapter.getAdapter(CreateRelationshipRequest.class);
+ return createElementRequest;
+ }
+
+ /**
+ * Test whether the given request is closer to the start (top) or to the finish (bottom) point of the execution specification
+ *
+ * @param createRequest
+ * The create request
+ * @return
+ * <code>true</code> if the given request is closer to the top of the figure; false if it is closer to the bottom
+ */
+ public static boolean isStart(IFigure targetFigure, CreateRequest createRequest) {
+ Point location = createRequest.getLocation();
+ Rectangle bounds = targetFigure.getBounds().getCopy();
+ targetFigure.translateToAbsolute(bounds);
+
+ double distanceToTop = location.getDistance(bounds.getTop());
+ double distanceToBottom = location.getDistance(bounds.getBottom());
+ return distanceToTop < distanceToBottom;
+ }
+
+ /**
+ * Test whether the given request is closer to the source or to the target point of the message
+ *
+ * @param targetFigure
+ * The connection figure representing the message
+ * @param createRequest
+ * The create request
+ * @return
+ * <code>true</code> if the given request is closer to the source of the connection; false if it is closer to the target
+ */
+ public static boolean isSource(IFigure targetFigure, CreateRequest createRequest) {
+ Point location = createRequest.getLocation();
+ IFigure connection = targetFigure;
+ if (connection instanceof Connection) {
+ PointList points = ((Connection) connection).getPoints();
+ if (points.size() >= 2) {
+ Point source = points.getFirstPoint();
+ Point target = points.getLastPoint();
+ double distanceToSource = location.getDistance(source);
+ double distanceToTarget = location.getDistance(target);
+ return distanceToSource < distanceToTarget;
+ }
+ }
+
+ // Default; shouldn't happen, unless the Message figure is invalid,
+ // in which case we can't determine the source/target).
+ return true;
+ }
+
+}

Back to the top