Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2018-07-04 09:11:19 -0400
committerCamille Letavernier2018-07-30 08:20:36 -0400
commit6a18860cbe7a0e1445dfc63e529d1a05d133fb81 (patch)
tree28cc7ba5c7ae081ac0fceb8b4a88a5ac86d898ae
parent339e288c348725f3d08e841c88035b65ce05f384 (diff)
downloadorg.eclipse.papyrus-6a18860cbe7a0e1445dfc63e529d1a05d133fb81.tar.gz
org.eclipse.papyrus-6a18860cbe7a0e1445dfc63e529d1a05d133fb81.tar.xz
org.eclipse.papyrus-6a18860cbe7a0e1445dfc63e529d1a05d133fb81.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.java65
-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, 96 insertions, 63 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 9fd8182aa2e..5ea49184f97 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
@@ -9,10 +9,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;
/**
@@ -41,7 +44,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);
/**
*
@@ -55,14 +58,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();
}
/**
@@ -70,18 +80,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();
}
@@ -92,15 +103,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 1db49c0d1f1..a568fe06ce3 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,43 +1,42 @@
/*******************************************************************************
- * Copyright (c) 2005 AIRBUS FRANCE. 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
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors: David Sciamma (Anyware Technologies), Mathieu Garcia (Anyware
- * Technologies), Jacques Lescot (Anyware Technologies), Thomas Friol (Anyware
- * Technologies), Nicolas Lalevee (Anyware Technologies) - initial API and
- * implementation
+ * Contributors:
+ * David Sciamma (Anyware Technologies), Mathieu Garcia (Anyware
+ * Technologies), 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
*
@@ -48,11 +47,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;
@@ -61,5 +61,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 bba8bc51415..a8df5ed76e4 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
@@ -15,6 +15,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;
@@ -25,6 +26,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;
@@ -389,17 +391,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));
+ }
}
}
@@ -417,8 +422,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