Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2015-06-10 09:52:10 +0000
committerRemi Schnekenburger2015-06-10 10:31:11 +0000
commite11b700b89a98ecd6f0f29bbf69f431b96cdce52 (patch)
tree1b880fbb6d0f1ba288a99d120a7b1b87eab54345
parentb9bed679a24b92d7ef3c107fa495b8988eb26dbd (diff)
downloadorg.eclipse.papyrus-e11b700b89a98ecd6f0f29bbf69f431b96cdce52.tar.gz
org.eclipse.papyrus-e11b700b89a98ecd6f0f29bbf69f431b96cdce52.tar.xz
org.eclipse.papyrus-e11b700b89a98ecd6f0f29bbf69f431b96cdce52.zip
442157: [LinksLF] Improved links routing, anchors & bevdpoints behavior
for Papyrus diagrams https://bugs.eclipse.org/bugs/show_bug.cgi?id=442157 Change-Id: I207de177958ad9f5d99157f45c41ff3e94e00a41 Reviewed-on: https://git.eclipse.org/r/49743 Reviewed-by: Remi Schnekenburger <remi.schnekenburger@cea.fr> Tested-by: Remi Schnekenburger <remi.schnekenburger@cea.fr>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/NodeEditPart.java8
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java84
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusSlidableSnapToGridAnchor.java72
3 files changed, 160 insertions, 4 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/NodeEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/NodeEditPart.java
index b031db92c14..bb2960a3e9c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/NodeEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/NodeEditPart.java
@@ -23,7 +23,6 @@ import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
@@ -32,6 +31,7 @@ import org.eclipse.gmf.runtime.notation.FillStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.runtime.notation.datatype.GradientData;
+import org.eclipse.gmf.tooling.runtime.linklf.editparts.LinkLFBorderedShapeEditPart;
import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.FollowSVGSymbolEditPolicy;
@@ -39,6 +39,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusConnectionHa
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusPopupBarEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusResizableShapeEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure;
+import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.LinkLFSVGNodePlateFigure;
import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.SVGNodePlateFigure;
import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ShapeService;
import org.eclipse.papyrus.infra.gmfdiag.common.snap.PapyrusDragEditPartsTrackerEx;
@@ -48,7 +49,7 @@ import org.w3c.dom.svg.SVGDocument;
/**
* this edit part can refresh shadow and gradient.
*/
-public abstract class NodeEditPart extends AbstractBorderedShapeEditPart implements IPapyrusEditPart {
+public abstract class NodeEditPart extends LinkLFBorderedShapeEditPart implements IPapyrusEditPart {
protected SVGNodePlateFigure svgNodePlate;
@@ -295,8 +296,7 @@ public abstract class NodeEditPart extends AbstractBorderedShapeEditPart impleme
* @return the figure that allow following border of shape
*/
protected NodeFigure createSVGNodePlate() {
-
- svgNodePlate = new SVGNodePlateFigure(-1, -1);
+ svgNodePlate = new LinkLFSVGNodePlateFigure(this, -1, -1).withLinkLFEnabled();
svgNodePlate.setDefaultNodePlate(createNodePlate());
return svgNodePlate;
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java
new file mode 100644
index 00000000000..c1340584b98
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
+import org.eclipse.gmf.tooling.runtime.linklf.LinkLFNodeFigure;
+
+public class LinkLFSVGNodePlateFigure extends SVGNodePlateFigure {
+ private static final double AVOID_DEFAULT_ANCHOR_AREA = 1.0;
+
+ public static final String ENABLE_LINKLF = "papyrus.linklf_enable"; //$NON-NLS-1$
+
+ private final GraphicalEditPart myHost;
+
+ private boolean myLinkLFIsEnabled = false;
+
+ public LinkLFSVGNodePlateFigure(GraphicalEditPart hostEP, int width, int height) {
+ super(width, height);
+ myHost = hostEP;
+ }
+
+ public LinkLFSVGNodePlateFigure withLinkLFEnabled() {
+ myLinkLFIsEnabled = Boolean.getBoolean(ENABLE_LINKLF);
+ return this;
+ }
+
+ @Override
+ protected ConnectionAnchor createAnchor(PrecisionPoint p) {
+ if (!myLinkLFIsEnabled) {
+ return super.createAnchor(p);
+ }
+ if (p == null) {
+ // If the old terminal for the connection anchor cannot be resolved (by SlidableAnchor) a null
+ // PrecisionPoint will passed in - this is handled here
+ return createDefaultAnchor();
+ }
+ PapyrusSlidableSnapToGridAnchor result = new PapyrusSlidableSnapToGridAnchor(this, p);
+ result.setEditPart(myHost);
+ return result;
+ }
+
+ @Override
+ protected double getSlidableAnchorArea() {
+ return myLinkLFIsEnabled ? AVOID_DEFAULT_ANCHOR_AREA : super.getSlidableAnchorArea();
+ }
+
+ protected ConnectionAnchor createConnectionAnchor(Point p) {
+ if (!myLinkLFIsEnabled) {
+ return super.createConnectionAnchor(p);
+ }
+ if (p == null) {
+ return getConnectionAnchor(szAnchor);
+ } else {
+ Point temp = p.getCopy();
+ translateToRelative(temp);
+ PrecisionPoint pt = BaseSlidableAnchor.getAnchorRelativeLocation(temp, getBounds());
+ if (isDefaultAnchorArea(pt)) {
+ return getConnectionAnchor(szAnchor);
+ }
+
+ LinkLFNodeFigure.forceSideForBorderItemAnchorLocation(myHost, pt);
+
+ return createAnchor(pt);
+ }
+ }
+
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusSlidableSnapToGridAnchor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusSlidableSnapToGridAnchor.java
new file mode 100644
index 00000000000..0451d307893
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusSlidableSnapToGridAnchor.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.tooling.runtime.linklf.DiagramGridSpec;
+import org.eclipse.gmf.tooling.runtime.linklf.SlidableSnapToGridAnchor;
+
+/**
+ * Internal class to manage anchors snappable to grid
+ */
+public class PapyrusSlidableSnapToGridAnchor extends SlidableSnapToGridAnchor {
+
+ private EditPart editPart;
+
+ /**
+ * Constructor.
+ *
+ * @param f
+ * @param p
+ */
+ public PapyrusSlidableSnapToGridAnchor(NodeFigure f, PrecisionPoint p) {
+ super(f, p);
+ }
+
+ /**
+ * If grid provider had been set up and has grid enabled then returns active
+ * grid specification in absolute coordinates. Otherwise returns null.
+ *
+ * @return <code>null</code> if no active grid or grid provider had not been
+ * set up.
+ */
+ protected Rectangle getAbsoluteGridSpec() {
+ if (editPart == null) {
+ return null;
+ } else {
+ EditPartViewer viewer = editPart.getViewer();
+ return viewer == null ? null : DiagramGridSpec
+ .getAbsoluteGridSpec(viewer);
+ }
+ }
+
+ public void setEditPart(EditPart editPart) {
+ this.editPart = editPart;
+ }
+
+ /**
+ * @see org.eclipse.gmf.tooling.runtime.linklf.SlidableSnapToGridAnchor#setEditPartViewer(org.eclipse.gef.EditPartViewer)
+ *
+ * @param viewer
+ */
+ @Override
+ public void setEditPartViewer(EditPartViewer viewer) {
+ throw new UnsupportedOperationException("This method should never be invoked inside Papyrus");
+ }
+
+}

Back to the top