diff options
author | mgolubev | 2014-08-28 03:59:02 +0000 |
---|---|---|
committer | mgolubev | 2014-08-28 09:37:30 +0000 |
commit | af2782074d574866d9406870f5df1572d2fbe109 (patch) | |
tree | a0de9c356d2b55518d9ac1440e04d10a63a22954 | |
parent | 9ce363ece09580002f2e235ed384604a6d639f44 (diff) | |
download | org.eclipse.papyrus-af2782074d574866d9406870f5df1572d2fbe109.tar.gz org.eclipse.papyrus-af2782074d574866d9406870f5df1572d2fbe109.tar.xz org.eclipse.papyrus-af2782074d574866d9406870f5df1572d2fbe109.zip |
[442161]: With snap to grid, bendpoints from routing should be on gridcommitters/mgolubev/anchors
[442159]: Enable LinksLF for links from old diagrams
[442158]: Bendpoints of links between inner nodes should move when
container is moved
[442156] Affixed nodes should only allow anchors on 2 of 4 sides
(backported from GMF)
Change-Id: I28fc62098dee00b2f8e3910f6dd7b30692b074fe
Signed-off-by: mgolubev <golubev@montages.com>
15 files changed, 823 insertions, 218 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/AbsoluteBendpointsConvention.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/AbsoluteBendpointsConvention.java index 8298f78f3a6..b0ac64428a7 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/AbsoluteBendpointsConvention.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/AbsoluteBendpointsConvention.java @@ -1,10 +1,12 @@ package org.eclipse.papyrus.infra.gmfdiag.common.linklf; +import java.util.Collections; import java.util.List; import org.eclipse.draw2d.AbsoluteBendpoint; import org.eclipse.draw2d.Bendpoint; import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.ConnectionAnchor; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; @@ -12,49 +14,220 @@ import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.RelativeBendpoints; import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint; -public class AbsoluteBendpointsConvention { +/** + * This class defines when to enable the enhanced link anchors and bendpoints behavior, + * which implementation is based on storing the fixed bendpoints coordinates instead of their relative locations to + * anchors. + */ +public abstract class AbsoluteBendpointsConvention { - private static final int MAGIC = -643984; + private static AbsoluteBendpointsConvention ourInstance; - public static RelativeBendpoint createAbsoluteBendpointStoredAsRelative(Point point) { - return new RelativeBendpoint(point.x, point.y, MAGIC, MAGIC); + public static AbsoluteBendpointsConvention getInstance() { + if(ourInstance == null) { + //ourInstance = new OnlyForNewLinks(); + ourInstance = new ForAllLinks(); + } + return ourInstance; } - public static boolean isAbsoluteStoredAsRelative(RelativeBendpoint modelBP) { - return modelBP.getTargetX() == MAGIC && modelBP.getTargetY() == MAGIC; - } + public abstract RelativeBendpoint createAbsoluteBendpointStoredAsRelative(Point point); + + public abstract boolean isAbsoluteStoredAsRelative(RelativeBendpoint modelBP); + + public abstract Bendpoint d2dBendpoint(RelativeBendpoint modelBP, Connection connection, float weight); + + public abstract boolean hasAbsoluteStoredAsRelativeBendpoints(Edge edge); + + public abstract PointList getPointList(Edge edge, Object linkConstraint); + + private abstract static class ConventionBase extends AbsoluteBendpointsConvention { - public static Bendpoint d2dBendpoint(RelativeBendpoint modelBP, Connection connection, float weight) { - if(isAbsoluteStoredAsRelative(modelBP)) { - return new AbsoluteBendpoint(modelBP.getSourceX(), modelBP.getSourceY()); + private static final int MAGIC = -643984; + + @Override + public RelativeBendpoint createAbsoluteBendpointStoredAsRelative(Point point) { + return new RelativeBendpoint(point.x, point.y, MAGIC, MAGIC); + } + + @Override + public boolean isAbsoluteStoredAsRelative(RelativeBendpoint modelBP) { + return modelBP.getTargetX() == MAGIC && modelBP.getTargetY() == MAGIC; } - org.eclipse.draw2d.RelativeBendpoint rbp = new org.eclipse.draw2d.RelativeBendpoint(connection); - rbp.setRelativeDimensions(new Dimension(modelBP.getSourceX(), modelBP.getSourceY()), // - new Dimension(modelBP.getTargetX(), modelBP.getTargetY())); - rbp.setWeight(weight); - return rbp; + + @Override + public Bendpoint d2dBendpoint(RelativeBendpoint modelBP, Connection connection, float weight) { + if(isAbsoluteStoredAsRelative(modelBP)) { + return new AbsoluteBendpoint(modelBP.getSourceX(), modelBP.getSourceY()); + } + return null; + } + + @Override + public PointList getPointList(Edge edge, Object linkConstraint) { + PointList result = new PointList(); + List<?> d2dBendpoints = linkConstraint instanceof List<?> ? (List<?>)linkConstraint : Collections.emptyList(); + RelativeBendpoints allModelBendpoints = (RelativeBendpoints)edge.getBendpoints(); + @SuppressWarnings("unchecked") + List<RelativeBendpoint> modelBendpoints = allModelBendpoints.getPoints(); + for(int i = 0; i < modelBendpoints.size(); i++) { + RelativeBendpoint nextModel = modelBendpoints.get(i); + Object nextD2d = d2dBendpoints.size() > i ? d2dBendpoints.get(i) : null; + + Point nextPoint = getLocation(nextModel, nextD2d); + if(nextPoint == null) { + throw new IllegalStateException("Can't extract location: modelBP: " + nextModel + ", d2dBP: " + nextD2d); + } + result.addPoint(nextPoint); + } + return result; + } + + protected static org.eclipse.draw2d.RelativeBendpoint newRelativeBendpointD2d(RelativeBendpoint modelBP, Connection connection, float weight) { + org.eclipse.draw2d.RelativeBendpoint rbp = new org.eclipse.draw2d.RelativeBendpoint(connection); + rbp.setRelativeDimensions(new Dimension(modelBP.getSourceX(), modelBP.getSourceY()), // + new Dimension(modelBP.getTargetX(), modelBP.getTargetY())); + rbp.setWeight(weight); + return rbp; + } + + protected abstract Point getLocation(RelativeBendpoint modelBendpoint, Object d2dbendpoint); + } - public static boolean hasAbsoluteStoredAsRelativeBendpoints(Edge edge) { - List<?> bendpoints = ((RelativeBendpoints)edge.getBendpoints()).getPoints(); - for(Object o : bendpoints) { - if(o instanceof RelativeBendpoint && isAbsoluteStoredAsRelative((RelativeBendpoint)o)) { - return true; + protected static class OnlyForNewLinks extends ConventionBase { + + @Override + public Bendpoint d2dBendpoint(RelativeBendpoint modelBP, Connection connection, float weight) { + Bendpoint result = super.d2dBendpoint(modelBP, connection, weight); + if(result == null) { + result = newRelativeBendpointD2d(modelBP, connection, weight); + } + return result; + } + + @Override + public boolean hasAbsoluteStoredAsRelativeBendpoints(Edge edge) { + List<?> bendpoints = ((RelativeBendpoints)edge.getBendpoints()).getPoints(); + for(Object o : bendpoints) { + if(o instanceof RelativeBendpoint && isAbsoluteStoredAsRelative((RelativeBendpoint)o)) { + return true; + } + } + return false; + } + + @Override + protected Point getLocation(RelativeBendpoint modelBendpoint, Object d2dbendpoint) { + if(isAbsoluteStoredAsRelative(modelBendpoint)) { + return new Point(modelBendpoint.getSourceX(), modelBendpoint.getSourceY()); + } + if(d2dbendpoint instanceof Bendpoint) { + return ((Bendpoint)d2dbendpoint).getLocation(); } + return null; } - return false; + } - public static PointList getAbsoluteRelativeBendpointsList(Edge edge) { - PointList result = new PointList(); - for(Object o : ((RelativeBendpoints)edge.getBendpoints()).getPoints()) { - if(o instanceof RelativeBendpoint && isAbsoluteStoredAsRelative((RelativeBendpoint)o)) { - RelativeBendpoint relativeBendpoint = (RelativeBendpoint)o; - result.addPoint(new Point(relativeBendpoint.getSourceX(), relativeBendpoint.getSourceY())); - } else { - throw new IllegalArgumentException("Expecting absolute bendpoints stored as relative, found: " + o); + protected static class ForAllLinks extends ConventionBase { + + @Override + public Bendpoint d2dBendpoint(RelativeBendpoint modelBP, Connection connection, float weight) { + Bendpoint result = super.d2dBendpoint(modelBP, connection, weight); + if(result == null) { + org.eclipse.draw2d.RelativeBendpoint rbp = newRelativeBendpointD2d(modelBP, connection, weight); + //if(connection.getSourceAnchor() != null && connection.getTargetAnchor() != null) { + result = new RelativeBendpointWrapper(rbp, connection); + //} + } + return result; + } + + @Override + public boolean hasAbsoluteStoredAsRelativeBendpoints(Edge edge) { + List<?> bendpoints = ((RelativeBendpoints)edge.getBendpoints()).getPoints(); + return !bendpoints.isEmpty(); + } + + @Override + protected Point getLocation(RelativeBendpoint modelBendpoint, Object d2dBendpoint) { + if(isAbsoluteStoredAsRelative(modelBendpoint)) { + return new Point(modelBendpoint.getSourceX(), modelBendpoint.getSourceY()); + } + if(d2dBendpoint instanceof AbsoluteBendpoint) { + AbsoluteBendpoint wrapper = (AbsoluteBendpoint)d2dBendpoint; + return wrapper.getLocation(); + } + throw new IllegalStateException("I had to create AbsoluteBendpointWrapper for this: " + modelBendpoint + ", " + d2dBendpoint); + } + + /** + * Provides implicit migration of the diagrams created before the LinksLF. + * <p/> + * Idea is to create the same "absolute" bendpoints for the old relative bendpoints created with previous version, and only update the + * persistence on the first modification of the link. + * <p/> + * However, positions of the {@link RelativeBendpoint} depends on the anchors and, more generally on the bounds of link ends, so they can't be + * computed immediately at the time of creation. This class introduced the deferred replacement, that is, once the {@link RelativeBendpoint} + * can compute its positions, their coordinates are saved and don't depend on the source or target anchors anymore. + */ + @SuppressWarnings("serial") + private static class RelativeBendpointWrapper extends AbsoluteBendpoint { + + private Point myLocation = null; + + private org.eclipse.draw2d.RelativeBendpoint myRelativeBendpoint; + + private Connection myConnection; + + /** + * Wraps the {@link RelativeBendpoint} and defers computation of its positions until it is ready. + * + * @param relativeBendpoint + * @param conn + */ + public RelativeBendpointWrapper(org.eclipse.draw2d.RelativeBendpoint relativeBendpoint, Connection conn) { + super(new Point()); + myRelativeBendpoint = relativeBendpoint; + myConnection = conn; + } + + @Override + public Point getLocation() { + if(myLocation == null && isReadyToComputeLocation()) { + myLocation = new Point(myRelativeBendpoint.getLocation()); + myRelativeBendpoint = null; + myConnection = null; + } + return myLocation != null ? myLocation : myRelativeBendpoint.getLocation(); + } + + private boolean isReadyToComputeLocation() { + if(myConnection == null) { + return false; + } + ConnectionAnchor source = myConnection.getSourceAnchor(); + ConnectionAnchor target = myConnection.getTargetAnchor(); + if(source == null || target == null) { + return false; + } + return hasLocation(source.getReferencePoint()) && hasLocation(target.getReferencePoint()); + } + + private boolean hasLocation(Point point) { + return point != null && (point.x() != 0 || point.y() != 0); + } + + @Override + public int x() { + return getLocation().x(); + } + + @Override + public int y() { + return getLocation().y(); } } - return result; } } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/DiagramGridSpec.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/DiagramGridSpec.java new file mode 100644 index 00000000000..885fc7fe7e5 --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/DiagramGridSpec.java @@ -0,0 +1,144 @@ +package org.eclipse.papyrus.infra.gmfdiag.common.linklf; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.SnapToGrid; + +/** + * Utility class to compute active grid specification for given edit part viewer. + * <p/> + * Clients may call static methods to compute grid spec once, or may setup listeners + * that will automatically update the active spec when it changed + */ +public class DiagramGridSpec { + + private final EditPartViewer myViewer; + + private PrecisionRectangle myRelativeGridSpec; + + private PrecisionRectangle myAbsoluteGridSpec; + + private final GridSpecListener myGridListener; + + public DiagramGridSpec(EditPartViewer viewer) { + myViewer = viewer; + myGridListener = new GridSpecListener() { + + @Override + public void gridSpecChanged() { + myRelativeGridSpec = null; + myAbsoluteGridSpec = null; + } + }; + myViewer.addPropertyChangeListener(myGridListener); + } + + public void dispose() { + myViewer.removePropertyChangeListener(myGridListener); + myRelativeGridSpec = null; + myAbsoluteGridSpec = null; + } + + /** + * Always returns the same instance to avoid endless creation + * @return active grid specification in absolute coordinates or <code>null</code> if not enabled + */ + public PrecisionRectangle getAbsoluteGridSpec() { + PrecisionRectangle result = getRelativeGridSpec(); + if (result == null) { + return null; + } + + if (myAbsoluteGridSpec == null) { + myAbsoluteGridSpec = new PrecisionRectangle(); + } + myAbsoluteGridSpec.setPreciseBounds(result.preciseX(), result.preciseY(), result.preciseWidth(), result.preciseHeight()); + GraphicalEditPart diagramEP = (GraphicalEditPart) myViewer.getContents(); + diagramEP.getContentPane().translateToAbsolute(myAbsoluteGridSpec); + + return myAbsoluteGridSpec; + } + + private PrecisionRectangle getRelativeGridSpec() { + if (myRelativeGridSpec == null) { + myRelativeGridSpec = getRelativeGridSpec(myViewer); + } + return myRelativeGridSpec; + } + + public EditPartViewer getViewer() { + return myViewer; + } + + /** + * Computes actual grid specification (origin + single cell width and height) in the absolute coordinate system. + * Note, in contrast to {@link #getRelativeGridSpec(EditPartViewer)} this specification depends on the active zoom or scroll + * and can't be cached by clients. + * @param viewer + * @return absolute grid specification, or <code>null</code> if grid is not enabled + */ + public static PrecisionRectangle getAbsoluteGridSpec(EditPartViewer viewer) { + PrecisionRectangle spec = getRelativeGridSpec(viewer); + if (spec != null) { + GraphicalEditPart diagramEP = (GraphicalEditPart) viewer.getContents(); + diagramEP.getContentPane().translateToAbsolute(spec); + } + return spec; + } + + /** + * Computes actual grid specification (origin + single cell width and height) in the coordinates relative + * to the diagram content pane. + * <p/> + * This specification depends only on the grid-relative properties stored in + * the {@link EditPartViewer}, so client may cache it and rely on {@link EditPartViewer#addPropertyChangeListener(PropertyChangeListener)} + * @param viewer + * @return grid specification in the coordinate system relative to diagram content pane, or <code>null</code> if grid is not enabled + */ + private static PrecisionRectangle getRelativeGridSpec(EditPartViewer viewer) { + Boolean enabled = (Boolean) viewer.getProperty(SnapToGrid.PROPERTY_GRID_ENABLED); + if (enabled == null || !enabled) { + return null; + } + double gridX = 0; + double gridY = 0; + Dimension spacing = (Dimension) viewer.getProperty(SnapToGrid.PROPERTY_GRID_SPACING); + if (spacing != null) { + gridX = spacing.preciseWidth(); + gridY = spacing.preciseHeight(); + } + if (gridX <= 0) { + gridX = SnapToGrid.DEFAULT_GRID_SIZE; + } + if (gridY <= 0) { + gridY = SnapToGrid.DEFAULT_GRID_SIZE; + } + Point origin = (Point) viewer.getProperty(SnapToGrid.PROPERTY_GRID_ORIGIN); + PrecisionRectangle result = new PrecisionRectangle(// + origin == null ? 0 : origin.preciseX(), origin == null ? 0 : origin.preciseY(), gridX, gridY); + + return result; + } + + public static abstract class GridSpecListener implements PropertyChangeListener { + + public void propertyChange(PropertyChangeEvent evt) { + String propertyName = evt.getPropertyName(); + if (SnapToGrid.PROPERTY_GRID_ORIGIN.equals(propertyName) || // + SnapToGrid.PROPERTY_GRID_ENABLED.equals(propertyName) || // + SnapToGrid.PROPERTY_GRID_SPACING.equals(propertyName)) { + + gridSpecChanged(); + } + } + + public abstract void gridSpecChanged(); + }; + +} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/LinksLFNodeFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/LinksLFNodeFigure.java index 81672a3369c..bcdf550a450 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/LinksLFNodeFigure.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/LinksLFNodeFigure.java @@ -3,12 +3,15 @@ package org.eclipse.papyrus.infra.gmfdiag.common.linklf; import org.eclipse.draw2d.AbstractPointListShape; import org.eclipse.draw2d.ConnectionAnchor; import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.ScalablePolygonShape; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.draw2d.geometry.PrecisionPoint; import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor; +import org.eclipse.gmf.runtime.draw2d.ui.figures.IBorderItemLocator; import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; public class LinksLFNodeFigure extends DefaultSizeNodeFigure { @@ -47,6 +50,21 @@ public class LinksLFNodeFigure extends DefaultSizeNodeFigure { if(isDefaultAnchorArea(pt)) { return getConnectionAnchor(szAnchor); } + + if (myHost instanceof IBorderItemEditPart) { + IBorderItemLocator locator = ((IBorderItemEditPart) myHost).getBorderItemLocator(); + switch (locator.getCurrentSideOfParent()) { + case PositionConstants.WEST: + case PositionConstants.EAST: + pt.setPreciseX(pt.preciseX() > 0.5 ? 1.0 : 0.0); + break; + case PositionConstants.SOUTH: + case PositionConstants.NORTH: + pt.setPreciseY(pt.preciseY() > 0.5 ? 1.0 : 0.0); + break; + } + } + return createAnchor(pt); } } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/SlidableSnapToGridAnchor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/SlidableSnapToGridAnchor.java index ab5c65ab2bb..5f2de4832a7 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/SlidableSnapToGridAnchor.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/SlidableSnapToGridAnchor.java @@ -5,14 +5,11 @@ import java.util.LinkedList; import java.util.List; import org.eclipse.draw2d.PositionConstants; -import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PrecisionPoint; import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gef.EditPartViewer; -import org.eclipse.gef.GraphicalEditPart; -import org.eclipse.gef.SnapToGrid; import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor; @@ -231,40 +228,7 @@ public class SlidableSnapToGridAnchor extends SlidableAnchor { * @return <code>null</code> if no active grid or grid provider had not been set up. */ protected Rectangle getAbsoluteGridSpec() { - return myGridProvider == null ? null : getAbsoluteGridSpec(myGridProvider); - } - - /** - * Computes actual grid specification (origin + single cell width and height). Translates result into the absolute coordinates. - * @param viewer - * @return <code>null</code> if grid is not enabled or absolute grid specification - */ - protected static PrecisionRectangle getAbsoluteGridSpec(EditPartViewer viewer) { - Boolean enabled = (Boolean) viewer.getProperty(SnapToGrid.PROPERTY_GRID_ENABLED); - if (enabled == null || !enabled) { - return null; - } - double gridX = 0; - double gridY = 0; - Dimension spacing = (Dimension) viewer.getProperty(SnapToGrid.PROPERTY_GRID_SPACING); - if (spacing != null) { - gridX = spacing.preciseWidth(); - gridY = spacing.preciseHeight(); - } - if (gridX <= 0) { - gridX = SnapToGrid.DEFAULT_GRID_SIZE; - } - if (gridY <= 0) { - gridY = SnapToGrid.DEFAULT_GRID_SIZE; - } - Point origin = (Point) viewer.getProperty(SnapToGrid.PROPERTY_GRID_ORIGIN); - PrecisionRectangle result = new PrecisionRectangle(// - origin == null ? 0 : origin.preciseX(), origin == null ? 0 : origin.preciseY(), gridX, gridY); - - GraphicalEditPart diagramEP = (GraphicalEditPart) viewer.getContents(); - diagramEP.getContentPane().translateToAbsolute(result); - - return result; + return myGridProvider == null ? null : DiagramGridSpec.getAbsoluteGridSpec(myGridProvider); } private static Point pickClosestPointToSet(Point source, Collection<? extends Point> set1, Collection<? extends Point> set2) { diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustBorderItemAnchorsEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustBorderItemAnchorsEditPolicy.java new file mode 100644 index 00000000000..251d69314ef --- /dev/null +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustBorderItemAnchorsEditPolicy.java @@ -0,0 +1,201 @@ +package org.eclipse.papyrus.infra.gmfdiag.common.linklf.editpolicies; + +import org.eclipse.draw2d.ConnectionAnchor; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.PrecisionPoint; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.handles.HandleBounds; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.core.commands.SetConnectionAnchorsCommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart; +import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator; +import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor; +import org.eclipse.gmf.runtime.draw2d.ui.figures.IBorderItemLocator; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; + +/** + * This edit policy adjusts anchors for links from and to host {@link IBorderItemEditPart}. + * Adjustment ensures that the anchors are always located on the side which is parallel to the actual side + * of the parent this border item is affixed to. + */ +public class AdjustBorderItemAnchorsEditPolicy extends AdjustAbsoluteBendpointsEditPolicyBase { + + /** + * Default role for registering this edit policy. + * <p/> + * The value is prefixed by class FQN in order to avoid conflicts, but the literal should NOT be used anywhere. + */ + public static final String ROLE = AdjustBorderItemAnchorsEditPolicy.class.getName() + ":Role"; + + @Override + protected Command getAdjustLinksCommand(ChangeBoundsRequest req) { + if(getHost() instanceof IBorderItemEditPart && getHost() instanceof INodeEditPart) { + return getAdjustAnchorsCommand(req); + } + return null; + } + + protected Command getAdjustAnchorsCommand(ChangeBoundsRequest req) { + IBorderItemEditPart host = (IBorderItemEditPart)getHost(); + final IBorderItemLocator locator = host.getBorderItemLocator(); + if(locator == null) { + return null; + } + + Rectangle bounds; + if(host.getFigure() instanceof HandleBounds) { + bounds = ((HandleBounds)host.getFigure()).getHandleBounds(); + } else { + bounds = host.getFigure().getBounds(); + } + PrecisionRectangle rect = new PrecisionRectangle(bounds); + getHostFigure().translateToAbsolute(rect); + rect.translate(req.getMoveDelta()); + rect.resize(req.getSizeDelta()); + + getHostFigure().translateToRelative(rect); + Rectangle realLocation = locator.getValidLocation(rect.getCopy(), host.getFigure()); + + int projectedSide = BorderItemLocator.findClosestSideOfParent(realLocation, ((GraphicalEditPart)host.getParent()).getFigure().getBounds()); + int currentSide = locator.getCurrentSideOfParent(); + + int curIndex = getIndexForSide(currentSide); + int projectedIndex = getIndexForSide(projectedSide); + + if((projectedSide & currentSide) != 0) { + return null; + } + + int rotation = projectedIndex - curIndex; + if(rotation < 0) { + rotation += 4; + } + if(rotation == 0) { + //weird + return null; + } + + ICommand result = null; + TransactionalEditingDomain domain = getHost().getEditingDomain(); + for(Object next : getHost().getSourceConnections()) { + if(next instanceof ConnectionEditPart) { + ConnectionEditPart nextLink = (ConnectionEditPart)next; + ConnectionAnchor anchor = nextLink.getConnectionFigure().getSourceAnchor(); + if(anchor == null) { + continue; + } + PrecisionPoint newRefPoint = rotateAnchorLocation(anchor, rotation); + String newTerminal = composeTerminalString(newRefPoint); + + SetConnectionAnchorsCommand nextCommand = new SetConnectionAnchorsCommand(domain, "Adjusting source anchors"); + nextCommand.setEdgeAdaptor(new EObjectAdapter(nextLink.getNotationView())); + nextCommand.setNewSourceTerminal(newTerminal); + + result = result == null ? nextCommand : result.compose(nextCommand); + } + } + + for(Object next : getHost().getTargetConnections()) { + if(next instanceof ConnectionEditPart) { + ConnectionEditPart nextLink = (ConnectionEditPart)next; + ConnectionAnchor anchor = nextLink.getConnectionFigure().getTargetAnchor(); + if(anchor == null) { + continue; + } + PrecisionPoint newRefPoint = rotateAnchorLocation(anchor, rotation); + String newTerminal = composeTerminalString(newRefPoint); + + SetConnectionAnchorsCommand nextCommand = new SetConnectionAnchorsCommand(domain, "Adjusting target anchors"); + nextCommand.setEdgeAdaptor(new EObjectAdapter(nextLink.getNotationView())); + nextCommand.setNewTargetTerminal(newTerminal); + + result = result == null ? nextCommand : result.compose(nextCommand); + } + } + + return result == null ? null : new ICommandProxy(result); + } + + private static int getIndexForSide(int side) { + if(hasBits(side, PositionConstants.NORTH)) { + return 0; + } + if(hasBits(side, PositionConstants.EAST)) { + return 1; + } + if(hasBits(side, PositionConstants.SOUTH)) { + return 2; + } + if(hasBits(side, PositionConstants.WEST)) { + return 3; + } + return 0; + } + + protected static String position2string(int position) { + if(position == PositionConstants.NONE) { + return "NONE"; + } + StringBuffer result = new StringBuffer(); + if(hasBits(position, PositionConstants.NORTH)) { + result.append("N"); + } + if(hasBits(position, PositionConstants.SOUTH)) { + result.append("S"); + } + if(hasBits(position, PositionConstants.WEST)) { + result.append("W"); + } + if(hasBits(position, PositionConstants.EAST)) { + result.append("E"); + } + + return result.toString(); + } + + protected static boolean hasBits(int value, int mask) { + return ((value & mask) != 0); + } + + protected PrecisionPoint rotateAnchorLocation(ConnectionAnchor anchor, int quarters) { + String terminal = ((BaseSlidableAnchor)anchor).getTerminal(); + PrecisionPoint result = BaseSlidableAnchor.parseTerminalString(terminal); + for(int i = 0; i < quarters; i++) { + double newX = 1. - result.preciseY(); + double newY = result.preciseX(); + result.setPreciseLocation(newX, newY); + } + return result; + } + + /** + * [GMFRT] make protected in {@link BaseSlidableAnchor} + * <p/> + * Creates a terminal string for any reference point passed in the format understandable by slidable anchors + * + * @param p + * - a <Code>PrecisionPoint</Code> that must be represented as a unique <Code>String</Code>, namely as "(preciseX,preciseY)" + * @return <code>String</code> terminal composed from specified <code>PrecisionPoint</code> + * @deprecated copy pasted from {@link BaseSlidableAnchor} + */ + @Deprecated + private String composeTerminalString(PrecisionPoint p) { + StringBuffer s = new StringBuffer(24); + s.append('('); // 1 char + s.append(p.preciseX()); // 10 chars + s.append(','); // 1 char + s.append(p.preciseY()); // 10 chars + s.append(')'); // 1 char + return s.toString(); // 24 chars max (+1 for safety, i.e. for string termination) + } + + +} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustImplicitlyMovedLinksEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustImplicitlyMovedLinksEditPolicy.java index 09f7f082299..b7d1bd91549 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustImplicitlyMovedLinksEditPolicy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustImplicitlyMovedLinksEditPolicy.java @@ -12,9 +12,13 @@ */ package org.eclipse.papyrus.infra.gmfdiag.common.linklf.editpolicies; +import java.util.Collection; +import java.util.LinkedList; + import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.commands.Command; import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.common.core.command.ICommand; @@ -26,7 +30,7 @@ import org.eclipse.gmf.runtime.notation.RelativeBendpoints; import org.eclipse.papyrus.infra.gmfdiag.common.linklf.AbsoluteBendpointsConvention; /** - * This edit policy adjusts bendpoints for links between the nodes moved at the same time. + * This edit policy adjusts bendpoints for links between the nodes moved at the same time. * Only absolute bendpoints (also possibly stored as relative, see {@link AbsoluteBendpointsConvention}) require adjustment. */ public class AdjustImplicitlyMovedLinksEditPolicy extends AdjustAbsoluteBendpointsEditPolicyBase { @@ -34,8 +38,7 @@ public class AdjustImplicitlyMovedLinksEditPolicy extends AdjustAbsoluteBendpoin /** * Default role for registering this edit policy. * <p/> - * The value is prefixed by class FQN in order to avoid conflicts, - * but the literal should NOT be used anywhere. + * The value is prefixed by class FQN in order to avoid conflicts, but the literal should NOT be used anywhere. */ public static final String ROLE = AdjustImplicitlyMovedLinksEditPolicy.class.getName() + ":Role"; @@ -46,12 +49,12 @@ public class AdjustImplicitlyMovedLinksEditPolicy extends AdjustAbsoluteBendpoin /** * Link is implicitly moved when its source and target are both moved (directly or indirectly). - * In this case, {@link RelativeBendpoints} should not be adjusted. - * But when the link has effectively absolute bendpoints (see {@link AbsoluteBendpointsConvention}) + * In this case, {@link RelativeBendpoints} should not be adjusted. + * But when the link has effectively absolute bendpoints (see {@link AbsoluteBendpointsConvention}) * all of them must be also moved to the same {@link ChangeBoundsRequest#getMoveDelta()} * <p/> - * Default implementation of this method will only affect the <strong>outgoing</strong> links - * from the host edit part to one of the edit parts being moved. This way all affected links will be modified only once. + * Default implementation of this method will only affect the <strong>outgoing</strong> links from the host edit part to one of the edit parts + * being moved. This way all affected links will be modified only once. */ protected Command getAdjustImplicitlyMovedLinksCommand(ChangeBoundsRequest req) { final Point moveDelta = req.getMoveDelta(); @@ -61,16 +64,26 @@ public class AdjustImplicitlyMovedLinksEditPolicy extends AdjustAbsoluteBendpoin CachedEditPartsSet allMoved = getMovedEditPartsSet(req); ICommand result = null; - for (Object next : getHost().getSourceConnections()) { - if (next instanceof ConnectionEditPart) { - ConnectionEditPart nextLinkEP = (ConnectionEditPart) next; - EditPart target = nextLinkEP.getTarget(); - MovedNodeKind move = allMoved.isMoved(target); - if (move == MovedNodeKind.DIRECTLY || move == MovedNodeKind.INDIRECTLY) { - ICommand nextAdjustment = getAdjustOneLinkCommand(nextLinkEP, req); - result = compose(result, nextAdjustment); + LinkedList<GraphicalEditPart> queue = new LinkedList<GraphicalEditPart>(); + queue.add(getHost()); + + while (!queue.isEmpty()) { + GraphicalEditPart cur = queue.removeFirst(); + for (Object nextLink : cur.getSourceConnections()) { + if (nextLink instanceof ConnectionEditPart) { + ConnectionEditPart nextLinkEP = (ConnectionEditPart) nextLink; + EditPart target = nextLinkEP.getTarget(); + MovedNodeKind move = allMoved.isMoved(target); + if (move == MovedNodeKind.DIRECTLY || move == MovedNodeKind.INDIRECTLY) { + ICommand nextAdjustment = getAdjustOneLinkCommand(nextLinkEP, req); + result = compose(result, nextAdjustment); + } } } + + @SuppressWarnings("unchecked") + Collection<GraphicalEditPart> children = cur.getChildren(); + queue.addAll(children); } return result == null ? null : new ICommandProxy(result.reduce()); } @@ -78,8 +91,8 @@ public class AdjustImplicitlyMovedLinksEditPolicy extends AdjustAbsoluteBendpoin private ICommand getAdjustOneLinkCommand(ConnectionEditPart linkEP, ChangeBoundsRequest req) { SetAbsoluteBendpointsCommand result = null; Edge edge = (Edge) linkEP.getNotationView(); - if (AbsoluteBendpointsConvention.hasAbsoluteStoredAsRelativeBendpoints(edge)) { - PointList newPoints = AbsoluteBendpointsConvention.getAbsoluteRelativeBendpointsList(edge); + if (AbsoluteBendpointsConvention.getInstance().hasAbsoluteStoredAsRelativeBendpoints(edge)) { + PointList newPoints = AbsoluteBendpointsConvention.getInstance().getPointList(edge, linkEP.getConnectionFigure().getRoutingConstraint()); newPoints.translate(req.getMoveDelta()); result = new SetAbsoluteBendpointsCommand(getDomain()); diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustLinksToIndirectlyMovedNodesEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustLinksToIndirectlyMovedNodesEditPolicy.java index cf78d5a3353..cb9f9713ced 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustLinksToIndirectlyMovedNodesEditPolicy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/AdjustLinksToIndirectlyMovedNodesEditPolicy.java @@ -12,13 +12,15 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.draw2d.Connection; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; -import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPart; import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.SnapToGrid; import org.eclipse.gef.commands.Command; import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.common.core.command.CommandResult; @@ -28,18 +30,19 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart; import org.eclipse.gmf.runtime.draw2d.ui.geometry.PointListUtilities; import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.OrthogonalRouter; import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.OrthogonalRouterUtilities; -import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.RectilinearRouter; import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.papyrus.infra.gmfdiag.common.linklf.AbsoluteBendpointsConvention; -import org.eclipse.papyrus.infra.gmfdiag.common.linklf.router.RectilinearRouter2; +import org.eclipse.papyrus.infra.gmfdiag.common.linklf.DiagramGridSpec; +import org.eclipse.papyrus.infra.gmfdiag.common.linklf.router.SnapToGridRectilinearRouter; public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteBendpointsEditPolicyBase { /** * Default role for registering this edit policy. * <p/> - * The value is prefixed by class FQN in order to avoid conflicts, but the literal should NOT be used anywhere. + * The value is prefixed by class FQN in order to avoid conflicts, + * but the literal should NOT be used anywhere. */ public static final String ROLE = AdjustLinksToIndirectlyMovedNodesEditPolicy.class.getName() + ":Role"; @@ -49,12 +52,12 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB @Override protected Command getAdjustLinksCommand(ChangeBoundsRequest req) { - if(myLastRequest != null && myLastRequest.get() == req) { - if(myLastCommand == null) { + if (myLastRequest != null && myLastRequest.get() == req) { + if (myLastCommand == null) { return null; } Command result = myLastCommand.get(); - if(result != null) { + if (result != null) { return result; } } @@ -73,66 +76,66 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB LinkedList<GraphicalEditPart> queue = new LinkedList<GraphicalEditPart>(); queue.addAll(getHost().getChildren()); - while(!queue.isEmpty()) { + while (!queue.isEmpty()) { GraphicalEditPart cur = queue.removeFirst(); - for(EditPart link : (Collection<EditPart>)cur.getSourceConnections()) { + for (EditPart link : (Collection<EditPart>) cur.getSourceConnections()) { ICommand nextOutgoingCommand = getAdjustOneLinkCommand(link, allMoved, req, true); result = compose(result, nextOutgoingCommand); } - for(EditPart link : (Collection<EditPart>)cur.getTargetConnections()) { + for (EditPart link : (Collection<EditPart>) cur.getTargetConnections()) { ICommand nextIncomingCommand = getAdjustOneLinkCommand(link, allMoved, req, false); result = compose(result, nextIncomingCommand); } - queue.addAll((Collection<GraphicalEditPart>)cur.getChildren()); + queue.addAll((Collection<GraphicalEditPart>) cur.getChildren()); } return result == null ? null : new ICommandProxy(result.reduce()); } protected ICommand getAdjustOneLinkCommand(EditPart linkEP, CachedEditPartsSet allMoved, ChangeBoundsRequest req, boolean outgoing) { - if(false == linkEP instanceof ConnectionEditPart) { + if (false == linkEP instanceof ConnectionEditPart) { return null; } - ConnectionEditPart link = (ConnectionEditPart)linkEP; + ConnectionEditPart link = (ConnectionEditPart) linkEP; EditPart staticEnd = outgoing ? link.getTarget() : link.getSource(); - if(staticEnd == null) { + if (staticEnd == null) { return null; } MovedNodeKind kind = allMoved.isMoved(staticEnd); - if(kind != MovedNodeKind.NO) { + if (kind != MovedNodeKind.NO) { return null; } Connection conn = link.getConnectionFigure(); - if(conn == null) { + if (conn == null) { return null; } - if(!acceptAdjustingConnection(link, conn)) { + if (!acceptAdjustingConnection(link, conn)) { return null; } - GraphicalEditPart staticGateEP = (GraphicalEditPart)findHighestDifferentAncestor(staticEnd, getHost()); - if(staticGateEP == null) { + GraphicalEditPart staticGateEP = (GraphicalEditPart) findHighestDifferentAncestor(staticEnd, getHost()); + if (staticGateEP == null) { return null; } PointList linkPoints = makeAbsolute(conn, conn.getPoints()); Point hostGate = findGatePosition(linkPoints, getHostFigure()); - if(hostGate == null) { + if (hostGate == null) { return null; } int hostGateSegment = PointListUtilities.findNearestLineSegIndexOfPoint(linkPoints, hostGate); Point staticGate; int staticGateSegment; - if(staticGateEP == staticEnd) { + if (staticGateEP == staticEnd) { staticGate = null; staticGateSegment = -1; } else { IFigure staticGateOwner = staticGateEP.getFigure(); staticGate = findGatePosition(linkPoints, staticGateOwner); - if(staticGate == null) { + if (staticGate == null) { return null; } staticGateSegment = PointListUtilities.findNearestLineSegIndexOfPoint(linkPoints, staticGate); @@ -156,38 +159,31 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB /** * Hook for subclasses, allows to decide whether to adjust links on instance-by-instance basis. * <p/> - * In this implementation the link is accepted if it - * <ul> + * In this implementation the link is accepted if it <ul> * <li>is backed by some {@link Edge}</li> * <li>has absolute bendpoints {@link AbsoluteBendpointsConvention} which has to be adjusted</li> * <li>has an orthogonal router</li> * </ul> * - * @param link - * link editpart to check - * @param conn - * its connection figure, known to be not <code>null</code> + * @param link link editpart to check + * @param conn its connection figure, known to be not <code>null</code> * @return true if link gates should be preserved */ protected boolean acceptAdjustingConnection(ConnectionEditPart link, Connection conn) { - Edge edge = (Edge)link.getNotationView(); - if(edge == null) { + Edge edge = (Edge) link.getNotationView(); + if (edge == null) { return false; } - return AbsoluteBendpointsConvention.hasAbsoluteStoredAsRelativeBendpoints(edge) && // - conn.getConnectionRouter() instanceof OrthogonalRouter; + return AbsoluteBendpointsConvention.getInstance().hasAbsoluteStoredAsRelativeBendpoints(edge) && // + conn.getConnectionRouter() instanceof OrthogonalRouter; } /** - * Finds the gate, that is an intersection between link points and the given gate owner. + * Finds the gate, that is an intersection between link points and the given gate owner. + * @param linkPointsAbs absolute link point coordinates + * @param gateOwner the figure which intersection with the link defines the gate * - * @param linkPointsAbs - * absolute link point coordinates - * @param gateOwner - * the figure which intersection with the link defines the gate - * - * @return absolute position of the intersection, or <code>null</code> if not found. If multiple intersections are found then only the first is - * returned + * @return absolute position of the intersection, or <code>null</code> if not found. If multiple intersections are found then only the first is returned */ protected Point findGatePosition(PointList linkPointsAbs, IFigure gateOwner) { Rectangle ownerBounds = makeAbsolute(gateOwner, gateOwner.getBounds()); @@ -197,19 +193,19 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB PointList distances = new PointList(); boolean computed = PointListUtilities.findIntersections(ownerPoints, linkPointsAbs, intersections, distances); - if(!computed || intersections.size() == 0) { + if (!computed || intersections.size() == 0) { System.err.println("Can't compute intersections between:" + // - " hostBounds: " + pointList2String(ownerPoints) + // - " and link: " + pointList2String(linkPointsAbs)); + " hostBounds: " + pointList2String(ownerPoints) + // + " and link: " + pointList2String(linkPointsAbs)); return null; } - if(intersections.size() > 1) { + if (intersections.size() > 1) { System.err.println("Expected exactly one intersection between:" + // - " hostBounds: " + pointList2String(ownerPoints) + // - " and link: " + pointList2String(linkPointsAbs) + // - " actually: " + pointList2String(intersections) + // - " will use the first one: " + intersections.getFirstPoint()); + " hostBounds: " + pointList2String(ownerPoints) + // + " and link: " + pointList2String(linkPointsAbs) + // + " actually: " + pointList2String(intersections) + // + " will use the first one: " + intersections.getFirstPoint()); } return intersections.getFirstPoint(); @@ -223,31 +219,27 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB } /** - * Provides the highest (closest to the root) editpart which is ancestor of the subj editPart but is still not a common ancestor of some other - * editpart - * - * @param subj - * the editPart to compute ancestor for - * @param other - * the editPart which ancestors should be avoided + * Provides the highest (closest to the root) editpart which is ancestor of the subj editPart but is still not a common ancestor of some other editpart + * @param subj the editPart to compute ancestor for + * @param other the editPart which ancestors should be avoided * @return */ protected static EditPart findHighestDifferentAncestor(EditPart subj, EditPart other) { Set<EditPart> otherChainUp = new HashSet<EditPart>(); EditPart cur = other; - while(cur != null) { + while (cur != null) { otherChainUp.add(cur); cur = cur.getParent(); } EditPart result = subj; - while(result != null) { + while (result != null) { EditPart parent = result.getParent(); - if(parent == null) { + if (parent == null) { //weird, there should be at least common root edit part return null; } - if(otherChainUp.contains(parent)) { + if (otherChainUp.contains(parent)) { return result; } result = parent; @@ -255,7 +247,7 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB throw new IllegalStateException(); } - protected static class PreserveGatesRequest { + protected static class PreserveGatesRequest extends Request { private final ConnectionEditPart myLink; @@ -311,7 +303,7 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB } public Edge getEdge() { - return (Edge)myLink.getNotationView(); + return (Edge) myLink.getNotationView(); } public PointList getLinkPointsBefore() { @@ -323,16 +315,21 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB } public GraphicalEditPart getStaticLinkEnd() { - return (GraphicalEditPart)(isOutgoing() ? myLink.getTarget() : myLink.getSource()); + return (GraphicalEditPart) (isOutgoing() ? myLink.getTarget() : myLink.getSource()); } public GraphicalEditPart getMovingLinkEnd() { - return (GraphicalEditPart)(isOutgoing() ? myLink.getSource() : myLink.getTarget()); + return (GraphicalEditPart) (isOutgoing() ? myLink.getSource() : myLink.getTarget()); } public Point getMoveDelta() { return myHostRequest.getMoveDelta(); } + + public SnapToGrid getSnapToGrid() { + PrecisionRectangle gridSpec = DiagramGridSpec.getAbsoluteGridSpec(getLink().getViewer()); + return gridSpec == null ? null : new SnapToGrid(getLink()); + } } protected static class PreserveGatesCommand extends AbstractTransactionalCommand { @@ -349,7 +346,7 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Point moveDelta = myRequest.getMoveDelta(); - if(moveDelta == null || moveDelta.x == 0 && moveDelta.y == 0) { + if (moveDelta == null || moveDelta.x == 0 && moveDelta.y == 0) { //may be the case due to the caching: command was created when moveDelta was here //but at the execution time request has changed return CommandResult.newOKCommandResult(); @@ -359,30 +356,30 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB //System.err.println("[1]: oldPoints: " + pointList2String(oldPoints)); PointList newPointsStart = new PointList(oldPoints.size()); PointList newPointsEnd = new PointList(oldPoints.size() * 2); - if(myRequest.isOutgoing()) { + if (myRequest.isOutgoing()) { //segment indexes are 1-based, see findNearestLineSegIndexOfPoint - for(int i = 0; i < myRequest.getMovingGateSegment(); i++) { + for (int i = 0; i < myRequest.getMovingGateSegment(); i++) { newPointsStart.addPoint(oldPoints.getPoint(i)); } newPointsStart.addPoint(myRequest.getMovingGateAbs()); newPointsStart.translate(moveDelta); - if(myRequest.getStaticGateAbs() != null && myRequest.getStaticGateSegment() == myRequest.getMovingGateSegment()) { + if (myRequest.getStaticGateAbs() != null && myRequest.getStaticGateSegment() == myRequest.getMovingGateSegment()) { newPointsEnd.addPoint(myRequest.getStaticGateAbs()); } - for(int i = myRequest.getMovingGateSegment(); i < oldPoints.size(); i++) { + for (int i = myRequest.getMovingGateSegment(); i < oldPoints.size(); i++) { newPointsEnd.addPoint(oldPoints.getPoint(i)); } } else { - for(int i = 0; i < myRequest.getMovingGateSegment(); i++) { + for (int i = 0; i < myRequest.getMovingGateSegment(); i++) { newPointsStart.addPoint(oldPoints.getPoint(i)); } - if(myRequest.getStaticGateAbs() != null && myRequest.getMovingGateSegment() == myRequest.getStaticGateSegment()) { + if (myRequest.getStaticGateAbs() != null && myRequest.getMovingGateSegment() == myRequest.getStaticGateSegment()) { newPointsStart.addPoint(myRequest.getStaticGateAbs()); } newPointsEnd.addPoint(myRequest.getMovingGateAbs()); - for(int i = myRequest.getMovingGateSegment(); i < oldPoints.size(); i++) { + for (int i = myRequest.getMovingGateSegment(); i < oldPoints.size(); i++) { newPointsEnd.addPoint(oldPoints.getPoint(i)); } newPointsEnd.translate(moveDelta); @@ -412,17 +409,18 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB middlePart.addPoint(routeStart); middlePart.addPoint(routeEnd); - if(!OrthogonalRouterUtilities.isRectilinear(middlePart)) { - PreserveGatesUtil.insertPointsProducingNotAlignedRectilinearSegments(middlePart, offSourceDirection, offTargetDirection); + if (!OrthogonalRouterUtilities.isRectilinear(middlePart)) { + SnapToGrid snapper = myRequest.getSnapToGrid(); + PreserveGatesUtil.insertPointsProducingNotAlignedRectilinearSegments(middlePart, offSourceDirection, offTargetDirection, snapper); OrthogonalRouterUtilities.transformToOrthogonalPointList(middlePart, // - PreserveGatesUtil.asVerticalOrHorizontal(offSourceDirection), // - PreserveGatesUtil.asVerticalOrHorizontal(offTargetDirection)); + PreserveGatesUtil.asVerticalOrHorizontal(offSourceDirection), // + PreserveGatesUtil.asVerticalOrHorizontal(offTargetDirection)); } - if(middlePart.getFirstPoint().equals(newPointsStart.getLastPoint())) { + if (middlePart.getFirstPoint().equals(newPointsStart.getLastPoint())) { middlePart.removePoint(0); } - if(middlePart.getLastPoint().equals(newPointsEnd.getFirstPoint())) { + if (middlePart.getLastPoint().equals(newPointsEnd.getFirstPoint())) { middlePart.removePoint(middlePart.size() - 1); } @@ -440,7 +438,7 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB myRequest.getLink().getConnectionFigure().translateToRelative(relPoints); //System.err.println("== (rel:) " + pointList2String(relPoints)); - if(newPoints != null) { + if (newPoints != null) { SetAbsoluteBendpointsCommand.setAbsoluteBendpoints(myRequest.getEdge(), relPoints); } @@ -449,70 +447,42 @@ public class AdjustLinksToIndirectlyMovedNodesEditPolicy extends AdjustAbsoluteB } - private static class PreserveGatesUtil extends RectilinearRouter2 { + private static class PreserveGatesUtil extends SnapToGridRectilinearRouter { public static int getOppositeDirection(int direction) { int result = 0; - if((direction & PositionConstants.EAST) != 0) { + if ((direction & PositionConstants.EAST) != 0) { result |= PositionConstants.WEST; } - if((direction & PositionConstants.WEST) != 0) { + if ((direction & PositionConstants.WEST) != 0) { result |= PositionConstants.EAST; } - if((direction & PositionConstants.NORTH) != 0) { + if ((direction & PositionConstants.NORTH) != 0) { result |= PositionConstants.SOUTH; } - if((direction & PositionConstants.SOUTH) != 0) { + if ((direction & PositionConstants.SOUTH) != 0) { result |= PositionConstants.NORTH; } return result; } /** - * @param points - * input list of points - * @param segment - * 1-based segment index, valid for given points list + * @param points input list of points + * @param segment 1-based segment index, valid for given points list * @return */ public static int getSegmentDirection(PointList points, int segment) { Point start = points.getPoint(segment - 1); Point end = points.getPoint(segment); - if(start.x == end.x) { + if (start.x == end.x) { return start.y < end.y ? PositionConstants.SOUTH : PositionConstants.NORTH; } - if(start.y == end.y) { + if (start.y == end.y) { return start.x < end.x ? PositionConstants.EAST : PositionConstants.WEST; } return getOutisePointOffRectanglePosition2(start, new Rectangle(end.x, end.y, 0, 0)); } - public static int asVerticalOrHorizontal(int direction) { - return getOffShapeDirection2(direction); - } - - public static void removeRedundantPoints(PointList line) { - removeRedundantPoints2(line); - } - - /** - * We need to find two points offset from the source and target anchors outside the shapes - * such that when the polyline is converted to rectilinear from oblique we won't have - * rectilinear line segments alligned with source or target shapes edges. - * <p/> - * Copy-pasted from {@link RectilinearRouter} lines 416. - */ - @Deprecated - public static void insertPointsProducingNotAlignedRectilinearSegments(PointList line, int sourceAnchorRelativeLocation, int targetAnchorRelativeLocation) { - Point offStart = line.getFirstPoint(); - Point offEnd = line.getLastPoint(); - Dimension offsetDim = offStart.getDifference(offEnd).scale(0.5); - offStart.translate(getTranslationValue2(sourceAnchorRelativeLocation, Math.abs(offsetDim.width), Math.abs(offsetDim.height))); - offEnd.translate(getTranslationValue2(targetAnchorRelativeLocation, Math.abs(offsetDim.width), Math.abs(offsetDim.height))); - line.insertPoint(offStart, 1); - line.insertPoint(offEnd, 2); - } - } } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/SetAbsoluteBendpointsCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/SetAbsoluteBendpointsCommand.java index d70f62d326e..a46d176ca21 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/SetAbsoluteBendpointsCommand.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/SetAbsoluteBendpointsCommand.java @@ -62,7 +62,7 @@ public class SetAbsoluteBendpointsCommand extends SetConnectionBendpointsCommand //Dimension s = getNewPointList().getPoint(i).getDifference(getSourceRefPoint()); //Dimension t = getNewPointList().getPoint(i).getDifference(getTargetRefPoint()); //newBendpoints.add(new RelativeBendpoint(s.width, s.height, t.width, t.height)); - newBendpoints.add(AbsoluteBendpointsConvention.createAbsoluteBendpointStoredAsRelative(newPointList.getPoint(i))); + newBendpoints.add(AbsoluteBendpointsConvention.getInstance().createAbsoluteBendpointStoredAsRelative(newPointList.getPoint(i))); } StringBuffer toString = new StringBuffer(); diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java index 63c69620aa6..0a7dfc23604 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java @@ -1,5 +1,86 @@ package org.eclipse.papyrus.infra.gmfdiag.common.linklf.router; +import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.PrecisionPoint; +import org.eclipse.draw2d.geometry.PrecisionRectangle; +import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.SnapToGrid; +import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.RectilinearRouter; +import org.eclipse.papyrus.infra.gmfdiag.common.linklf.DiagramGridSpec; + public class SnapToGridRectilinearRouter extends RectilinearRouter2 { + private DiagramGridSpec myGridSpec; + + public void setEditPartViewer(EditPartViewer viewer) { + if(myGridSpec != null && myGridSpec.getViewer() == viewer) { + return; + } + if(myGridSpec != null) { + myGridSpec.dispose(); + } + myGridSpec = viewer == null ? null : new DiagramGridSpec(viewer); + } + + @Override + public void routeLine(Connection conn, int nestedRoutingDepth, PointList newLine) { + super.routeLine(conn, nestedRoutingDepth, newLine); + } + + private PrecisionRectangle getGridSpec() { + return myGridSpec == null ? null : myGridSpec.getAbsoluteGridSpec(); + } + + /** + * We need to find two points offset from the source and target anchors outside the shapes + * such that when the polyline is converted to rectilinear from oblique we won't have + * rectilinear line segments alligned with source or target shapes edges. + * <p/> + * Copy-pasted from {@link RectilinearRouter} lines 416. + */ + @Deprecated + public static void insertPointsProducingNotAlignedRectilinearSegments(PointList line, int sourceAnchorRelativeLocation, int targetAnchorRelativeLocation) { + Point offStart = line.getFirstPoint(); + Point offEnd = line.getLastPoint(); + Dimension offsetDim = offStart.getDifference(offEnd).scale(0.5); + offStart.translate(getTranslationValue2(sourceAnchorRelativeLocation, Math.abs(offsetDim.width), Math.abs(offsetDim.height))); + offEnd.translate(getTranslationValue2(targetAnchorRelativeLocation, Math.abs(offsetDim.width), Math.abs(offsetDim.height))); + line.insertPoint(offStart, 1); + line.insertPoint(offEnd, 2); + } + + public static void insertPointsProducingNotAlignedRectilinearSegments(PointList line, int sourceAnchorRelativeLocation, int targetAnchorRelativeLocation, SnapToGrid snapper) { + insertPointsProducingNotAlignedRectilinearSegments(line, sourceAnchorRelativeLocation, targetAnchorRelativeLocation); + if(snapper != null) { + PrecisionPoint addedForSource = new PrecisionPoint(line.getPoint(1)); + PrecisionPoint snappedForSource = addedForSource.getPreciseCopy(); + PrecisionPoint addedForTarget = new PrecisionPoint(line.getPoint(2)); + PrecisionPoint snappedForTarget = addedForTarget.getPreciseCopy(); + + snapper.snapPoint(null, asVerticalOrHorizontal(sourceAnchorRelativeLocation), addedForSource, snappedForSource); + snapper.snapPoint(null, asVerticalOrHorizontal(targetAnchorRelativeLocation), addedForTarget, snappedForTarget); + + if(snappedForSource.getDistance(addedForSource) <= snappedForTarget.getDistance(addedForTarget)) { + Dimension delta = snappedForSource.getDifference(addedForSource); + line.setPoint(snappedForSource, 1); + line.setPoint(addedForTarget.getTranslated(delta), 2); + } else { + Dimension delta = snappedForTarget.getDifference(addedForTarget); + line.setPoint(addedForSource.getTranslated(delta), 1); + line.setPoint(snappedForTarget, 2); + } + } + } + + public static int asVerticalOrHorizontal(int direction) { + return getOffShapeDirection2(direction); + } + + public static void removeRedundantPoints(PointList line) { + removeRedundantPoints2(line); + } + } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersConnectionLayer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersConnectionLayer.java index be3568a2b26..679e8eb94c9 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersConnectionLayer.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersConnectionLayer.java @@ -1,8 +1,10 @@ package org.eclipse.papyrus.infra.gmfdiag.common.linklf.router.provider; import org.eclipse.draw2d.ConnectionRouter; +import org.eclipse.gef.EditPartViewer; import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.ConnectionLayerEx; import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.RectilinearRouter; +import org.eclipse.papyrus.infra.gmfdiag.common.linklf.router.SnapToGridRectilinearRouter; /** * [GMFRT] request extraction of protected createXXXRouter() instead @@ -11,16 +13,32 @@ public class CustomRoutersConnectionLayer extends ConnectionLayerEx { private RectilinearRouter myCustomRectilinearRouter; + private EditPartViewer myViewer; + + protected EditPartViewer getViewer() { + return myViewer; + } + + public void setEditPartViewer(EditPartViewer viewer) { + myViewer = viewer; + if(myCustomRectilinearRouter instanceof SnapToGridRectilinearRouter) { + ((SnapToGridRectilinearRouter)myCustomRectilinearRouter).setEditPartViewer(viewer); + } + } + @Override public ConnectionRouter getRectilinearRouter() { - if (myCustomRectilinearRouter == null) { + if(myCustomRectilinearRouter == null) { myCustomRectilinearRouter = createRectilinearRouter(); } return myCustomRectilinearRouter; } protected RectilinearRouter createRectilinearRouter() { - return new RectilinearRouter(); + //return new RectilinearRouter(); + SnapToGridRectilinearRouter result = new SnapToGridRectilinearRouter(); + result.setEditPartViewer(getViewer()); + return result; } } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersDiagramRootEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersDiagramRootEditPart.java index fc8dfbcc46f..48ccfdd04db 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersDiagramRootEditPart.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/provider/CustomRoutersDiagramRootEditPart.java @@ -10,6 +10,8 @@ import org.eclipse.gmf.runtime.notation.MeasurementUnit; public class CustomRoutersDiagramRootEditPart extends RenderedDiagramRootEditPart { + private CustomRoutersConnectionLayer myConnectionLayer; + public CustomRoutersDiagramRootEditPart(MeasurementUnit mUnit) { super(mUnit); } @@ -30,7 +32,21 @@ public class CustomRoutersDiagramRootEditPart extends RenderedDiagramRootEditPar } protected ConnectionLayerEx createConnectionLayer() { - return new CustomRoutersConnectionLayer(); + myConnectionLayer = new CustomRoutersConnectionLayer(); + return myConnectionLayer; + } + + @Override + protected void register() { + super.register(); + myConnectionLayer.setEditPartViewer(getViewer()); + + } + + @Override + protected void unregister() { + myConnectionLayer.setEditPartViewer(null); + super.unregister(); } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/DefaultEditPolicies.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/DefaultEditPolicies.java index f8bd578a99e..4beaac1ee59 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/DefaultEditPolicies.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/DefaultEditPolicies.java @@ -1,7 +1,9 @@ package org.eclipse.papyrus.uml.diagram.common.editparts.linkslf; import org.eclipse.gef.EditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.linklf.editpolicies.AdjustBorderItemAnchorsEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.linklf.editpolicies.AdjustImplicitlyMovedLinksEditPolicy; import org.eclipse.papyrus.infra.gmfdiag.common.linklf.editpolicies.LinksLFGraphicalNodeEditPolicy; @@ -11,6 +13,10 @@ class DefaultEditPolicies { static void installNodeEditPolicies(INodeEditPart nodeEP) { nodeEP.installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new LinksLFGraphicalNodeEditPolicy()); nodeEP.installEditPolicy(AdjustImplicitlyMovedLinksEditPolicy.ROLE, new AdjustImplicitlyMovedLinksEditPolicy()); + + if(nodeEP instanceof AbstractBorderItemEditPart) { + nodeEP.installEditPolicy(AdjustBorderItemAnchorsEditPolicy.ROLE, new AdjustBorderItemAnchorsEditPolicy()); + } } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFConnectionEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFConnectionEditPart.java index 3ef32e945f6..d5642550b0b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFConnectionEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFConnectionEditPart.java @@ -49,7 +49,7 @@ public abstract class LinksLFConnectionEditPart extends ConnectionEditPart { } else { weight = i / ((float)modelConstraint.size() - 1); } - Bendpoint bp = AbsoluteBendpointsConvention.d2dBendpoint(wbp, getConnectionFigure(), weight); + Bendpoint bp = getAbsoluteBendpointsConvention().d2dBendpoint(wbp, getConnectionFigure(), weight); figureConstraint.add(bp); } getConnectionFigure().setRoutingConstraint(figureConstraint); @@ -108,6 +108,9 @@ public abstract class LinksLFConnectionEditPart extends ConnectionEditPart { installBendpointEditPolicy(); } } - + + protected AbsoluteBendpointsConvention getAbsoluteBendpointsConvention() { + return AbsoluteBendpointsConvention.getInstance(); + } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFShapeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFShapeCompartmentEditPart.java index 9bd6780745d..f8ad3b9ef94 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFShapeCompartmentEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFShapeCompartmentEditPart.java @@ -12,7 +12,6 @@ */
package org.eclipse.papyrus.uml.diagram.common.editparts.linkslf;
-import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.eclipse.draw2d.FreeformViewport;
@@ -37,23 +36,19 @@ import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.AnimatableScrollPane; import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.OverlayScrollPaneLayout;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.linklf.DiagramGridSpec.GridSpecListener;
public class LinksLFShapeCompartmentEditPart extends ShapeCompartmentEditPart {
- private final PropertyChangeListener myGridListener = new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- String propertyName = evt.getPropertyName();
- if(SnapToGrid.PROPERTY_GRID_ORIGIN.equals(propertyName) || //
- SnapToGrid.PROPERTY_GRID_ENABLED.equals(propertyName) || //
- SnapToGrid.PROPERTY_GRID_SPACING.equals(propertyName)) {
-
- updateGridBehavior();
- }
+ private final GridSpecListener myGridListener = new GridSpecListener() {
+
+ @Override
+ public void gridSpecChanged() {
+ updateGridBehavior();
}
};
-
+
public LinksLFShapeCompartmentEditPart(View view) {
super(view);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFUMLConnectionNodeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFUMLConnectionNodeEditPart.java index 1d2a5773f01..071b98872d5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFUMLConnectionNodeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/linkslf/LinksLFUMLConnectionNodeEditPart.java @@ -49,7 +49,7 @@ public abstract class LinksLFUMLConnectionNodeEditPart extends UMLConnectionNode } else { weight = i / ((float)modelConstraint.size() - 1); } - Bendpoint bp = AbsoluteBendpointsConvention.d2dBendpoint(wbp, getConnectionFigure(), weight); + Bendpoint bp = getAbsoluteBendpointsConvention().d2dBendpoint(wbp, getConnectionFigure(), weight); figureConstraint.add(bp); } getConnectionFigure().setRoutingConstraint(figureConstraint); @@ -109,5 +109,8 @@ public abstract class LinksLFUMLConnectionNodeEditPart extends UMLConnectionNode } } + protected AbsoluteBendpointsConvention getAbsoluteBendpointsConvention() { + return AbsoluteBendpointsConvention.getInstance(); + } } |