From 4c24265df4bd0694977d3ecf10cf0e5122438e09 Mon Sep 17 00:00:00 2001
From: Daniel Ratiu <ratiu@fortiss.org>
Date: Thu, 20 Oct 2011 11:53:55 +0000
Subject: [PATCH] first steps for the component architecture simulator -- still
 hacky but some intermediate results are available refs 236

---
 .../LayoutedConnectionEditPartBase.java       | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/LayoutedConnectionEditPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/LayoutedConnectionEditPartBase.java
index 72f6a78c2..bbe163aab 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/LayoutedConnectionEditPartBase.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/LayoutedConnectionEditPartBase.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.eclipse.draw2d.AbsoluteBendpoint;
 import org.eclipse.draw2d.BendpointConnectionRouter;
+import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.draw2d.Graphics;
 import org.eclipse.draw2d.Label;
 import org.eclipse.draw2d.MidpointLocator;
@@ -32,6 +33,7 @@ import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.ecore.util.EContentAdapter;
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
+import org.eclipse.swt.graphics.Color;
 import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
 import org.fortiss.tooling.base.model.base.ConnectionSegmentBase;
 import org.fortiss.tooling.base.model.layout.LayoutPackage;
@@ -61,6 +63,9 @@ public abstract class LayoutedConnectionEditPartBase<T extends ConnectionSegment
 	/** The label drawn next to the connection. */
 	protected final Label relationshipLabel = new Label(modelElement.getName());
 
+	/** The simulation value label drawn in highlighted color. */
+	private final Label simulationLabel = new Label("");
+
 	/** The adapter used for dealing with changes of the */
 	// TODO (FH): check for collision with full refresh adapter of super class !
 	protected final Adapter layoutChanged = new EContentAdapter() {
@@ -83,6 +88,7 @@ public abstract class LayoutedConnectionEditPartBase<T extends ConnectionSegment
 	/** Constructor. */
 	protected LayoutedConnectionEditPartBase(T modelElement) {
 		super(modelElement);
+		simulationLabel.setForegroundColor(getSimulationLabelColor());
 	}
 
 	/** {@inheritDoc} */
@@ -127,6 +133,23 @@ public abstract class LayoutedConnectionEditPartBase<T extends ConnectionSegment
 		};
 		connection.add(relationshipLabel, mpl);
 
+		// Update simulation label
+		if (connection.getChildren().contains(simulationLabel)) {
+			connection.remove(simulationLabel);
+		}
+		if (!"".equals(simulationLabel.getText())) {
+			mpl = new MidpointLocator(connection, size / 2) {
+				@Override
+				protected org.eclipse.draw2d.geometry.Point getReferencePoint() {
+					org.eclipse.draw2d.geometry.Point p = super
+							.getReferencePoint();
+					p.y += 2 * DefaultLayoutConstants.DEFAULT_GRID_SIZE;
+					return p;
+				}
+			};
+			connection.add(simulationLabel, mpl);
+		}
+
 		getConnectionFigure().setRoutingConstraint(figureConstraint);
 	}
 
@@ -166,4 +189,15 @@ public abstract class LayoutedConnectionEditPartBase<T extends ConnectionSegment
 	protected void refreshVisuals() {
 		refreshBendpoints();
 	}
+
+	/** Sets the simulation value label to the given value. */
+	public void setSimulationValue(String value) {
+		simulationLabel.setText(value);
+		refreshVisuals();
+	}
+
+	/** Returns the simulation label color. */
+	protected Color getSimulationLabelColor() {
+		return ColorConstants.red;
+	}
 }
-- 
GitLab