diff options
author | Camille Letavernier | 2018-07-04 13:10:25 +0000 |
---|---|---|
committer | Camille Letavernier | 2018-07-30 12:20:34 +0000 |
commit | 339e288c348725f3d08e841c88035b65ce05f384 (patch) | |
tree | dcedc44bc1b285a0bcbe9b33f5696dbc524888e8 | |
parent | 2f8f0d9e7dca31bd12707c360ef871687c21990b (diff) | |
download | org.eclipse.papyrus-339e288c348725f3d08e841c88035b65ce05f384.tar.gz org.eclipse.papyrus-339e288c348725f3d08e841c88035b65ce05f384.tar.xz org.eclipse.papyrus-339e288c348725f3d08e841c88035b65ce05f384.zip |
Bug 536638: [Sequence Diagram] Provide OccurrenceSpecification Anchors
for Durations
https://bugs.eclipse.org/bugs/show_bug.cgi?id=536638
- Add anchors for ExecutionSpecifications and Messages
Change-Id: I99ebf56afa8ca4d433c18e7ba7d4dfc9b406c180
Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
11 files changed, 312 insertions, 3 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java index 0b61105bbcc..e2ab8201b1d 100755 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java @@ -19,6 +19,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.draw2d.AbstractPointListShape; +import org.eclipse.draw2d.Connection; import org.eclipse.draw2d.ConnectionAnchor; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; @@ -36,6 +37,7 @@ import org.eclipse.gmf.runtime.common.core.command.CommandResult; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart; +import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor; import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx; import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; @@ -139,6 +141,22 @@ public class FixAnchorHelper { protected Point getRealAnchorPoint(final AbstractConnectionEditPart edgeEP, final boolean sourcePoint) { final IFigure figure = edgeEP.getFigure(); Point point = null; + if (figure instanceof Connection) { + // Bug 536638: We now have specific Anchors that are dynamically computed, and not based on a X/Y Ratio + // We *don't* want to "fix" these! + Connection connection = (Connection) figure; + if (sourcePoint && connection.getSourceAnchor() != null) { + ConnectionAnchor sourceAnchor = connection.getSourceAnchor(); + if (false == sourceAnchor instanceof BaseSlidableAnchor) { + return null; + } + } else if (!sourcePoint && connection.getTargetAnchor() != null) { + ConnectionAnchor targetAnchor = connection.getTargetAnchor(); + if (false == targetAnchor instanceof BaseSlidableAnchor) { + return null; + } + } + } if (figure instanceof AbstractPointListShape) { if (sourcePoint) { point = ((AbstractPointListShape) figure).getStart().getCopy(); @@ -343,12 +361,12 @@ public class FixAnchorHelper { /** * Return the side of the point on the included Rectangle - * + * * @since 3.1 * @param pt * Point with absolute position * @return integer representing the position from PositionConstants. - * + * */ protected int getSideFromRectangle(Point pt) { while (getIncludedRect().contains(pt)) { diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/AnchorConstants.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/AnchorConstants.java new file mode 100644 index 00000000000..fe9339c31b0 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/AnchorConstants.java @@ -0,0 +1,72 @@ +/***************************************************************************** + * 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.anchors; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.uml2.uml.DestructionOccurrenceSpecification; +import org.eclipse.uml2.uml.ExecutionSpecification; +import org.eclipse.uml2.uml.Message; + +/** + * Constants class for Anchors + */ +public final class AnchorConstants { + private AnchorConstants() { + // Constants class; no instance + } + + /** + * <p> + * The Anchor Terminal for an Anchor at the start/beginning of an element. + * </p> + * + * <p> + * This anchor represents a single point (Which depends on the anchorage {@link IFigure}), without any parameter. + * </p> + * + * <p> + * This anchor may represent, for example, the start of an {@link ExecutionSpecification}, or the source Send Event of a {@link Message} + * </p> + */ + public static final String START_TERMINAL = "start"; + + /** + * <p> + * The Anchor Terminal for an Anchor at the finish/end of an element. + * </p> + * + * <p> + * This anchor represents a single point (Which depends on the anchorage {@link IFigure}), without any parameter. + * </p> + * + * <p> + * This anchor may represent, for example, the finish of an {@link ExecutionSpecification}, or the target Receive Event of a {@link Message} + * </p> + */ + public static final String END_TERMINAL = "end"; + + /** + * <p> + * The Anchor Terminal for an Anchor at the center of an element. + * </p> + * + * <p> + * This anchor represents a single point (Which depends on the anchorage {@link IFigure}), without any parameter. + * </p> + * + * <p> + * This anchor typically represents the center of the X in a {@link DestructionOccurrenceSpecification} + * </p> + */ + public static final String CENTER_TERMINAL = "center"; +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/CenterAnchor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/CenterAnchor.java new file mode 100644 index 00000000000..be94663a889 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/CenterAnchor.java @@ -0,0 +1,36 @@ +/***************************************************************************** + * 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.anchors; + +import org.eclipse.draw2d.AbstractConnectionAnchor; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.uml2.uml.DestructionOccurrenceSpecification; + +/** + * An anchor to the center of an element (Typically a {@link DestructionOccurrenceSpecification}) + */ +public class CenterAnchor extends AbstractConnectionAnchor { + + public CenterAnchor(IFigure anchorage) { + super(anchorage); + } + + @Override + public Point getLocation(Point reference) { + Point center = getOwner().getBounds().getCenter().getCopy(); + getOwner().translateToAbsolute(center); + return center; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/ConnectionSourceAnchor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/ConnectionSourceAnchor.java new file mode 100644 index 00000000000..6da15ce29b3 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/ConnectionSourceAnchor.java @@ -0,0 +1,38 @@ +/***************************************************************************** + * 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.anchors; + +import org.eclipse.draw2d.AbstractConnectionAnchor; +import org.eclipse.draw2d.PolylineConnection; +import org.eclipse.draw2d.geometry.Point; + +/** + * Anchors a Connection to the source of a {@link PolylineConnection} (Typically the sendEvent of a Message) + */ +public class ConnectionSourceAnchor extends AbstractConnectionAnchor { + + private final PolylineConnection anchorage; + + public ConnectionSourceAnchor(PolylineConnection anchorage) { + super(anchorage); + this.anchorage = anchorage; + } + + @Override + public Point getLocation(Point reference) { + Point source = anchorage.getStart().getCopy(); + anchorage.translateToAbsolute(source); + return source; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/ConnectionTargetAnchor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/ConnectionTargetAnchor.java new file mode 100644 index 00000000000..eeea63e49b6 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/ConnectionTargetAnchor.java @@ -0,0 +1,39 @@ +/***************************************************************************** + * 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.anchors; + +import org.eclipse.draw2d.AbstractConnectionAnchor; +import org.eclipse.draw2d.PolylineConnection; +import org.eclipse.draw2d.geometry.Point; + + +/** + * Anchors a Connection to the target of a {@link PolylineConnection} (Typically the receiveEvent of a Message) + */ +public class ConnectionTargetAnchor extends AbstractConnectionAnchor { + + private final PolylineConnection anchorage; + + public ConnectionTargetAnchor(PolylineConnection anchorage) { + super(anchorage); + this.anchorage = anchorage; + } + + @Override + public Point getLocation(Point reference) { + Point target = anchorage.getEnd().getCopy(); + anchorage.translateToAbsolute(target); + return target; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/NodeBottomAnchor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/NodeBottomAnchor.java new file mode 100644 index 00000000000..efd72365047 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/NodeBottomAnchor.java @@ -0,0 +1,36 @@ +/***************************************************************************** + * 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.anchors; + +import org.eclipse.draw2d.AbstractConnectionAnchor; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; + +/** + * Anchors a Connection to the Bottom-Center point of a Node (Typically the finish of an Execution Specification) + */ +public class NodeBottomAnchor extends AbstractConnectionAnchor { + + public NodeBottomAnchor(IFigure anchorage) { + super(anchorage); + } + + @Override + public Point getLocation(Point reference) { + IFigure owner = getOwner(); + Point bottom = owner.getBounds().getBottom().getCopy(); + owner.translateToAbsolute(bottom); + return bottom; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/NodeTopAnchor.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/NodeTopAnchor.java new file mode 100644 index 00000000000..f11b1fdc436 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/anchors/NodeTopAnchor.java @@ -0,0 +1,36 @@ +/***************************************************************************** + * 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.anchors; + +import org.eclipse.draw2d.AbstractConnectionAnchor; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; + +/** + * Anchors a Connection to the Top-Center point of a Node (Typically the start of an Execution Specification) + */ +public class NodeTopAnchor extends AbstractConnectionAnchor { + + public NodeTopAnchor(IFigure anchorage) { + super(anchorage); + } + + @Override + public Point getLocation(Point reference) { + IFigure owner = getOwner(); + Point top = owner.getBounds().getTop().getCopy(); + owner.translateToAbsolute(top); + return top; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DurationLinkFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DurationLinkFigure.java index babfbb5dfd0..d3063197edd 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DurationLinkFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DurationLinkFigure.java @@ -14,6 +14,7 @@ package org.eclipse.papyrus.uml.diagram.sequence.figures; import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.ConnectionRouter; import org.eclipse.draw2d.Graphics; import org.eclipse.draw2d.PolylineConnection; import org.eclipse.draw2d.PolylineDecoration; @@ -189,7 +190,7 @@ public class DurationLinkFigure extends UMLEdgeFigure { public boolean containsPoint(int x, int y) { Rectangle topLine = new Rectangle(getStart(), getTopLineEnd()); topLine.expand(SELECTION_TOLERANCE, SELECTION_TOLERANCE); - if (topLine.contains(x, y)){ + if (topLine.contains(x, y)) { return true; } @@ -233,6 +234,11 @@ public class DurationLinkFigure extends UMLEdgeFigure { return bounds; } + @Override + public void setConnectionRouter(ConnectionRouter cr) { + // Skip; this figure doesn't support routers/bendpoints + } + /** * <p> * Set the orientation of the arrow (Orientation#VERTICAL or Orientation#HORIZONTAL). 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 48d512dc7b6..3a6c01fd127 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 @@ -18,6 +18,9 @@ import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.geometry.PrecisionPoint; import org.eclipse.gef.GraphicalEditPart; 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; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.NodeTopAnchor; import org.eclipse.papyrus.uml.diagram.sequence.edit.helpers.AnchorHelper; /** @@ -46,6 +49,12 @@ public class ExecutionSpecificationNodePlate extends LinkLFSVGNodePlateFigure im @Override public ConnectionAnchor getConnectionAnchor(String terminal) { + if (AnchorConstants.START_TERMINAL.equals(terminal)) { + return new NodeTopAnchor(this); + } else if (AnchorConstants.END_TERMINAL.equals(terminal)) { + return new NodeBottomAnchor(this); + } + // Use FixedAnchorEx for MessageSync, this will be invoked by mapConnectionAnchor(termial) operation. if (terminal != null && terminal.indexOf("{") != -1 && terminal.indexOf("}") != -1) { int position = AnchorHelper.FixedAnchorEx.parsePosition(terminal); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/MessageFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/MessageFigure.java index 41a0026f7f1..f4754c4d938 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/MessageFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/MessageFigure.java @@ -14,6 +14,7 @@ package org.eclipse.papyrus.uml.diagram.sequence.figures; import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.ConnectionAnchor; import org.eclipse.draw2d.RotatableDecoration; import org.eclipse.draw2d.Shape; import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; @@ -21,6 +22,9 @@ import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode; import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; import org.eclipse.papyrus.uml.diagram.common.figure.edge.UMLEdgeFigure; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.AnchorConstants; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.ConnectionSourceAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.ConnectionTargetAnchor; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Cursor; @@ -178,4 +182,15 @@ public abstract class MessageFigure extends UMLEdgeFigure { public void setMapMode(IMapMode mapMode) { this.mapMode = mapMode; } + + + @Override + public ConnectionAnchor getConnectionAnchor(String terminal) { + if (AnchorConstants.START_TERMINAL.equals(terminal)) { + return new ConnectionSourceAnchor(this); + } else if (AnchorConstants.END_TERMINAL.equals(terminal)) { + return new ConnectionTargetAnchor(this); + } + return super.getConnectionAnchor(terminal); + } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java index b83f8c5bfc7..079c6f0707f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java @@ -531,6 +531,10 @@ public class SequenceUtil { // get position from anchor id String oldTerminal = ((IdentityAnchor) idAnchor).getId(); PrecisionPoint pp = BaseSlidableAnchor.parseTerminalString(oldTerminal); + if (pp == null) { + // Not a BaseSlidableAnchor + return null; + } if (pp.preciseX() <= 1 && pp.preciseX() >= 0 && pp.preciseY() >= 0 && pp.preciseY() <= 1) { int xPos = linkedPartBounds.x + delta.width + (int) Math.round(anchorOwningFigure.getBounds().width * pp.preciseX()); int yPos = linkedPartBounds.y + delta.height + (int) Math.round(anchorOwningFigure.getBounds().height * pp.preciseY()); |