Skip to content
Snippets Groups Projects
Commit ce4458bd authored by David Trachtenherz's avatar David Trachtenherz
Browse files

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
parent 0e2babab
No related branches found
No related tags found
No related merge requests found
...@@ -39,8 +39,8 @@ import org.eclipse.draw2d.geometry.Point; ...@@ -39,8 +39,8 @@ import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification; 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.EObject;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editparts.AbstractConnectionEditPart; import org.eclipse.gef.editparts.AbstractConnectionEditPart;
import org.eclipse.gef.editpolicies.BendpointEditPolicy; import org.eclipse.gef.editpolicies.BendpointEditPolicy;
...@@ -102,11 +102,12 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -102,11 +102,12 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
* The adapter used to receive change notifications for the * The adapter used to receive change notifications for the
* {@link #modelElement}. * {@link #modelElement}.
*/ */
protected final Adapter fullRefreshAdapter = new AdapterImpl() { // protected final Adapter fullRefreshAdapter = new AdapterImpl() {
protected final Adapter fullRefreshAdapter = new EContentAdapter() {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void notifyChanged(Notification notification) { public void notifyChanged(Notification notification) {
super.notifyChanged(notification);
// do not care what happens, just refresh everything // do not care what happens, just refresh everything
refresh(); refresh();
} }
...@@ -121,7 +122,8 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -121,7 +122,8 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
setModel(modelElement); setModel(modelElement);
this.modelElementHandler = (IModelElementHandler<T>) IModelElementHandlerService.INSTANCE this.modelElementHandler = (IModelElementHandler<T>) IModelElementHandlerService.INSTANCE
.getModelElementHandler(modelElement); .getModelElementHandler(modelElement);
this.relationshipLabel = new Label(modelElement.getName()) { this.relationshipLabel = new Label(
determineRelationshipLabelFigureText()) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setBounds(Rectangle rect) { public void setBounds(Rectangle rect) {
...@@ -224,13 +226,13 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -224,13 +226,13 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
@Override @Override
public void activate() { public void activate() {
super.activate(); super.activate();
modelElement.eAdapters().add(fullRefreshAdapter); getModel().eAdapters().add(fullRefreshAdapter);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void deactivate() { public void deactivate() {
modelElement.eAdapters().remove(fullRefreshAdapter); getModel().eAdapters().remove(fullRefreshAdapter);
super.deactivate(); super.deactivate();
} }
...@@ -276,7 +278,7 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -276,7 +278,7 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
// EObjectSelectionUtils requires us to adapt to EObject, since // EObjectSelectionUtils requires us to adapt to EObject, since
// graphical edit parts can be provided as selection as well. // graphical edit parts can be provided as selection as well.
if (key == EObject.class) { if (key == EObject.class) {
return modelElement; return getModel();
} }
return super.getAdapter(key); return super.getAdapter(key);
} }
...@@ -288,9 +290,17 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -288,9 +290,17 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
return new Label(); 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. */ /** Updates the bend points, based on the model. */
protected void refreshBendpoints() { protected void refreshBendpoints() {
Points pts = getConnectionPoints(modelElement); Points pts = getConnectionPoints(getModel());
List<AbsoluteBendpoint> figureConstraint = new ArrayList<AbsoluteBendpoint>(); List<AbsoluteBendpoint> figureConstraint = new ArrayList<AbsoluteBendpoint>();
int size = 0; int size = 0;
...@@ -308,7 +318,7 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase> ...@@ -308,7 +318,7 @@ public abstract class ConnectionEditPartBase<T extends ConnectionSegmentBase>
if (connection.getChildren().contains(relationshipLabel)) { if (connection.getChildren().contains(relationshipLabel)) {
connection.remove(relationshipLabel); connection.remove(relationshipLabel);
} }
relationshipLabel.setText(modelElement.getName()); relationshipLabel.setText(determineRelationshipLabelFigureText());
MidpointLocator mpl = new MidpointLocator(connection, size / 2) { MidpointLocator mpl = new MidpointLocator(connection, size / 2) {
@Override @Override
protected Point getReferencePoint() { protected Point getReferencePoint() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment