From ce4458bd950fa07429eb44aaf3c31a5129ae2460 Mon Sep 17 00:00:00 2001
From: David Trachtenherz <trachtenherz@fortiss.org>
Date: Tue, 14 Feb 2012 16:00:15 +0000
Subject: [PATCH] Adjustments of label text and refresh adapter, now more
 similar to GraphicalEditPartBase: - fullRefreshAdapter is now an
 EContentAdapter - relationshipLabel text now determined by
 determineRelationshipLabelFigureText() refs 336

---
 .../ui/editpart/ConnectionEditPartBase.java   | 28 +++++++++++++------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java
index 5f99bc15b..d727cbfe0 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editpart/ConnectionEditPartBase.java
@@ -39,8 +39,8 @@ import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.emf.common.notify.Adapter;
 import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EContentAdapter;
 import org.eclipse.gef.commands.Command;
 import org.eclipse.gef.editparts.AbstractConnectionEditPart;
 import org.eclipse.gef.editpolicies.BendpointEditPolicy;
@@ -102,11 +102,12 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
 	 * The adapter used to receive change notifications for the
 	 * {@link #modelElement}.
 	 */
-	protected final Adapter fullRefreshAdapter = new AdapterImpl() {
-
+	// protected final Adapter fullRefreshAdapter = new AdapterImpl() {
+	protected final Adapter fullRefreshAdapter = new EContentAdapter() {
 		/** {@inheritDoc} */
 		@Override
 		public void notifyChanged(Notification notification) {
+			super.notifyChanged(notification);
 			// do not care what happens, just refresh everything
 			refresh();
 		}
@@ -121,7 +122,8 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
 		setModel(modelElement);
 		this.modelElementHandler = (IModelElementHandler<T>) IModelElementHandlerService.INSTANCE
 				.getModelElementHandler(modelElement);
-		this.relationshipLabel = new Label(modelElement.getName()) {
+		this.relationshipLabel = new Label(
+				determineRelationshipLabelFigureText()) {
 			/** {@inheritDoc} */
 			@Override
 			public void setBounds(Rectangle rect) {
@@ -224,13 +226,13 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
 	@Override
 	public void activate() {
 		super.activate();
-		modelElement.eAdapters().add(fullRefreshAdapter);
+		getModel().eAdapters().add(fullRefreshAdapter);
 	}
 
 	/** {@inheritDoc} */
 	@Override
 	public void deactivate() {
-		modelElement.eAdapters().remove(fullRefreshAdapter);
+		getModel().eAdapters().remove(fullRefreshAdapter);
 		super.deactivate();
 	}
 
@@ -276,7 +278,7 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
 		// EObjectSelectionUtils requires us to adapt to EObject, since
 		// graphical edit parts can be provided as selection as well.
 		if (key == EObject.class) {
-			return modelElement;
+			return getModel();
 		}
 		return super.getAdapter(key);
 	}
@@ -288,9 +290,17 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
 		return new Label();
 	}
 
+	/**
+	 * Determines the text of the relationship label figure during a refresh.
+	 * The default implementation returns the model element name.
+	 */
+	protected String determineRelationshipLabelFigureText() {
+		return getModel().getName();
+	}
+
 	/** Updates the bend points, based on the model. */
 	protected void refreshBendpoints() {
-		Points pts = getConnectionPoints(modelElement);
+		Points pts = getConnectionPoints(getModel());
 
 		List<AbsoluteBendpoint> figureConstraint = new ArrayList<AbsoluteBendpoint>();
 		int size = 0;
@@ -308,7 +318,7 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
 		if (connection.getChildren().contains(relationshipLabel)) {
 			connection.remove(relationshipLabel);
 		}
-		relationshipLabel.setText(modelElement.getName());
+		relationshipLabel.setText(determineRelationshipLabelFigureText());
 		MidpointLocator mpl = new MidpointLocator(connection, size / 2) {
 			@Override
 			protected Point getReferencePoint() {
-- 
GitLab