Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #389: Update self message router and feeback #449

Merged
merged 4 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ public ConnectionAnchor getConnectionAnchor(String terminal) {

@Override
public void validate() {
super.validate();

if (isValid()) {
return;
}
MessageDirection direction = computeDirection();
if (getSourceAnchor() instanceof ISideAnchor) {
((ISideAnchor)getSourceAnchor()).setConnectionSide(direction.getExecutionSide(true));
int side = direction.getExecutionSide(true);
((ISideAnchor)getSourceAnchor()).setConnectionSide(side);
}
if (getTargetAnchor() instanceof ISideAnchor) {
((ISideAnchor)getTargetAnchor()).setConnectionSide(direction.getExecutionSide(false));
}
super.validate();
}

MessageDirection computeDirection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public void setConnectionSide(int side) {
}
}

@Override
public Point getReferencePoint() {
Rectangle body = getOwner().getBounds().getCopy();
getOwner().translateToAbsolute(body);
return body.getBottom();
}

@Override
public Point getLocation(Point reference) {
Rectangle body = getOwner().getBounds().getCopy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.papyrus.uml.diagram.sequence.figure.anchors;

import static org.eclipse.draw2d.PositionConstants.LEFT;
import static org.eclipse.draw2d.PositionConstants.RIGHT;

import org.eclipse.core.runtime.Assert;
import org.eclipse.draw2d.AbstractConnectionAnchor;
Expand All @@ -29,7 +30,7 @@ public class ExecutionSpecificationSideAnchor extends AbstractConnectionAnchor i

public ExecutionSpecificationSideAnchor(IFigure figure, int height) {
super(figure);
this.side = LEFT;
this.side = RIGHT; // by default, anchors are located on the right.
this.height = height;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public void setConnectionSide(int side) {
}
}

@Override
public Point getReferencePoint() {
Rectangle body = getOwner().getBounds().getCopy();
getOwner().translateToAbsolute(body);
return body.getTop();
}

@Override
public Point getLocation(Point reference) {
Rectangle body = getOwner().getBounds().getCopy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
*/
public class LifelineBodyAnchor extends AbstractConnectionAnchor implements ISequenceAnchor {

private final LifelineBodyFigure lifelinebodyFigure;
private int distance;


public LifelineBodyAnchor(LifelineBodyFigure lifelinebodyFigure, int distance) {
super(lifelinebodyFigure);
// We actually attach the anchor to the BodyFigure of the Lifeline
// Note: this causes issues for policies/interaction, because the body is far away
// from the Lifeline's Bounds. However, we're only interested in rendering here, and this works fine
this.distance = distance;
this.lifelinebodyFigure = lifelinebodyFigure;
}

@Override
Expand All @@ -45,13 +42,24 @@ public String getTerminal() {

@Override
public Point getLocation(Point reference) {
Rectangle body = lifelinebodyFigure.getBounds().getCopy();
lifelinebodyFigure.translateToAbsolute(body);
int boundedHeight = Math.min(distance, body.height);
int realHeight = (int)Math.round(boundedHeight * getScale(lifelinebodyFigure));
Point location = new Point(0, realHeight);
location.translate(body.getTopLeft());
return location;
return getReferencePoint();
}

@Override
public Point getReferencePoint() {
if (getOwner() == null) {
rschnekenbu marked this conversation as resolved.
Show resolved Hide resolved
return null;
} else {
// reference point is the top of the lifeline
// useful for the router
Rectangle body = getOwner().getBounds().getCopy();
getOwner().translateToAbsolute(body);
int boundedHeight = Math.min(distance, body.height);
int realHeight = (int)Math.round(boundedHeight * getScale(getOwner()));
Point location = new Point(1, realHeight);
location.translate(body.getTopLeft());
return location;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
Expand Down Expand Up @@ -136,7 +137,11 @@ private void refreshLifeline(MLifeline lifeline) {
}

private void refreshEditPartOfShape(Shape shape) {
Object lifelineEditPart = getViewer().getEditPartRegistry().get(shape);
EditPartViewer viewer = getViewer();
if (viewer == null) {
return;
}
Object lifelineEditPart = viewer.getEditPartRegistry().get(shape);
if (lifelineEditPart instanceof EditPart) {
EditPart editPart = (EditPart)lifelineEditPart;
List<?> lifelineEditpartChildren = editPart.getChildren();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

import com.google.common.eventbus.EventBus;

import java.beans.PropertyChangeEvent;
import java.util.List;
import java.util.stream.Stream;

import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.ConnectionLayer;
import org.eclipse.draw2d.ConnectionRouter;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineDecoration;
Expand All @@ -31,32 +34,43 @@
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.Request;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.ConnectionLayerEx;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
import org.eclipse.gmf.runtime.notation.ArrowType;
import org.eclipse.gmf.runtime.notation.IdentityAnchor;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Routing;
import org.eclipse.gmf.runtime.notation.RoutingStyle;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.sequence.figure.MessageFigure;
import org.eclipse.papyrus.uml.diagram.sequence.figure.magnets.ConnectionFigureMagnetHelper;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.Activator;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.policies.LogicalModelElementSemanticEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.policies.MessageBendpointsEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.policies.MessageEndpointEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.locators.SelfMessageRouter;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.tools.MessageMoveTracker;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.tools.SequenceConnectionSelectionTracker;
import org.eclipse.papyrus.uml.interaction.model.MInteraction;
import org.eclipse.papyrus.uml.interaction.model.MLifeline;
import org.eclipse.papyrus.uml.interaction.model.spi.ViewTypes;
import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.UMLPackage;

@SuppressWarnings("restriction")
public class MessageEditPart extends ConnectionNodeEditPart implements ISequenceEditPart {

private final EventBus bus = new EventBus();

private ConnectionFigureMagnetHelper magnetHelper;

private SelfMessageRouter selfMessageRouter;

public MessageEditPart(View view) {
super(view);
}
Expand Down Expand Up @@ -93,6 +107,11 @@ protected void handleNotificationEvent(Notification notification) {
refreshLifelineIfHeightOrPositionHasChanged(notification);
}

@Override
protected void refreshBendpoints() {
// nothing to refresh, as bendpoints are not used
}

protected void updateArrowDecoration() {
updateArrowDecoration(getMessageFigure());
}
Expand Down Expand Up @@ -132,6 +151,9 @@ private void refreshLifeline(MLifeline lifeline) {
}

private void refreshEditPartOfShape(Shape shape) {
if(getViewer() == null) {
return;
}
Object lifelineEditPart = getViewer().getEditPartRegistry().get(shape);
if (lifelineEditPart instanceof EditPart) {
EditPart editPart = (EditPart)lifelineEditPart;
Expand Down Expand Up @@ -224,6 +246,47 @@ protected void refreshRouterChange() {
// No bendpoints in messages to refresh
}

@Override
protected void handlePropertyChangeEvent(PropertyChangeEvent event) {
// Avoid calling super, as it only handles the refresh of the routing property. The super method
// refreshes the router based on the routing style of the notation model. In the case of feedback, the
// router may be different (getting from a self message to a normal message for example). So refresh
// should be avoided in this case, and connection router shall be updated on notation model change
// only. The feedback router is handled in the feedback related methods.
}

@Override
protected void installRouter() {
ConnectionLayer cLayer = (ConnectionLayer)getLayer(LayerConstants.CONNECTION_LAYER);
RoutingStyle style = (RoutingStyle)((View)getModel())
.getStyle(NotationPackage.Literals.ROUTING_STYLE);

if (style != null && cLayer instanceof ConnectionLayerEx) {

ConnectionLayerEx cLayerEx = (ConnectionLayerEx)cLayer;
Routing routing = style.getRouting();
if (Routing.MANUAL_LITERAL == routing) {
getConnectionFigure().setConnectionRouter(cLayerEx.getObliqueRouter());
} else if (Routing.RECTILINEAR_LITERAL == routing) {
getConnectionFigure().setConnectionRouter(getSelfMessageRouter());
} else if (Routing.TREE_LITERAL == routing) {
getConnectionFigure().setConnectionRouter(cLayerEx.getTreeRouter());
}

}

refreshRouterChange();
}

private ConnectionRouter getSelfMessageRouter() {
if (selfMessageRouter == null) {
int minimumWidth = Activator.getDefault().getLayoutConstraints(getEditingDomain())
.getMinimumWidth(ViewTypes.MESSAGE);
selfMessageRouter = new SelfMessageRouter(minimumWidth);
}
return selfMessageRouter;
}

@Override
protected void refreshRoutingStyles() {
// Routing styles are not supported because we do not support bendpoints
Expand Down
Loading