[442157] LinkLF: common base clases backported from Papyrus LinkLF with
additional capability for LinkLF to be switched off

Change-Id: I8dddeecc745283c63513b01e6e5a0488697c9945
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/LinkLFShapeNodeAnchorDelegate.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/LinkLFShapeNodeAnchorDelegate.java
index 3f74d5c..021649c 100644
--- a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/LinkLFShapeNodeAnchorDelegate.java
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/LinkLFShapeNodeAnchorDelegate.java
@@ -1,6 +1,7 @@
 package org.eclipse.gmf.tooling.runtime.linklf;
 
 import java.util.Arrays;
+import java.util.Map;
 
 import org.eclipse.draw2d.Connection;
 import org.eclipse.draw2d.ConnectionAnchor;
@@ -16,6 +17,7 @@
 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNodeEditPolicy;
 import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.OrthogonalRouter;
 import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.tooling.runtime.linklf.editparts.LinkLFAnchorsDelegatingEditPart.ConnectionAnchorDelegate;
 
 /**
  * Shared delegate for creation of the {@link SlidableSnapToGridAnchor} for host
@@ -28,7 +30,7 @@
  * 
  * @since 3.3
  */
-public class LinkLFShapeNodeAnchorDelegate {
+public class LinkLFShapeNodeAnchorDelegate implements ConnectionAnchorDelegate {
 
 	/**
 	 * The {@link LinkLFShapeNodeAnchorDelegate} performs additional routing to
@@ -57,6 +59,7 @@
 		return myNodeFigure;
 	}
 
+	@Override
 	public ConnectionAnchor getSourceConnectionAnchor(Request request) {
 		Point fromRequest = safeGetPointFromLinkRequest(request);
 		ConnectionAnchor result = getNodeFigure().getSourceConnectionAnchorAt(
@@ -80,8 +83,9 @@
 					pointsBefore.toIntArray())) {
 				conn.setPoints(pointsBefore);
 				if (router instanceof OrthogonalRouter) {
-					request.getExtendedData().put(KEY_ROUTED_LINK_POINTS,
-							pointsAfter);
+					@SuppressWarnings("unchecked")
+					Map<String, Object> extData = request.getExtendedData();
+					extData.put(KEY_ROUTED_LINK_POINTS, pointsAfter);
 				}
 			}
 			conn.setSourceAnchor(oldSourceAnchor);
@@ -89,6 +93,7 @@
 		return result;
 	}
 
+	@Override
 	public ConnectionAnchor getTargetConnectionAnchor(Request request) {
 		Point fromRequestAbs = safeGetPointFromLinkRequest(request);
 		ConnectionAnchor result = getNodeFigure().getTargetConnectionAnchorAt(
@@ -111,8 +116,9 @@
 					pointsBefore.toIntArray())) {
 				conn.setPoints(pointsBefore);
 				if (router instanceof OrthogonalRouter) {
-					request.getExtendedData().put(KEY_ROUTED_LINK_POINTS,
-							pointsAfter);
+					@SuppressWarnings("unchecked")
+					Map<String, Object> extData = request.getExtendedData();
+					extData.put(KEY_ROUTED_LINK_POINTS, pointsAfter);
 				}
 			}
 			conn.setTargetAnchor(oldTargetAnchor);
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFAnchorsDelegatingEditPart.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFAnchorsDelegatingEditPart.java
new file mode 100644
index 0000000..3053230
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFAnchorsDelegatingEditPart.java
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (c) 2014-15 CEA LIST, Montages AG 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:
+ *   Michael Golubev (Montages) - Initial API and implementation
+ *   
+ *****************************************************************************/
+package org.eclipse.gmf.tooling.runtime.linklf.editparts;
+
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.gef.NodeEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+
+/**
+ * Mixin interface for all LinkLF edit parts that allows to delegate anchors
+ * handling to {@link ConnectionAnchorDelegate}
+ * 
+ * @since 3.3
+ */
+public interface LinkLFAnchorsDelegatingEditPart {
+
+	/**
+	 * Allows to externally change {@link ConnectionAnchorDelegate} and thus
+	 * enable or disable LinkLF mode.
+	 * 
+	 * @param anchorDelegate
+	 *            delegate or <code>null</code> to reset to default GMF Runtime
+	 *            implementation
+	 */
+	public void setAnchorDelegate(ConnectionAnchorDelegate anchorDelegate);
+
+	public NodeFigure getNodeFigure();
+
+	/**
+	 * Common interface for creation of the {@link ConnectionAnchor} for host
+	 * {@link NodeEditPart}s.
+	 * <p/>
+	 * Implemented as a delegate to be easily installed to different
+	 * {@link NodeEditPart} sub-classes that does not share common
+	 * diagram-specific base class.
+	 * <p/>
+	 * 
+	 * @see NodeEditPart
+	 * @since 3.3
+	 */
+	public interface ConnectionAnchorDelegate {
+
+		public ConnectionAnchor getSourceConnectionAnchor(Request request);
+
+		public ConnectionAnchor getTargetConnectionAnchor(Request request);
+
+	}
+
+}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFBorderedShapeEditPart.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFBorderedShapeEditPart.java
new file mode 100644
index 0000000..8247d25
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFBorderedShapeEditPart.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2014-15 CEA LIST, Montages AG 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:
+ *   Michael Golubev (Montages) - Initial API and implementation
+ *   
+ *****************************************************************************/
+package org.eclipse.gmf.tooling.runtime.linklf.editparts;
+
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.gef.Request;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * Extends {@link AbstractBorderedShapeEditPart} with ability to delegate anchor
+ * handling and creation to specific {@link ConnectionAnchorDelegate}.
+ * <p/>
+ * By default LinkLF mode is switched off, but may be enabled by setting
+ * {@link LinkLFShapeNodeEditPart} delegate instance.
+ * 
+ * @since 3.3
+ * @see LinkLFShapeNodeEditPart
+ */
+public abstract class LinkLFBorderedShapeEditPart extends
+		AbstractBorderedShapeEditPart implements
+		LinkLFAnchorsDelegatingEditPart {
+
+	/**
+	 * This is default delegate that just delegates to the super implementation
+	 * in {@link AbstractBorderedShapeEditPart}
+	 */
+	private final ConnectionAnchorDelegate DELEGATE_TO_SUPER = new ConnectionAnchorDelegate() {
+
+		@Override
+		public ConnectionAnchor getTargetConnectionAnchor(Request request) {
+			return LinkLFBorderedShapeEditPart.super
+					.getTargetConnectionAnchor(request);
+		}
+
+		@Override
+		public ConnectionAnchor getSourceConnectionAnchor(Request request) {
+			return LinkLFBorderedShapeEditPart.super
+					.getSourceConnectionAnchor(request);
+		}
+	};
+
+	private ConnectionAnchorDelegate myAnchorDelegate = DELEGATE_TO_SUPER;
+
+	public LinkLFBorderedShapeEditPart(View view) {
+		super(view);
+	}
+
+	@Override
+	public final ConnectionAnchor getSourceConnectionAnchor(Request request) {
+		return myAnchorDelegate.getSourceConnectionAnchor(request);
+	}
+
+	@Override
+	public final ConnectionAnchor getTargetConnectionAnchor(Request request) {
+		return myAnchorDelegate.getTargetConnectionAnchor(request);
+	}
+
+	/**
+	 * Allows to externally change {@link ConnectionAnchorDelegate} and thus
+	 * enable or disable LinkLF mode.
+	 * 
+	 * @param anchorDelegate
+	 *            delegate or <code>null</code> to reset to default GMF Runtime
+	 *            implementation
+	 */
+	public void setAnchorDelegate(ConnectionAnchorDelegate anchorDelegate) {
+		myAnchorDelegate = anchorDelegate;
+		if (myAnchorDelegate == null) {
+			myAnchorDelegate = DELEGATE_TO_SUPER;
+		}
+	}
+	
+	@Override
+	public NodeFigure getNodeFigure() {
+		return super.getNodeFigure();
+	}
+
+}
diff --git a/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFShapeNodeEditPart.java b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFShapeNodeEditPart.java
new file mode 100644
index 0000000..01b4ab5
--- /dev/null
+++ b/plugins/org.eclipse.gmf.tooling.runtime/src/org/eclipse/gmf/tooling/runtime/linklf/editparts/LinkLFShapeNodeEditPart.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2014-15 CEA LIST, Montages AG 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:
+ *   Michael Golubev (Montages) - Initial API and implementation
+ *   
+ *****************************************************************************/
+package org.eclipse.gmf.tooling.runtime.linklf.editparts;
+
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.gef.Request;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * Extends {@link ShapeNodeEditPart} with ability to delegate anchor handling
+ * and creation to specific {@link ConnectionAnchorDelegate}.
+ * <p/>
+ * By default LinkLF mode is switched off, but may be enabled by setting
+ * {@link LinkLFShapeNodeEditPart} delegate instance.
+ * 
+ * @since 3.3
+ * @see LinkLFBorderedShapeEditPart
+ */
+public abstract class LinkLFShapeNodeEditPart extends ShapeNodeEditPart
+		implements LinkLFAnchorsDelegatingEditPart {
+
+	/**
+	 * This is default delegate that just delegates to the super implementation
+	 * in {@link ShapeNodeEditPart}
+	 */
+	private final ConnectionAnchorDelegate DELEGATE_TO_SUPER = new ConnectionAnchorDelegate() {
+
+		@Override
+		public ConnectionAnchor getTargetConnectionAnchor(Request request) {
+			return LinkLFShapeNodeEditPart.super
+					.getTargetConnectionAnchor(request);
+		}
+
+		@Override
+		public ConnectionAnchor getSourceConnectionAnchor(Request request) {
+			return LinkLFShapeNodeEditPart.super
+					.getSourceConnectionAnchor(request);
+		}
+	};
+
+	private ConnectionAnchorDelegate myAnchorDelegate = DELEGATE_TO_SUPER;
+
+	public LinkLFShapeNodeEditPart(View view) {
+		super(view);
+	}
+
+	@Override
+	public final ConnectionAnchor getSourceConnectionAnchor(Request request) {
+		return myAnchorDelegate.getSourceConnectionAnchor(request);
+	}
+
+	@Override
+	public final ConnectionAnchor getTargetConnectionAnchor(Request request) {
+		return myAnchorDelegate.getTargetConnectionAnchor(request);
+	}
+
+	/**
+	 * Allows to externally change {@link ConnectionAnchorDelegate} and thus
+	 * enable or disable LinkLF mode.
+	 * 
+	 * @param anchorDelegate
+	 *            delegate or <code>null</code> to reset to default GMF Runtime
+	 *            implementation
+	 */
+	@Override
+	public void setAnchorDelegate(ConnectionAnchorDelegate anchorDelegate) {
+		myAnchorDelegate = anchorDelegate;
+		if (myAnchorDelegate == null) {
+			myAnchorDelegate = DELEGATE_TO_SUPER;
+		}
+	}
+	
+	@Override
+	public NodeFigure getNodeFigure() {
+		return super.getNodeFigure();
+	}
+
+}