Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/LifelineNodePlate.java30
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/ExecutionSpecificationNodePlate.java28
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/FigureHitTestUtil.java140
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineFigure.java95
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineNodeFigure.java17
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/CustomExecutionSpecificationCreationEditPolicy.java40
6 files changed, 311 insertions, 39 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/LifelineNodePlate.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/LifelineNodePlate.java
index 90dfbebb96d..a97e8898b64 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/LifelineNodePlate.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/LifelineNodePlate.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2018 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,12 +11,15 @@
* Contributors:
* CEA LIST - Initial API and implementation
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 531596
+ * Christian W. Damus - bug 539373
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence;
import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.TreeSearch;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
@@ -54,12 +57,13 @@ public class LifelineNodePlate extends LinkLFSVGNodePlateFigure {
}
- /**
- * @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getPolygonPoints()
- */
@Override
public PointList getPolygonPoints() {
- return ((NodeFigure) this.getChildren().get(0)).getPolygonPoints();
+ return getLifelineFigure().getPolygonPoints();
+ }
+
+ NodeFigure getLifelineFigure() {
+ return (NodeFigure) this.getChildren().get(0);
}
@Override
@@ -88,9 +92,6 @@ public class LifelineNodePlate extends LinkLFSVGNodePlateFigure {
}
}
- /**
- * @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#isDefaultAnchorArea(org.eclipse.draw2d.geometry.PrecisionPoint)
- */
@Override
protected boolean isDefaultAnchorArea(PrecisionPoint p) {
return false;
@@ -98,10 +99,13 @@ public class LifelineNodePlate extends LinkLFSVGNodePlateFigure {
@Override
public boolean containsPoint(int x, int y) {
- if (Math.abs(this.getBounds().x + this.getBounds().width / 2 - x) < 20) {
- return super.containsPoint(x, y);
- }
- return false;
+ return getLifelineFigure().containsPoint(x, y);
+ }
+
+ @Override
+ public final IFigure findFigureAt(int x, int y, TreeSearch search) {
+ NodeFigure lifeline = getLifelineFigure();
+ return lifeline.findFigureAt(x, y, search);
}
-} \ 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/figures/ExecutionSpecificationNodePlate.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/ExecutionSpecificationNodePlate.java
index 2a45154b9bc..39894b9df3d 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/ExecutionSpecificationNodePlate.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/ExecutionSpecificationNodePlate.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2017 CEA LIST and others.
+ * Copyright (c) 2017, 2018 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,15 +10,19 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus - bug 539373
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.figures;
import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.TreeSearch;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.figures.BorderedNodeFigure;
import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.LinkLFSVGNodePlateFigure;
import org.eclipse.papyrus.uml.diagram.sequence.anchors.AnchorConstants;
import org.eclipse.papyrus.uml.diagram.sequence.anchors.NodeBottomAnchor;
@@ -76,4 +80,26 @@ public class ExecutionSpecificationNodePlate extends LinkLFSVGNodePlateFigure im
}
return super.getConnectionAnchorTerminal(c);
}
+
+ @Override
+ public boolean containsPoint(int x, int y) {
+ boolean result = super.containsPoint(x, y);
+ if (!result) {
+ // Hit test my border items
+ BorderedNodeFigure parent = (BorderedNodeFigure) getParent();
+ result = parent.getBorderItemContainer().containsPoint(x, y);
+ }
+ return result;
+ }
+
+ @Override
+ public final IFigure findFigureAt(int x, int y, TreeSearch search) {
+ IFigure result = super.findFigureAt(x, y, search);
+ if (result == null) {
+ // Search my border items
+ BorderedNodeFigure parent = (BorderedNodeFigure) getParent();
+ result = parent.getBorderItemContainer().findFigureAt(x, y, search);
+ }
+ return result;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/FigureHitTestUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/FigureHitTestUtil.java
new file mode 100644
index 00000000000..3026fcc454a
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/FigureHitTestUtil.java
@@ -0,0 +1,140 @@
+/*****************************************************************************
+ * 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 2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.sequence.figures;
+
+import java.util.List;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.TreeSearch;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ * Hit-test utilities for {@code IFigure figure}s.
+ */
+public class FigureHitTestUtil {
+ public static final FigureHitTestUtil INSTANCE = new FigureHitTestUtil();
+
+ private static final int FUZZ_FACTOR = 2;
+
+ // A slightly fuzzy point for hit-testing on a polyline
+ private final Rectangle fuzzyPoint = new Rectangle(0, 0,
+ FUZZ_FACTOR * 2 + 1, FUZZ_FACTOR * 2 + 1);
+
+ /**
+ * Not instantiable by clients.
+ */
+ private FigureHitTestUtil() {
+ super();
+ }
+
+ /**
+ * Obtain the children of a figure as a typed list.
+ *
+ * @param figure
+ * a figure
+ * @return its children
+ */
+ @SuppressWarnings("unchecked")
+ public final List<? extends IFigure> getChildren(IFigure figure) {
+ return figure.getChildren();
+ }
+
+ /**
+ * Fuzzily test whether a {@code polygon} contains some point. Effectively,
+ * test whether the {@code polygon} overlaps a tiny square around the point.
+ *
+ * @param polygon
+ * a polygon
+ * @param x
+ * the X coördinate at which to search
+ * @param y
+ * the Y coördinate at which to search
+ * @return whether the point fuzzily is in the {@code polygon}
+ */
+ public boolean fuzzyHitTest(PointList polygon, int x, int y) {
+ boolean result = polygon.polygonContainsPoint(x, y);
+ if (!result) {
+ // If the center of our rectangle isn't in the polygon but
+ // any of it does overlap the polygon, then it must intersect
+ // the polygon boundary
+ fuzzyPoint.setLocation(x - FUZZ_FACTOR, y - FUZZ_FACTOR);
+ result = polygon.intersects(fuzzyPoint);
+ }
+ return result;
+ }
+
+ /**
+ * Query whether any child of a {@code figure} contains a point.
+ *
+ * @param figure
+ * a figure
+ * @param x
+ * the X coördinate at which to search
+ * @param y
+ * the Y coördinate at which to search
+ * @return whether any child of the {@code figure} contains the point
+ */
+ public boolean anyChildContainsPoint(IFigure figure, int x, int y) {
+ boolean result = false;
+
+ final List<? extends IFigure> children = getChildren(figure);
+
+ for (int i = children.size() - 1; i >= 0; i--) {
+ IFigure next = children.get(i);
+ if (next.isVisible() && next.containsPoint(x, y)) {
+ result = true;
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Find a child figure (recursively) at the given location, excluding
+ * the {@code figure}, itself.
+ *
+ * @param figure
+ * a figure in which to search for some child
+ * @param x
+ * the X coördinate at which to search
+ * @param y
+ * the Y coördinate at which to search
+ * @param search
+ * a tree search filter
+ *
+ * @return the child, or {@code null} if there is no child at this location
+ */
+ public IFigure findChildAt(IFigure figure, int x, int y, TreeSearch search) {
+ IFigure result = null;
+
+ final List<? extends IFigure> children = getChildren(figure);
+
+ for (int i = children.size() - 1; i >= 0; i--) {
+ IFigure next = children.get(i);
+ if (next.isVisible()) {
+ next = next.findFigureAt(x, y, search);
+ if (next != null) {
+ result = next;
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineFigure.java
index 73444a12e08..bbb8270c575 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineFigure.java
@@ -13,6 +13,7 @@
* Soyatec - Initial API and implementation
* Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 519408
* Vincent LORENZO (CEA LIST) vincent.lorenzo@cea.fr - Bug 531520
+ * Christian W. Damus - bug 539373
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.figures;
@@ -32,6 +33,7 @@ import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.RectangleFigure;
+import org.eclipse.draw2d.TreeSearch;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
@@ -74,6 +76,9 @@ public class LifelineFigure extends RoundedCompartmentFigure {
}
}
+ // Buffer on either side of the stem to take as hit area for mouse pointer
+ private static final int STEM_HIT_BUFFER = 20;
+
protected RectangleFigure lifelineHeaderBoundsFigure;
@Deprecated
@@ -89,6 +94,12 @@ public class LifelineFigure extends RoundedCompartmentFigure {
*/
private List<NodeFigure> childrenFigure = new ArrayList<>();
+ // The polygon to which connections (messages etc.) attach
+ private PointList cachedPolygon;
+
+ // A polygon defining the area in which the lifeline may be selected by the mouse pointer
+ private PointList cachedHitAreaPolygon;
+
/**
* Constructor.
*/
@@ -115,33 +126,57 @@ public class LifelineFigure extends RoundedCompartmentFigure {
*/
@Override
public PointList getPolygonPoints() {
- // we create the nude Lifeline figure
+ if (cachedPolygon == null) {
+ // we create the basic Lifeline figure
final PointList points = new PointList(8);
+
+ int bottomOfHeader = ((LifeLineLayoutManager) this.getLifeLineLayoutManager()).getBottomHeader();
+ Rectangle bounds = this.getBounds();
+ int right = bounds.right();
+ int midX = bounds.x + bounds.width / 2;
+
// top left corner
- points.addPoint(this.getBounds().x, this.getBounds().y);
+ points.addPoint(bounds.x, bounds.y);
// top right corner
- points.addPoint(this.getBounds().x + this.getBounds().width, this.getBounds().y);
+ points.addPoint(right, bounds.y);
// bottom header right corner
- points.addPoint(this.getBounds().x + this.getBounds().width, ((LifeLineLayoutManager) this.getLifeLineLayoutManager()).getBottomHeader());
+ points.addPoint(right, bottomOfHeader);
// bottom middle header
- points.addPoint(this.getBounds().x + this.getBounds().width / 2, ((LifeLineLayoutManager) this.getLifeLineLayoutManager()).getBottomHeader());
+ points.addPoint(midX, bottomOfHeader);
// middle bottom lifeline
- points.addPoint(this.getBounds().x + this.getBounds().width / 2, this.getBounds().y + this.getBounds().height);
+ points.addPoint(midX, bounds.bottom());
// bottom middle header
- points.addPoint(this.getBounds().x + this.getBounds().width / 2, ((LifeLineLayoutManager) this.getLifeLineLayoutManager()).getBottomHeader());
+ points.addPoint(midX, bottomOfHeader);
// bottom left header
- points.addPoint(this.getBounds().x, ((LifeLineLayoutManager) this.getLifeLineLayoutManager()).getBottomHeader());
+ points.addPoint(bounds.x, bottomOfHeader);
// top left header
- points.addPoint(this.getBounds().x, this.getBounds().y);
+ points.addPoint(bounds.x, bounds.y);
+
+ // Duplicate this basic shape for the hit area but make a wider target on the stem
+ final PointList hitArea = points.getCopy();
+ Point broadStem = new Point(midX + STEM_HIT_BUFFER, bottomOfHeader);
+ hitArea.setPoint(broadStem, 3);
+ broadStem.setY(bounds.bottom());
+ hitArea.setPoint(broadStem, 4);
+ broadStem.setX(midX - STEM_HIT_BUFFER);
+ hitArea.insertPoint(broadStem, 5); // This is a new point at the bottom of the stem
+ broadStem.setY(bottomOfHeader);
+ hitArea.setPoint(broadStem, 6);
+ cachedHitAreaPolygon = hitArea;
- if (this.childrenFigure.isEmpty()) {
- return points;
- } else {
// for bug 531520:
// all messages are now attached in the notation to the Lifeline
// we continue to represent them attached to the ExecutionSpeficiation, that why we complete the polygon list with the ExecutionSpeficiation of the Lifeline
- return completeFigureWithChildren(points);
+ cachedPolygon = completeFigureWithChildren(points);
}
+
+ return cachedPolygon;
+ }
+
+ private PointList getHitAreaPolygon() {
+ // Ensure it is computed
+ getPolygonPoints();
+ return cachedHitAreaPolygon;
}
/**
@@ -397,16 +432,17 @@ public class LifelineFigure extends RoundedCompartmentFigure {
// Draw dash line first to be under child
graphics.setLineDash(new int[] { 5, 5 });
graphics.drawLine(new Point(rect.x + rect.width / 2, ((LifeLineLayoutManager) this.getLifeLineLayoutManager()).getBottomHeader()), new Point(rect.x + rect.width / 2, rect.y + rect.height - 1));
- graphics.popState();
- // to draw the anchor shape for debug (bug 531520)
- // if (false == this.childrenFigure.isEmpty()) {
- // graphics.setForegroundColor(new Color(Display.getDefault(), new RGB(255, 0, 0)));
- // PointList pol = getPolygonPoints();
+ // DEBUG: to draw the convex hull of the lifeline shape (bug 531520)
+ // if (!this.childrenFigure.isEmpty()) {
+ // graphics.setForegroundColor(org.eclipse.draw2d.ColorConstants.red);
+ // PointList pol = getPolygonPoints(); // getHitAreaPolygon();
// graphics.drawPolygon(pol);
// graphics.setForegroundColor(getForegroundColor());
// }
+ graphics.popState();
+
// Then finish to draw figure.
super.paint(graphics);
@@ -509,6 +545,29 @@ public class LifelineFigure extends RoundedCompartmentFigure {
this.childrenFigure = childrenFigure == null ? Collections.emptyList() : childrenFigure;
}
+ @Override
+ public void invalidate() {
+ cachedPolygon = null;
+ cachedHitAreaPolygon = null;
+ super.invalidate();
+ }
+
+ @Override
+ public boolean containsPoint(int x, int y) {
+ // The easy case: on the lifeline itself (and its buffer zone)
+ boolean result = getHitAreaPolygon().polygonContainsPoint(x, y);
+ if (!result) {
+ // Drill into children for their border items etc.
+ result = FigureHitTestUtil.INSTANCE.anyChildContainsPoint(this, x, y);
+ }
+ return result;
+ }
+
+ @Override
+ protected IFigure findDescendantAtExcluding(int x, int y, TreeSearch search) {
+ // Our client area is degenerate, so don't consider it as super does
+ return FigureHitTestUtil.INSTANCE.findChildAt(this, x, y, search);
+ }
/**
*
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineNodeFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineNodeFigure.java
index 159687ec9f1..c36d6902b68 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineNodeFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/LifelineNodeFigure.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2018 CEA LIST and others.
+ * Copyright (c) 2018 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus - bug 539373
*
*****************************************************************************/
@@ -34,10 +35,14 @@ public class LifelineNodeFigure extends SelectableBorderedNodeFigure {
@Override
public boolean containsPoint(int x, int y) {
- if (Math.abs(this.getBounds().x + this.getBounds().width / 2 - x) < 20) {
- return super.containsPoint(x, y); // check also the other bounds
+ // Hit test the lifeline itself with execution specifications
+ boolean result = getMainFigure().containsPoint(x, y);
+ if (!result) {
+ // Try the border items (e.g., time observations)
+ result = FigureHitTestUtil.INSTANCE.anyChildContainsPoint(
+ getBorderItemContainer(), x, y);
}
- return false;
+ return result;
}
@Override
@@ -45,11 +50,11 @@ public class LifelineNodeFigure extends SelectableBorderedNodeFigure {
if (search.prune(this)) {
return null;
}
- IFigure result = getBorderItemContainer().findFigureAt(x, y, search);
+ IFigure result = FigureHitTestUtil.INSTANCE.findChildAt(getBorderItemContainer(), x, y, search);
if (result != null) {
return result;
}
return getMainFigure().findFigureAt(x, y, search);
}
-} \ 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/CustomExecutionSpecificationCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/CustomExecutionSpecificationCreationEditPolicy.java
index 04f217139e8..3bf1c87c5cb 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/CustomExecutionSpecificationCreationEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/CustomExecutionSpecificationCreationEditPolicy.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2017 CEA LIST and others.
+ * Copyright (c) 2017, 2018 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,23 +10,36 @@
*
* Contributors:
* Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 539373
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling;
+import static org.eclipse.papyrus.uml.service.types.utils.ElementUtil.isTypeOf;
+
+import java.util.stream.Stream;
+
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.util.DurationLinkUtil;
+import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
import org.eclipse.papyrus.uml.service.types.element.UMLDIElementTypes;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
/**
* This allows to define the creation edit policy for the execution specification.
@@ -51,4 +64,29 @@ public class CustomExecutionSpecificationCreationEditPolicy extends DefaultCreat
}
return super.getSetBoundsCommand(request, descriptor);
}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public EditPart getTargetEditPart(Request request) {
+ EditPart result = super.getTargetEditPart(request);
+ if (!(request instanceof CreateRequest)) {
+ return result;
+ }
+
+ Stream<? extends IElementType> elementTypes = null;
+ if (request instanceof CreateViewAndElementRequest) {
+ elementTypes = ((CreateViewAndElementRequest) request).getViewDescriptors().stream()
+ .map(v -> v.getElementAdapter().getAdapter(IElementType.class));
+ } else if (request instanceof CreateUnspecifiedTypeRequest) {
+ elementTypes = ((CreateUnspecifiedTypeRequest) request).getElementTypes().stream();
+ }
+ if ((elementTypes != null) && elementTypes.anyMatch(type -> isTypeOf(type, UMLElementTypes.EXECUTION_SPECIFICATION))) {
+ // The lifeline is responsible for creating all execution specifications, as they
+ // are semantically all children of it (nesting is strictly visual)
+ return SequenceUtil.getParentLifelinePart(getHost());
+ }
+
+ return result;
+ }
+
}

Back to the top