Bug 391523 - Revise getSelectionInfo...() in IToolBehaviorProvider

* use of bendpoint colors provided by IConnectionSelectionInfo

Change-Id: I56d3ae32403684fc7ca8b5e41baddcd2eb380991
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/ConnectionBendpointEditPolicy.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/ConnectionBendpointEditPolicy.java
index 4394c88..da3d820 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/ConnectionBendpointEditPolicy.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/policy/ConnectionBendpointEditPolicy.java
@@ -9,6 +9,7 @@
  *
  * Contributors:
  *    SAP AG - initial API, implementation and documentation
+ *    mgorning - Bug 391523 - Revise getSelectionInfo...() in IToolBehaviorProvider
  *
  * </copyright>
  *
@@ -34,7 +35,10 @@
 import org.eclipse.graphiti.features.context.impl.RemoveBendpointContext;
 import org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext;
 import org.eclipse.graphiti.mm.algorithms.styles.Point;
+import org.eclipse.graphiti.mm.pictograms.Connection;
 import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.tb.IConnectionSelectionInfo;
+import org.eclipse.graphiti.tb.IToolBehaviorProvider;
 import org.eclipse.graphiti.ui.internal.command.GefCommandWrapper;
 import org.eclipse.graphiti.ui.internal.config.IConfigurationProviderInternal;
 import org.eclipse.graphiti.ui.internal.figures.GFPolylineConnection;
@@ -49,11 +53,25 @@
 	/** The tolerance for the snap-to adjacent bendpoint feedback. */
 	private static final int SNAP_TO_TOLERANCE = 15;
 
+	private IConnectionSelectionInfo connectionSelectionInfo;
+
 	public ConnectionBendpointEditPolicy(IConfigurationProviderInternal configurationProvider) {
 		super(configurationProvider);
 	}
 
 	@Override
+	public void activate() {
+		super.activate();
+
+		Object model = getHost().getModel();
+		if (model instanceof Connection) {
+			IToolBehaviorProvider tbp = getConfigurationProvider().getDiagramTypeProvider()
+					.getCurrentToolBehaviorProvider();
+			connectionSelectionInfo = tbp.getSelectionInfoForConnection((Connection) model);
+		}
+	}
+
+	@Override
 	protected Command getCreateBendpointCommand(BendpointRequest request) {
 		Command ret = null;
 
@@ -70,11 +88,12 @@
 			// http://www.koders.com/java/fid363E5D238D7C1D6660EBA03C7944827E823C6B42.aspx
 			getConnection().translateToRelative(location);
 
-			AddBendpointContext context = new AddBendpointContext(freeFormConnection, location.x, location.y, bendpointIndex);
+			AddBendpointContext context = new AddBendpointContext(freeFormConnection, location.x, location.y,
+					bendpointIndex);
 			IAddBendpointFeature addBendpointFeature = getFeatureProvider().getAddBendpointFeature(context);
 			if (addBendpointFeature != null) {
-				ret = new GefCommandWrapper(new GenericFeatureCommandWithContext(addBendpointFeature, context), getConfigurationProvider()
-						.getDiagramEditor().getEditingDomain());
+				ret = new GefCommandWrapper(new GenericFeatureCommandWithContext(addBendpointFeature, context),
+						getConfigurationProvider().getDiagramEditor().getEditingDomain());
 			}
 		}
 		// workaround: no snapping to original position
@@ -133,8 +152,8 @@
 
 			IMoveBendpointFeature moveBendpointFeature = getFeatureProvider().getMoveBendpointFeature(context);
 			if (moveBendpointFeature != null) {
-				ret = new GefCommandWrapper(new GenericFeatureCommandWithContext(moveBendpointFeature, context), getConfigurationProvider()
-						.getDiagramEditor().getEditingDomain());
+				ret = new GefCommandWrapper(new GenericFeatureCommandWithContext(moveBendpointFeature, context),
+						getConfigurationProvider().getDiagramEditor().getEditingDomain());
 			}
 		}
 
@@ -165,7 +184,8 @@
 		// ADDED: enable snap-to adjacent bendpoints.
 		snapToAdjacentBendpoints(request, bp.getLocation());
 
