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

Nested Executions initial implementation #394

Merged
merged 11 commits into from
Nov 8, 2018
28 changes: 23 additions & 5 deletions examples/LightweightSequenceExample/AnchorsModel.notation
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
<children xmi:type="notation:Shape" xmi:id="_K-C0I0FsEei1zqUjbAwdJw" type="Label_Lifeline_Name"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_8e1YkUFrEei1zqUjbAwdJw" type="Shape_Lifeline_Body">
<children xmi:type="notation:Shape" xmi:id="_WOpEkHoVEei2Pril6_cVrw" type="Shape_Execution_Specification">
<element xmi:type="uml:ActionExecutionSpecification" href="AnchorsModel.uml#_WJbNYHoVEei2Pril6_cVrw"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_WOpEkXoVEei2Pril6_cVrw" x="-5" y="131" width="10" height="40"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_W-OHYHoVEei2Pril6_cVrw" type="Shape_Execution_Specification">
<element xmi:type="uml:ActionExecutionSpecification" href="AnchorsModel.uml#_W5-gkHoVEei2Pril6_cVrw"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_W-OHYXoVEei2Pril6_cVrw" x="-5" y="37" width="10" height="40"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_XkzmQHoVEei2Pril6_cVrw" type="Shape_Execution_Specification">
<element xmi:type="uml:ActionExecutionSpecification" href="AnchorsModel.uml#_Xe3WUHoVEei2Pril6_cVrw"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_XkzmQXoVEei2Pril6_cVrw" x="-5" y="84" width="10" height="40"/>
</children>
<layoutConstraint xmi:type="notation:Size" xmi:id="_vOnYUUFuEeioV-9wZ7qOXA" height="300"/>
</children>
<element xmi:type="uml:Lifeline" href="AnchorsModel.uml#_KXH04CHtEeiIiO6KSag_9g"/>
Expand All @@ -43,14 +55,20 @@
<edges xmi:type="notation:Connector" xmi:id="_zzyVYCHtEeiIiO6KSag_9g" type="Edge_Message" source="_8e1YkEFrEei1zqUjbAwdJw" target="_8e1YkUFrEei1zqUjbAwdJw">
<element xmi:type="uml:Message" href="AnchorsModel.uml#_-fTu8Ce2Eei33oLfoI_NYA"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_zzyVYSHtEeiIiO6KSag_9g"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVYiHtEeiIiO6KSag_9g" id="10"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVYyHtEeiIiO6KSag_9g" id="10"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVYiHtEeiIiO6KSag_9g" id="176"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVYyHtEeiIiO6KSag_9g" id="188"/>
</edges>
<edges xmi:type="notation:Connector" xmi:id="_zzyVZCHtEeiIiO6KSag_9g" type="Edge_Message" source="_8e1YkUFrEei1zqUjbAwdJw" target="_8e1YkEFrEei1zqUjbAwdJw">
<element xmi:type="uml:Message" href="AnchorsModel.uml#_SlpyIie3Eei33oLfoI_NYA"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_zzyVZSHtEeiIiO6KSag_9g"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVZiHtEeiIiO6KSag_9g" id="25"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVZyHtEeiIiO6KSag_9g" id="40"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVZiHtEeiIiO6KSag_9g" id="212"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_zzyVZyHtEeiIiO6KSag_9g" id="251"/>
</edges>
<edges xmi:type="notation:Connector" xmi:id="_QXm_wHoVEei2Pril6_cVrw" type="Edge_Message" source="_8e1YkEFrEei1zqUjbAwdJw" target="_8e1YkUFrEei1zqUjbAwdJw">
<element xmi:type="uml:Message" href="AnchorsModel.uml#_QXiuUHoVEei2Pril6_cVrw"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_QXm_wXoVEei2Pril6_cVrw"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_QXm_wnoVEei2Pril6_cVrw" id="4"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_QXm_w3oVEei2Pril6_cVrw" id="4"/>
</edges>
</notation:Diagram>
<notation:Diagram xmi:id="_ZqujACIHEei5e5kSMChtjA" type="LightweightSequenceDiagram" name="LifelineHeaderAnchorsDiagram" measurementUnit="Pixel">
Expand Down Expand Up @@ -178,7 +196,7 @@
<children xmi:type="notation:Shape" xmi:id="_8e1Yl0FrEei1zqUjbAwdJw" type="Shape_Lifeline_Body">
<children xmi:type="notation:Shape" xmi:id="_hsd48CIUEeiFUtGmEMBqqw" type="Shape_Execution_Specification">
<element xmi:type="uml:ActionExecutionSpecification" href="AnchorsModel.uml#_UmObcCIUEeiFUtGmEMBqqw"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_hsd48SIUEeiFUtGmEMBqqw" x="33" y="25" width="10" height="150"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_hsd48SIUEeiFUtGmEMBqqw" x="0" y="25" width="10" height="150"/>
</children>
<layoutConstraint xmi:type="notation:Size" xmi:id="_O6vy4EFvEeioV-9wZ7qOXA" height="300"/>
</children>
Expand Down
16 changes: 14 additions & 2 deletions examples/LightweightSequenceExample/AnchorsModel.uml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@
<importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
</packageImport>
<packagedElement xmi:type="uml:Interaction" xmi:id="_4ihK0CHsEeiIiO6KSag_9g" name="LifelineBodyAnchors">
<lifeline xmi:type="uml:Lifeline" xmi:id="_JbPbcCHtEeiIiO6KSag_9g" name="LeftLine" coveredBy="_CkcYUCe3Eei33oLfoI_NYA _SlpyISe3Eei33oLfoI_NYA"/>
<lifeline xmi:type="uml:Lifeline" xmi:id="_KXH04CHtEeiIiO6KSag_9g" name="RightLine" coveredBy="_LR0YICe3Eei33oLfoI_NYA _SlpyICe3Eei33oLfoI_NYA"/>
<lifeline xmi:type="uml:Lifeline" xmi:id="_JbPbcCHtEeiIiO6KSag_9g" name="LeftLine" coveredBy="_CkcYUCe3Eei33oLfoI_NYA _SlpyISe3Eei33oLfoI_NYA _QXfD8HoVEei2Pril6_cVrw"/>
<lifeline xmi:type="uml:Lifeline" xmi:id="_KXH04CHtEeiIiO6KSag_9g" name="RightLine" coveredBy="_LR0YICe3Eei33oLfoI_NYA _SlpyICe3Eei33oLfoI_NYA _QXhgMHoVEei2Pril6_cVrw _WJb0cHoVEei2Pril6_cVrw _WJbNYHoVEei2Pril6_cVrw _WJcbgHoVEei2Pril6_cVrw _W5-gkXoVEei2Pril6_cVrw _W5-gkHoVEei2Pril6_cVrw _W5_HoHoVEei2Pril6_cVrw _Xe3WUXoVEei2Pril6_cVrw _Xe3WUHoVEei2Pril6_cVrw _Xe39YHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_CkcYUCe3Eei33oLfoI_NYA" name="left-send" covered="_JbPbcCHtEeiIiO6KSag_9g" message="_-fTu8Ce2Eei33oLfoI_NYA"/>
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_LR0YICe3Eei33oLfoI_NYA" name="right-recv" covered="_KXH04CHtEeiIiO6KSag_9g" message="_-fTu8Ce2Eei33oLfoI_NYA"/>
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_SlpyICe3Eei33oLfoI_NYA" name="right-send" covered="_KXH04CHtEeiIiO6KSag_9g" message="_SlpyIie3Eei33oLfoI_NYA"/>
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_SlpyISe3Eei33oLfoI_NYA" name="left-recv" covered="_JbPbcCHtEeiIiO6KSag_9g" message="_SlpyIie3Eei33oLfoI_NYA"/>
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_QXfD8HoVEei2Pril6_cVrw" covered="_JbPbcCHtEeiIiO6KSag_9g" message="_QXiuUHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_QXhgMHoVEei2Pril6_cVrw" covered="_KXH04CHtEeiIiO6KSag_9g" message="_QXiuUHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ExecutionOccurrenceSpecification" xmi:id="_W5-gkXoVEei2Pril6_cVrw" covered="_KXH04CHtEeiIiO6KSag_9g" execution="_W5-gkHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ActionExecutionSpecification" xmi:id="_W5-gkHoVEei2Pril6_cVrw" name="Execution2" covered="_KXH04CHtEeiIiO6KSag_9g" finish="_W5_HoHoVEei2Pril6_cVrw" start="_W5-gkXoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ExecutionOccurrenceSpecification" xmi:id="_W5_HoHoVEei2Pril6_cVrw" covered="_KXH04CHtEeiIiO6KSag_9g" execution="_W5-gkHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ExecutionOccurrenceSpecification" xmi:id="_Xe3WUXoVEei2Pril6_cVrw" covered="_KXH04CHtEeiIiO6KSag_9g" execution="_Xe3WUHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ActionExecutionSpecification" xmi:id="_Xe3WUHoVEei2Pril6_cVrw" name="Execution3" covered="_KXH04CHtEeiIiO6KSag_9g" finish="_Xe39YHoVEei2Pril6_cVrw" start="_Xe3WUXoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ExecutionOccurrenceSpecification" xmi:id="_Xe39YHoVEei2Pril6_cVrw" covered="_KXH04CHtEeiIiO6KSag_9g" execution="_Xe3WUHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ExecutionOccurrenceSpecification" xmi:id="_WJb0cHoVEei2Pril6_cVrw" covered="_KXH04CHtEeiIiO6KSag_9g" execution="_WJbNYHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ActionExecutionSpecification" xmi:id="_WJbNYHoVEei2Pril6_cVrw" name="Execution1" covered="_KXH04CHtEeiIiO6KSag_9g" finish="_WJcbgHoVEei2Pril6_cVrw" start="_WJb0cHoVEei2Pril6_cVrw"/>
<fragment xmi:type="uml:ExecutionOccurrenceSpecification" xmi:id="_WJcbgHoVEei2Pril6_cVrw" covered="_KXH04CHtEeiIiO6KSag_9g" execution="_WJbNYHoVEei2Pril6_cVrw"/>
<message xmi:type="uml:Message" xmi:id="_-fTu8Ce2Eei33oLfoI_NYA" name="leftToRight" messageSort="asynchCall" receiveEvent="_LR0YICe3Eei33oLfoI_NYA" sendEvent="_CkcYUCe3Eei33oLfoI_NYA"/>
<message xmi:type="uml:Message" xmi:id="_SlpyIie3Eei33oLfoI_NYA" name="rightToLeft" messageSort="asynchCall" receiveEvent="_SlpyISe3Eei33oLfoI_NYA" sendEvent="_SlpyICe3Eei33oLfoI_NYA"/>
<message xmi:type="uml:Message" xmi:id="_QXiuUHoVEei2Pril6_cVrw" messageSort="asynchCall" receiveEvent="_QXhgMHoVEei2Pril6_cVrw" sendEvent="_QXfD8HoVEei2Pril6_cVrw"/>
</packagedElement>
<packagedElement xmi:type="uml:Interaction" xmi:id="_Zqq4oCIHEei5e5kSMChtjA" name="LifelineHeaderAnchor">
<lifeline xmi:type="uml:Lifeline" xmi:id="_Zqq4oSIHEei5e5kSMChtjA" name="LeftLine" coveredBy="_1oUqsSe3Eei33oLfoI_NYA"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
Expand Down Expand Up @@ -97,11 +96,6 @@ protected ConnectionAnchor createBodyAnchor(int height) {
return new LifelineBodyAnchor(this, height);
}

