Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-07-04 09:11:19 -0400
committerCamille Letavernier2018-09-24 06:48:15 -0400
commit10e5a6a5cb69413ce9edc3bfe803441197ea5255 (patch)
tree9de94c664b19b8048995f7a874dd19f2f943f7f0
parent6db391f608829b25a7069f72eb2501363bd4aebd (diff)
downloadorg.eclipse.papyrus-10e5a6a5cb69413ce9edc3bfe803441197ea5255.tar.gz
org.eclipse.papyrus-10e5a6a5cb69413ce9edc3bfe803441197ea5255.tar.xz
org.eclipse.papyrus-10e5a6a5cb69413ce9edc3bfe803441197ea5255.zip
Bug 536638: [Sequence Diagram] Provide OccurrenceSpecification Anchors
for Durations https://bugs.eclipse.org/bugs/show_bug.cgi?id=536638 - Deprecate IdentityAnchorHelper#getPercentage methods, as it causes runtime exceptions with all IdentityAnchors that do not represent a SlidableAnchor. Change-Id: I9df66c088d07274b2bf537b6df216debf2aca4b2 Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java59
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DestructionEventFigure.java50
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectRectangleToGridEditPolicy.java35
3 files changed, 87 insertions, 57 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
index 73cb24315aa..d7138f8c37b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2018 CEA LIST, EclipseSource and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,10 +11,13 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * EclipseSource - Bug 536638
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
import org.eclipse.gmf.runtime.notation.IdentityAnchor;
/**
@@ -43,7 +46,7 @@ public class IdentityAnchorHelper {
/**
* the char separating percentage as string in ids of {@link IdentityAnchor}
*/
- public static final String X_Y_SEPARATOR_AS_STRING = new String(new char[] { X_Y_SEPARATOR });
+ public static final String X_Y_SEPARATOR_AS_STRING = Character.toString(X_Y_SEPARATOR);
/**
*
@@ -57,14 +60,21 @@ public class IdentityAnchorHelper {
/**
*
* @param anchor
- * an anchor
+ * an {@link IdentityAnchor} representing a {@link BaseSlidableAnchor}
* @return
- * the value of x percentage
+ * the value of x percentage
+ * @deprecated
+ * This method only supports {@link IdentityAnchor IdentityAnchors} representing a {@link BaseSlidableAnchor}. Other
+ * anchors would cause an exception. Use {@link BaseSlidableAnchor#parseTerminalString(String)} instead; and check if the
+ * resulting point is != null (If null, then the {@link IdentityAnchor} doesn't represent a {@link BaseSlidableAnchor})
*/
+ @Deprecated
public static final double getXPercentage(final IdentityAnchor anchor) {
- String id = anchor.getId();
- id = id.substring(1, id.indexOf(X_Y_SEPARATOR_AS_STRING));
- return Double.parseDouble(id);
+ PrecisionPoint point = BaseSlidableAnchor.parseTerminalString(anchor.getId());
+ if (point == null) {
+ throw new IllegalArgumentException("Anchor " + anchor.getId() + " is not a valid BaseSlidableAnchor");
+ }
+ return point.preciseX();
}
/**
@@ -72,18 +82,19 @@ public class IdentityAnchorHelper {
* @param anchor
* an anchor
* @return
- * the value of y percentage
+ * the value of y percentage
+ * @deprecated
+ * This method only supports {@link IdentityAnchor IdentityAnchors} representing a {@link BaseSlidableAnchor}. Other
+ * anchors would cause an exception. Use {@link BaseSlidableAnchor#parseTerminalString(String)} instead; and check if the
+ * resulting point is != null (If null, then the {@link IdentityAnchor} doesn't represent a {@link BaseSlidableAnchor})
*/
+ @Deprecated
public static final double getYPercentage(final IdentityAnchor anchor) {
- String id = anchor.getId();
- if(id.indexOf(X_Y_SEPARATOR_AS_STRING)==-1) {
- return 0;
- }
- id = id.substring(id.indexOf(X_Y_SEPARATOR_AS_STRING) + 1, id.length() - 1);
- if(id.indexOf(END_ID)!=-1){
- id = id.substring(0, id.indexOf(END_ID));
+ PrecisionPoint point = BaseSlidableAnchor.parseTerminalString(anchor.getId());
+ if (point == null) {
+ throw new IllegalArgumentException("Anchor " + anchor.getId() + " is not a valid BaseSlidableAnchor");
}
- return Double.parseDouble(id);
+ return point.preciseY();
}
@@ -94,15 +105,15 @@ public class IdentityAnchorHelper {
* @param percentageOnY
* the percentage on y
* @return
- * the string representing the new id for an anchor
+ * the string representing the new id for an anchor
*/
public static final String createNewAnchorIdValue(final double percentageOnX, final double percentageOnY) {
- final StringBuffer buffer = new StringBuffer();
- buffer.append(START_ID);
- buffer.append(Double.toString(percentageOnX));
- buffer.append(X_Y_SEPARATOR_AS_STRING);
- buffer.append(Double.toString(percentageOnY));
- buffer.append(END_ID);
- return buffer.toString();
+ final StringBuilder builder = new StringBuilder();
+ builder.append(START_ID);
+ builder.append(Double.toString(percentageOnX));
+ builder.append(X_Y_SEPARATOR_AS_STRING);
+ builder.append(Double.toString(percentageOnY));
+ builder.append(END_ID);
+ return builder.toString();
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DestructionEventFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DestructionEventFigure.java
index 6d2ca825903..a4224978805 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DestructionEventFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/figures/DestructionEventFigure.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2005 AIRBUS FRANCE.
+ * Copyright (c) 2005, 2018 AIRBUS FRANCE, 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 2.0
@@ -14,37 +14,33 @@
* Jacques Lescot (Anyware Technologies),
* Thomas Friol (Anyware Technologies),
* Nicolas Lalevee (Anyware Technologies) - initial API and implementation
+ * EclipseSource - Bug 536638
*
****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.figures;
+import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
+import org.eclipse.papyrus.uml.diagram.sequence.anchors.AnchorConstants;
+import org.eclipse.papyrus.uml.diagram.sequence.anchors.CenterAnchor;
+import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
/**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
+ * Figure for a {@link DestructionOccurrenceSpecification}. It is drawn as an X centered over a Lifeline body
*/
-public class DestructionEventFigure extends org.eclipse.draw2d.Figure {
+public class DestructionEventFigure extends DefaultSizeNodeFigure {
+
+ private int lineWidth = 1;
/**
* Constructor <!-- begin-user-doc --> <!-- end-user-doc -->
- *
- * @generated
*/
public DestructionEventFigure() {
- super();
- }
- /**
- * @return a <code>Dimension</code> that represents the minimum or default size of
- * this figure.
- * @since 3.0
- */
- public Dimension getDefaultSize() {
- return new Dimension(40,40);
+ super(40, 40);
}
+
/**
* The stop is a cross
*
@@ -55,11 +51,12 @@ public class DestructionEventFigure extends org.eclipse.draw2d.Figure {
super.paintFigure(graphics);
graphics.pushState();
graphics.setLineWidth(2);
- graphics.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height);
- graphics.drawLine(bounds.x, bounds.y+ bounds.height, bounds.x + bounds.width, bounds.y);
+ graphics.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height);
+ graphics.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width, bounds.y);
graphics.popState();
}
+ @Override
public void setLineWidth(int w) {
if ((lineWidth == w) || (w < 0)) {
return;
@@ -68,5 +65,18 @@ public class DestructionEventFigure extends org.eclipse.draw2d.Figure {
repaint();
}
- private int lineWidth = 1;
+ /**
+ * @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getConnectionAnchor(java.lang.String)
+ *
+ * @param terminal
+ * @return
+ */
+ @Override
+ public ConnectionAnchor getConnectionAnchor(String terminal) {
+ if (AnchorConstants.CENTER_TERMINAL.equals(terminal)) {
+ return new CenterAnchor(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/referencialgrilling/ConnectRectangleToGridEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectRectangleToGridEditPolicy.java
index e108b1be794..01cdc14dc54 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectRectangleToGridEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectRectangleToGridEditPolicy.java
@@ -17,6 +17,7 @@
package org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
@@ -27,6 +28,7 @@ import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.notation.Bounds;
import org.eclipse.gmf.runtime.notation.DecorationNode;
@@ -391,17 +393,20 @@ public class ConnectRectangleToGridEditPolicy extends ConnectToGridEditPolicy im
*/
protected void updateAnchorFromHeight(IdentityAnchor anchor, Node node, int deltaHeight) {
if (null != anchor) {
- double yPercent = IdentityAnchorHelper.getYPercentage(anchor);
- double xPercent = IdentityAnchorHelper.getXPercentage(anchor);
-
- // calculate bounds from notation
- int nodeHeight = BoundForEditPart.getHeightFromView(node);
- double oldHeight = nodeHeight - deltaHeight;
- double preciseHeight = nodeHeight;
-
- double newPercentY = (yPercent * oldHeight) / preciseHeight;
- final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(xPercent, newPercentY);
- execute(new SetCommand(getDiagramEditPart(getHost()).getEditingDomain(), anchor, NotationPackage.eINSTANCE.getIdentityAnchor_Id(), newIdValue));
+ PrecisionPoint anchorLocation = BaseSlidableAnchor.parseTerminalString(anchor.getId());
+ if (anchorLocation != null) {
+ double yPercent = anchorLocation.preciseY();
+ double xPercent = anchorLocation.preciseX();
+
+ // calculate bounds from notation
+ int nodeHeight = BoundForEditPart.getHeightFromView(node);
+ double oldHeight = nodeHeight - deltaHeight;
+ double preciseHeight = nodeHeight;
+
+ double newPercentY = (yPercent * oldHeight) / preciseHeight;
+ final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(xPercent, newPercentY);
+ execute(new SetCommand(getDiagramEditPart(getHost()).getEditingDomain(), anchor, NotationPackage.eINSTANCE.getIdentityAnchor_Id(), newIdValue));
+ }
}
}
@@ -419,8 +424,12 @@ public class ConnectRectangleToGridEditPolicy extends ConnectToGridEditPolicy im
*/
protected void updateAnchorFromY(IdentityAnchor anchor, Node node, int oldY, int newY) {
if (null != anchor && !anchor.getId().trim().equals("")) { //$NON-NLS-1$
- double yPercent = IdentityAnchorHelper.getYPercentage(anchor);
- double xPercent = IdentityAnchorHelper.getXPercentage(anchor);
+ PrecisionPoint anchorLocation = BaseSlidableAnchor.parseTerminalString(anchor.getId());
+ if (anchorLocation == null) {
+ return;
+ }
+ double yPercent = anchorLocation.preciseY();
+ double xPercent = anchorLocation.preciseX();
// calculate bounds from notation
double height = BoundForEditPart.getHeightFromView(node);

Back to the top