-		// <sw 23022009> add: "request.getIndex() < constraint.size()" to fix CSN 0120061532 0001148754 2009
+		// <sw 23022009> add: "request.getIndex() < constraint.size()" to fix
+		// CSN 0120061532 0001148754 2009
 		if (constraint.size() > 0 && request.getIndex() < constraint.size()) {
 			constraint.set(request.getIndex(), bp);
 		} else {
@@ -193,7 +213,8 @@
 		for (int i = 0; i < points.size() - 1; i++) {
 			// CHANGED: create GFBendpointCreationHandle instead of
 			// BendpointCreationHandle
-			list.add(new GFBendpointHandle(connEP, 0, i, getConfigurationProvider(), GFBendpointHandle.Type.CREATE));
+			list.add(new GFBendpointHandle(connEP, 0, i, getConfigurationProvider(), GFBendpointHandle.Type.CREATE,
+					connectionSelectionInfo));
 		}
 
 		return list;
@@ -215,14 +236,19 @@
 
 		for (int i = 0; i < points.size() - 1; i++) {
 			// Put a create handle on the middle of every segment
-			// CHANGED: create GFBendpointCreationHandle instead of BendpointCreationHandle
-			list.add(new GFBendpointHandle(connEP, bendPointIndex, i, getConfigurationProvider(), GFBendpointHandle.Type.CREATE));
+			// CHANGED: create GFBendpointCreationHandle instead of
+			// BendpointCreationHandle
+			list.add(new GFBendpointHandle(connEP, bendPointIndex, i, getConfigurationProvider(),
+					GFBendpointHandle.Type.CREATE, connectionSelectionInfo));
 
 			// If the current user bendpoint matches a bend location, show a
 			// move handle
-			if (i < points.size() - 1 && bendPointIndex < bendPoints.size() && currBendPoint.equals(points.getPoint(i + 1))) {
-				// CHANGED: create GFBendpointMoveHandle instead of BendpointMoveHandle
-				list.add(new GFBendpointHandle(connEP, bendPointIndex, i + 1, getConfigurationProvider(), GFBendpointHandle.Type.MOVE));
+			if (i < points.size() - 1 && bendPointIndex < bendPoints.size()
+					&& currBendPoint.equals(points.getPoint(i + 1))) {
+				// CHANGED: create GFBendpointMoveHandle instead of
+				// BendpointMoveHandle
+				list.add(new GFBendpointHandle(connEP, bendPointIndex, i + 1, getConfigurationProvider(),
+						GFBendpointHandle.Type.MOVE, connectionSelectionInfo));
 
 				// Go to the next user bendpoint
 				bendPointIndex++;
@@ -265,7 +291,8 @@
 		// moved onto the line,
 		// so that the bendpoint is deleted. In that case just use the next
 		// point, which is the connections end-point.
-		int successorIndex = (request.getIndex() + 2 >= points.size()) ? request.getIndex() + 1 : request.getIndex() + 2;
+		int successorIndex = (request.getIndex() + 2 >= points.size()) ? request.getIndex() + 1
+				: request.getIndex() + 2;
 		org.eclipse.draw2d.geometry.Point successor = points.getPoint(successorIndex).getCopy();
 		getConnection().translateToAbsolute(successor);
 		int deltaSuccessor = getDistanceBetweenPoints(p, successor);
@@ -338,7 +365,8 @@
 
 	@Override
 	protected void showSelection() {
-		IMoveBendpointFeature moveBendpointFeature = getFeatureProvider().getMoveBendpointFeature(new MoveBendpointContext(null));
+		IMoveBendpointFeature moveBendpointFeature = getFeatureProvider().getMoveBendpointFeature(
+				new MoveBendpointContext(null));
 		if (moveBendpointFeature != null) {
 			super.showSelection();
 		}
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/GFBendpointHandle.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/GFBendpointHandle.java
index 820441f..eab9164 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/GFBendpointHandle.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/GFBendpointHandle.java
@@ -9,6 +9,7 @@
  *
  * Contributors:
  *    SAP AG - initial API, implementation and documentation
+ *    mgorning - Bug 391523 - Revise getSelectionInfo...() in IToolBehaviorProvider
  *
  * </copyright>
  *
@@ -32,9 +33,12 @@
 import org.eclipse.graphiti.features.context.impl.AddBendpointContext;
 import org.eclipse.graphiti.features.context.impl.MoveBendpointContext;
 import org.eclipse.graphiti.features.context.impl.RemoveBendpointContext;
+import org.eclipse.graphiti.tb.IConnectionSelectionInfo;
 import org.eclipse.graphiti.ui.internal.config.IConfigurationProviderInternal;
 import org.eclipse.graphiti.ui.internal.figures.GFFigureUtil;
+import org.eclipse.graphiti.ui.internal.util.DataTypeTransformation;
 import org.eclipse.graphiti.ui.platform.IConfigurationProvider;
+import org.eclipse.graphiti.util.IColorConstant;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 
@@ -101,6 +105,8 @@
 	 */
 	private String dragTrackerType;
 
+	private IConnectionSelectionInfo connectionSelectionInfo;
+
 	/**
 	 * Creates a new GFBendpointHandle.
 	 * 
@@ -116,8 +122,11 @@
 	 * @param type
 	 *            The type of the bendpoint handle (create/move).
 	 */
-	public GFBendpointHandle(ConnectionEditPart owner, int index, int locatorIndex, IConfigurationProviderInternal configurationProvider, Type type) {
+	public GFBendpointHandle(ConnectionEditPart owner, int index, int locatorIndex,
+			IConfigurationProviderInternal configurationProvider, Type type,
+			IConnectionSelectionInfo connectionSelectionInfo) {
 		super();
+		this.connectionSelectionInfo = connectionSelectionInfo;
 		setCursor(Cursors.NO);
 
 		setConfigurationProvider(configurationProvider);
@@ -205,6 +214,13 @@
 	}
 
 	private Color getFgColorPrimary() {
+		if (connectionSelectionInfo != null) {
+			IColorConstant color = connectionSelectionInfo.getPrimarySelectionBendpointForegroundColor();
+			if (color != null) {
+				Color swtColor = DataTypeTransformation.toSwtColor(configurationProvider.getResourceRegistry(), color);
+				return swtColor;
+			}
+		}
 		if (FG_COLOR_PRIMARY == null || FG_COLOR_PRIMARY.isDisposed()) {
 			FG_COLOR_PRIMARY = configurationProvider.getResourceRegistry().getSwtColor("cc6a01"); //$NON-NLS-1$
 		}
@@ -212,6 +228,13 @@
 	}
 
 	private Color getFgColorSecondary() {
+		if (connectionSelectionInfo != null) {
+			IColorConstant color = connectionSelectionInfo.getSecondarySelectionBendpointForegroundColor();
+			if (color != null) {
+				Color swtColor = DataTypeTransformation.toSwtColor(configurationProvider.getResourceRegistry(), color);
+				return swtColor;
+			}
+		}
 		if (FG_COLOR_SECONDARY == null || FG_COLOR_SECONDARY.isDisposed()) {
 			FG_COLOR_SECONDARY = configurationProvider.getResourceRegistry().getSwtColor("cc6a01"); //$NON-NLS-1$
 		}
@@ -219,6 +242,13 @@
 	}
 
 	private Color getBgColorPrimary() {
+		if (connectionSelectionInfo != null) {
+			IColorConstant color = connectionSelectionInfo.getPrimarySelectionBendpointBackgroundColor();
+			if (color != null) {
+				Color swtColor = DataTypeTransformation.toSwtColor(configurationProvider.getResourceRegistry(), color);
+				return swtColor;
+			}
+		}
 		if (BG_COLOR_PRIMARY == null || BG_COLOR_PRIMARY.isDisposed()) {
 			BG_COLOR_PRIMARY = configurationProvider.getResourceRegistry().getSwtColor("ffaa2f"); //$NON-NLS-1$
 		}
@@ -226,6 +256,13 @@
 	}
 
 	private Color getBgColorSecondary() {
+		if (connectionSelectionInfo != null) {
+			IColorConstant color = connectionSelectionInfo.getSecondarySelectionBendpointBackgroundColor();
+			if (color != null) {
+				Color swtColor = DataTypeTransformation.toSwtColor(configurationProvider.getResourceRegistry(), color);
+				return swtColor;
+			}
+		}
 		if (BG_COLOR_SECONDARY == null || BG_COLOR_SECONDARY.isDisposed()) {
 			BG_COLOR_SECONDARY = configurationProvider.getResourceRegistry().getSwtColor("ffffff"); //$NON-NLS-1$
 		}