@Override
public PointList getPolygonPoints() {
return super.getPolygonPoints();
}

@Override
public ConnectionAnchor getSourceConnectionAnchorAt(Point p) {
// This method would be used to retrieve an Anchor from a Request (Create, Reconnect). However,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*****************************************************************************
* Copyright (c) 2018 EclipseSource and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* R. Schnekenburger - Initial API and implementation
*
*****************************************************************************/

package org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.policies;

import java.util.Optional;
import java.util.OptionalInt;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.util.SequenceTypeSwitch;
import org.eclipse.papyrus.uml.interaction.model.MElement;
import org.eclipse.papyrus.uml.interaction.model.MExecution;
import org.eclipse.papyrus.uml.interaction.model.MInteraction;
import org.eclipse.papyrus.uml.interaction.model.MObject;
import org.eclipse.papyrus.uml.interaction.model.util.Optionals;
import org.eclipse.papyrus.uml.interaction.model.util.SequenceDiagramSwitch;
import org.eclipse.uml2.uml.Element;

/**
* ExecutionSpecification creation edit policy based on the <em>Logical Model</em>.
*/
public class ExecutionSpecificationCreationEditPolicy extends LogicalModelCreationEditPolicy {

@Override
protected Optional<org.eclipse.emf.common.command.Command> getCreationCommand(MInteraction interaction,
Element parentElement, View parentView, Point location, Dimension size, IElementType type) {

Optional<MExecution> mExecution = Optionals.as(interaction.getElement(parentElement),
MExecution.class);
if (!mExecution.isPresent()) {
return Optional.empty();
}

class CommandSwitch extends SequenceDiagramSwitch<Command> {

@Override
@SuppressWarnings("hiding")
public Command caseMExecution(MExecution execution) {
return new SequenceTypeSwitch<Command>() {
@Override
public Command caseExecutionSpecification(IElementType type) {
EClass eClass = type.getEClass();
Optional<MElement<?>> before = execution.elementAt(location.y());
int offset = location.y();

if (before.isPresent()) {
// Get the bottom of the before element
OptionalInt bottom = before.get().getBottom();
if (bottom.isPresent()) {
int relativeBottom = bottom.getAsInt()
- getLayoutHelper().getTop((Shape)parentView);
offset = offset - relativeBottom;
} else {
// If it doesn't have a bottom, then ignore it
before = Optional.empty();
}
}

return execution.insertNestedExecutionAfter(before.orElse(execution), offset,
size != null ? size.height : 40, eClass);
}

@Override
public Command caseAsyncMessage(IHintedType type) {
return null;
}

@Override
public Command defaultCase(Object object) {
return CommandSwitch.super.caseMExecution(execution);
}
}.doSwitch(type);
}

@Override
public Command defaultCase(MObject object) {
return UnexecutableCommand.INSTANCE;
}
}

return mExecution.map(new CommandSwitch()::doSwitch);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.Activator;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.parts.ExecutionSpecificationEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.parts.InteractionCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.runtime.internal.edit.parts.LifelineBodyEditPart;
import org.eclipse.papyrus.uml.interaction.model.spi.ViewTypes;
Expand Down Expand Up @@ -55,6 +56,8 @@ public NoPapyrusEditPolicyProvider() {
LifelineCreationEditPolicy::new);
substitute(InteractionCompartmentEditPart.class, EditPolicyRoles.CREATION_ROLE,
InteractionCreationEditPolicy::new);
substitute(ExecutionSpecificationEditPart.class, EditPolicyRoles.CREATION_ROLE,
ExecutionSpecificationCreationEditPolicy::new);

// Diagram assistant edit policies
substitute(LifelineBodyEditPart.class, EditPolicyRoles.POPUPBAR_ROLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.draw2d.geometry.Translatable;
import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
import org.eclipse.papyrus.uml.diagram.sequence.figure.LifelineHeaderFigure;

//TODO Support a side (Current it is always to the right side)
public class ExecutionSpecificationBorderItemLocator implements IBorderItemLocator {
Expand All @@ -32,44 +30,16 @@ public ExecutionSpecificationBorderItemLocator(IFigure figure) {

@Override
public void relocate(IFigure borderExecutionSpecification) {
Point location = new Point(0, getConstraint().y);
translateToInteraction(location);
int width = borderExecutionSpecification.getBounds().width;
Rectangle parentExecution = parentExecutionSpecification.getBounds().getCopy();

location.translate(-width / 2., 0); // Translate to the right border of the parent
Point location = new Point(parentExecution.getRight().x() - getConstraint().width / 2,
parentExecution.getTop().y + getConstraint().y);

Rectangle newBounds = getConstraint().getCopy();
newBounds.setLocation(location);
borderExecutionSpecification.setBounds(newBounds);
}

/**
* <p>
* The border execution specification coordinates are relative to this.figure (Which is also an execution
* specification). The result coordinates must be relative to the interaction (Lifeline's parent).
* </p>
* <p>
* This is required because neither the Lifeline nor the Execution Specification has an X/Y Layout
* Compartment (Only the interaction does).
* </p>
*
* @param bounds
* The bounds to be translated to the lifeline's parent coordinates system
*/
// TODO: Is there a way to make this more generic, e.g. by identifying the first non-null, non-delegating
// layout?
private void translateToInteraction(Translatable bounds) {
IFigure parent = parentExecutionSpecification;
while (parent != null) {
parent.translateToParent(bounds);
if (parent instanceof LifelineHeaderFigure) {
parent.translateToParent(bounds);
return;
}
parent = parent.getParent();
}
}

private Rectangle getConstraint() {
return this.constraint;
}
Expand All @@ -81,7 +51,12 @@ public void setConstraint(Rectangle constraint) {

@Override
public Rectangle getValidLocation(Rectangle proposedLocation, IFigure borderItem) {
return proposedLocation; // TODO Shift x and limit to the height of the parent
Rectangle parentExecution = parentExecutionSpecification.getBounds().getCopy();
Point location = new Point(parentExecution.getRight().x - getConstraint().width / 2,
parentExecution.getTop().y + getConstraint().y);
Rectangle newBounds = getConstraint().getCopy();
newBounds.setLocation(location);
return newBounds;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Object getImage(Object object) {
@Override
public String getText(Object object) {
String label = ((MDestruction) object).getName();
return (label == null) || (label.length() == 0) ? getString("_UI_MDestruction_type") : //$NON-NLS-1$
return label == null || label.length() == 0 ? getString("_UI_MDestruction_type") : //$NON-NLS-1$
getString("_UI_MDestruction_type") + " " + label; //$NON-NLS-1$ //$NON-NLS-2$
}

Expand Down
Loading