From 94e017428e887c22c9a3ff100cbb5dbc61cd50ad Mon Sep 17 00:00:00 2001 From: Nicolas FAUVERGUE Date: Tue, 18 Sep 2018 13:53:00 +0200 Subject: Bug 536486 - [Sequence Diagram] Duration/time constraint & Duration/time observation and general ordering https://bugs.eclipse.org/bugs/show_bug.cgi?id=536486 - Manage Duration/Time constraint, Duration/Time observation and GeneralOrdering Change-Id: Ice6a31e9b4bb1e757378494a62a2714d775f47dd Signed-off-by: Nicolas FAUVERGUE --- .../gmfdiag/common/helper/FixAnchorHelper.java | 22 +++++++- .../common/helper/IdentityAnchorHelper.java | 59 +++++++++++++--------- 2 files changed, 55 insertions(+), 26 deletions(-) (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse') 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 5de99a35d5d..6e6b7d6ea23 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 @@ -21,6 +21,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; @@ -38,6 +39,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; @@ -141,6 +143,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(); @@ -345,12 +363,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/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(); } } -- cgit v1.2.3