diff options
author | ptessier | 2017-11-16 10:37:34 +0000 |
---|---|---|
committer | ptessier | 2018-01-10 11:12:02 +0000 |
commit | bd76aeb90c96045ffe24dd880ea580cee225e0bc (patch) | |
tree | 2cb85f22e5e1468b88be0aa6fe3c7bb17188f2ce /plugins/uml/diagram | |
parent | fdce1a4aef9455a0cd5ad514ac5cf5792d64b4b2 (diff) | |
download | org.eclipse.papyrus-bd76aeb90c96045ffe24dd880ea580cee225e0bc.tar.gz org.eclipse.papyrus-bd76aeb90c96045ffe24dd880ea580cee225e0bc.tar.xz org.eclipse.papyrus-bd76aeb90c96045ffe24dd880ea580cee225e0bc.zip |
Bug 527333 - [Sequence Diagram] Some error exist in event replacement
for execution specification
- ExecSpec event replacement:
- can't link message to the start or the finish of an execution
specification if a messageEnd is already set.
- UpdateExecSpecWeakRef:
- do not move message if it is at start event
- just move first found element, other will follow the move
- Cast error fix when target or source is related to an other message.
-...
Change-Id: I5c4034b5259d20d6544eb0df10bf1628930450ed
Signed-off-by: Mickael ADAM <mickael.adam@all4tec.net>
Diffstat (limited to 'plugins/uml/diagram')
4 files changed, 195 insertions, 175 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/UpdateWeakReferenceForExecSpecEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/UpdateWeakReferenceForExecSpecEditPolicy.java index 92e943877e2..be73d8d3482 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/UpdateWeakReferenceForExecSpecEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/UpdateWeakReferenceForExecSpecEditPolicy.java @@ -42,6 +42,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpec import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractMessageEditPart; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart; import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin; +import org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling.GridManagementEditPolicy; import org.eclipse.papyrus.uml.diagram.sequence.util.LifelineEditPartUtil; import org.eclipse.papyrus.uml.diagram.sequence.util.LogOptions; import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil; @@ -57,13 +58,15 @@ import org.eclipse.uml2.uml.OccurrenceSpecification; * */ public class UpdateWeakReferenceForExecSpecEditPolicy extends UpdateWeakReferenceEditPolicy { - public static final String UDPATE_WEAK_REFERENCE_FOR_EXECSPEC = "UpdateWeakReferenceForExecSpecEditPolicy"; //$NON-NLS-1$ /** * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.eclipse.gef.Request) + * * @param request * @return + * + * * <img src="../../../../../../../../../icons/sequenceScheme.png" width="250" /> * <UL> * <LI>when move E --> move B on the coordinate Y of E and move A on the coordinate Y of E @@ -107,8 +110,8 @@ public class UpdateWeakReferenceForExecSpecEditPolicy extends UpdateWeakReferenc */ private Command getUpdateWeakRefForExecSpecCreate(final CreateViewAndElementRequest request) { Command command = null; - CreateViewAndElementRequest createRequest = request; - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "Execution Specification creation request at:" + ((IAdaptable) getHost()).getAdapter(View.class).getElement()); + CreateViewAndElementRequest createRequest = (CreateViewAndElementRequest) request; + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "Execution Specification creation request at:" + ((View) ((IAdaptable) getHost()).getAdapter(View.class)).getElement()); // Snap to grid Location createRequest.setLocation(SequenceUtil.getSnappedLocation(getHost(), createRequest.getLocation())); @@ -117,80 +120,79 @@ public class UpdateWeakReferenceForExecSpecEditPolicy extends UpdateWeakReferenc getHostFigure().translateToRelative(reqlocationOnScreen); UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "=> Request Location on screen: " + reqlocationOnScreen); - List<OccurrenceSpecification> nextEventsFromPosition = new ArrayList<>(); - List<OccurrenceSpecification> previousEventsFromPosition = new ArrayList<>(); + List<OccurrenceSpecification> nextEventsFromPosition = new ArrayList<OccurrenceSpecification>(); + List<OccurrenceSpecification> previousEventsFromPosition = new ArrayList<OccurrenceSpecification>(); // Get next and previous event from the lifeline source EditPart host = getHost(); if (host instanceof LifelineEditPart) { - nextEventsFromPosition.addAll(LifelineEditPartUtil.getNextEventsFromPosition(reqlocationOnScreen, (LifelineEditPart) host)); + nextEventsFromPosition.addAll(LifelineEditPartUtil.getNextEventsFromPosition(reqlocationOnScreen.getCopy().translate(0, GridManagementEditPolicy.threshold), (LifelineEditPart) host)); previousEventsFromPosition.addAll(LifelineEditPartUtil.getPreviousEventsFromPosition(new Point(reqlocationOnScreen.x, reqlocationOnScreen.y + deltaMoveAtCreationAndDeletion + AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT), (LifelineEditPart) host)); } + // get the list of element just below new created message + nextEventsFromPosition.retainAll(previousEventsFromPosition); + if (!nextEventsFromPosition.isEmpty()) { CompoundCommand compoundCommand = new CompoundCommand(); - // get the list of element just below new created message - nextEventsFromPosition.retainAll(previousEventsFromPosition); - - // For each next event below - for (OccurrenceSpecification nextEvent : nextEventsFromPosition) { - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\tNext Event: " + nextEvent); - - ArrayList<EditPart> senderList = SenderRequestUtils.getSenders(request); - - List<?> connectionsAndChildren = new ArrayList<>(); - connectionsAndChildren.addAll(((GraphicalEditPart) host).getSourceConnections()); - connectionsAndChildren.addAll(((GraphicalEditPart) host).getTargetConnections()); - connectionsAndChildren.addAll(((GraphicalEditPart) host).getChildren()); - - for (Object editPart : connectionsAndChildren) { - // move messages - if (editPart instanceof ConnectionEditPart) { - EObject message = ((View) ((AbstractMessageEditPart) editPart).getAdapter(View.class)).getElement(); - if (message instanceof Message && null != ((Message) message).getSendEvent() && ((Message) message).getSendEvent().equals(nextEvent) - || message instanceof Message && null != ((Message) message).getReceiveEvent() && ((Message) message).getReceiveEvent().equals(nextEvent)) { - - // compute Delta - Point moveDelta = new Point(0, 0); - PolylineConnectionEx polyline = (PolylineConnectionEx) ((ConnectionEditPart) editPart).getFigure(); - Point anchorPositionOnScreen; - if (((Message) message).getSendEvent().equals(nextEvent)) { - anchorPositionOnScreen = polyline.getTargetAnchor().getReferencePoint(); - } else { - anchorPositionOnScreen = polyline.getSourceAnchor().getReferencePoint(); - } - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tanchorPositionOnScreen:\t" + anchorPositionOnScreen); - - Point newLocation = new Point(0, createRequest.getLocation().y + AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT + deltaMoveAtCreationAndDeletion); - newLocation = SequenceUtil.getSnappedLocation(getHost(), newLocation); - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tNew location to be set:\t" + newLocation); - moveDelta.y = newLocation.y - anchorPositionOnScreen.y; - - // add move source and target request - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tMoveDela:\t\t" + moveDelta.y); - moveTargetConnectionEditPart(null, moveDelta, compoundCommand, (ConnectionEditPart) editPart, senderList); - moveSourceConnectionEditPart(null, moveDelta, compoundCommand, (ConnectionEditPart) editPart, senderList); + // only first element need to be moved, other will follow + OccurrenceSpecification nextEvent = nextEventsFromPosition.get(0); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\tNext Event: " + nextEvent); + + ArrayList<EditPart> senderList = SenderRequestUtils.getSenders(request); + + List<?> connectionsAndChildren = new ArrayList<>(); + connectionsAndChildren.addAll(((GraphicalEditPart) host).getSourceConnections()); + connectionsAndChildren.addAll(((GraphicalEditPart) host).getTargetConnections()); + connectionsAndChildren.addAll(((GraphicalEditPart) host).getChildren()); + + for (Object editPart : connectionsAndChildren) { + // move messages + if (editPart instanceof ConnectionEditPart) { + EObject message = ((View) ((AbstractMessageEditPart) editPart).getAdapter(View.class)).getElement(); + if (message instanceof Message && null != ((Message) message).getSendEvent() && ((Message) message).getSendEvent().equals(nextEvent) + || message instanceof Message && null != ((Message) message).getReceiveEvent() && ((Message) message).getReceiveEvent().equals(nextEvent)) { + + // compute Delta + Point moveDelta = new Point(0, 0); + PolylineConnectionEx polyline = (PolylineConnectionEx) ((ConnectionEditPart) editPart).getFigure(); + Point anchorPositionOnScreen; + if (((Message) message).getSendEvent().equals(nextEvent)) { + anchorPositionOnScreen = polyline.getTargetAnchor().getReferencePoint(); + } else { + anchorPositionOnScreen = polyline.getSourceAnchor().getReferencePoint(); } - } else - // move execution specification - if (editPart instanceof AbstractExecutionSpecificationEditPart) { - EObject element = ((View) ((AbstractExecutionSpecificationEditPart) editPart).getAdapter(View.class)).getElement(); - - if (element instanceof ExecutionSpecification && null != ((ExecutionSpecification) element).getStart() && ((ExecutionSpecification) element).getStart().equals(nextEvent)) { - // compute Delta - Point moveDelta = new Point(0, 0); - Point figureLocation = ((AbstractExecutionSpecificationEditPart) editPart).getFigure().getBounds().getLocation(); - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tlocationOfFigure:\t" + figureLocation); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tanchorPositionOnScreen:\t" + anchorPositionOnScreen); - Point newLocation = new Point(0, reqlocationOnScreen.y + AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT + deltaMoveAtCreationAndDeletion); - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tNew location to be set:\t" + newLocation); - moveDelta.y = newLocation.y - figureLocation.y; + Point newLocation = new Point(0, createRequest.getLocation().y + AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT + deltaMoveAtCreationAndDeletion); + newLocation = SequenceUtil.getSnappedLocation(getHost(), newLocation); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tNew location to be set:\t" + newLocation); + moveDelta.y = newLocation.y - anchorPositionOnScreen.y; - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tMoveDela:\t\t" + moveDelta.y); - moveRoundedEditPart(null, moveDelta, compoundCommand, (EditPart) editPart, senderList); - } - } + // add move source and target request + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tMoveDela:\t\t" + moveDelta.y); + moveTargetConnectionEditPart(null, moveDelta, compoundCommand, (ConnectionEditPart) editPart, senderList); + moveSourceConnectionEditPart(null, moveDelta, compoundCommand, (ConnectionEditPart) editPart, senderList); + } + } else + // move execution specification + if (editPart instanceof AbstractExecutionSpecificationEditPart) { + EObject element = ((View) ((AbstractExecutionSpecificationEditPart) editPart).getAdapter(View.class)).getElement(); + + if (element instanceof ExecutionSpecification && null != ((ExecutionSpecification) element).getStart() && ((ExecutionSpecification) element).getStart().equals(nextEvent)) { + // compute Delta + Point moveDelta = new Point(0, 0); + Point figureLocation = ((AbstractExecutionSpecificationEditPart) editPart).getFigure().getBounds().getLocation(); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tlocationOfFigure:\t" + figureLocation); + + Point newLocation = new Point(0, reqlocationOnScreen.y + AbstractExecutionSpecificationEditPart.DEFAUT_HEIGHT + deltaMoveAtCreationAndDeletion); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tNew location to be set:\t" + newLocation); + moveDelta.y = newLocation.y - figureLocation.y; + + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "\t\tMoveDela:\t\t" + moveDelta.y); + moveRoundedEditPart(null, moveDelta, compoundCommand, (EditPart) editPart, senderList); + } } } if (!compoundCommand.isEmpty()) { @@ -209,32 +211,32 @@ public class UpdateWeakReferenceForExecSpecEditPolicy extends UpdateWeakReferenc */ private Command getUpdateWeakRefForExecSpecResize(final ChangeBoundsRequest request) { CompoundCommand compoundCommand = new CompoundCommand(); - Point nextLocation = request.getLocation(); + Point nextLocation = ((ChangeBoundsRequest) request).getLocation(); UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "+ MOVE at " + nextLocation + " of " + getHost());//$NON-NLS-1$ //$NON-NLS-2$ Rectangle locationAndSize = new PrecisionRectangle(getHostFigure().getBounds()); Point moveDelta = new Point(0, 0); if (RequestConstants.REQ_MOVE.equals(request.getType())) { - moveDelta = request.getMoveDelta(); + moveDelta = ((ChangeBoundsRequest) request).getMoveDelta(); } else if (RequestConstants.REQ_RESIZE.equals(request.getType())) { - moveDelta = new Point(0, request.getSizeDelta().height + request.getMoveDelta().y); + moveDelta = new Point(0, ((ChangeBoundsRequest) request).getSizeDelta().height + ((ChangeBoundsRequest) request).getMoveDelta().y); } if (moveDelta.y != 0 && mustMove) { if (getHost() instanceof AbstractExecutionSpecificationEditPart) { getHostFigure().translateToAbsolute(locationAndSize); - locationAndSize = request.getTransformedRectangle(locationAndSize); + locationAndSize = ((ChangeBoundsRequest) request).getTransformedRectangle(locationAndSize); } if (getHost().getEditPolicy(SequenceReferenceEditPolicy.SEQUENCE_REFERENCE) != null) { SequenceReferenceEditPolicy references = (SequenceReferenceEditPolicy) getHost().getEditPolicy(SequenceReferenceEditPolicy.SEQUENCE_REFERENCE); if (!SenderRequestUtils.isASender(request, getHost())) { // Gets weak references - HashMap<EditPart, String> weakReferences = new HashMap<>(); + HashMap<EditPart, String> weakReferences = new HashMap<EditPart, String>(); if ((moveDelta.y > 0 && mustMoveBelowAtMovingDown) || (moveDelta.y < 0 && mustMoveBelowAtMovingUp)) { weakReferences.putAll(references.getWeakReferences()); } for (Iterator<EditPart> iterator = weakReferences.keySet().iterator(); iterator.hasNext();) { - EditPart editPart = iterator.next(); + EditPart editPart = (EditPart) iterator.next(); if (!SenderRequestUtils.isASender(request, editPart)) { UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "+--> try to Move of " + moveDelta.y + " " + editPart);//$NON-NLS-1$ ArrayList<EditPart> senderList = SenderRequestUtils.getSenders(request); @@ -273,7 +275,6 @@ public class UpdateWeakReferenceForExecSpecEditPolicy extends UpdateWeakReferenc Point moveDelta = new Point(0, -hostConnectionEditPart.getPrimaryShape().getBounds().height); if (moveDelta.y < 0) { - // get the edit policy of references if (hostConnectionEditPart.getEditPolicy(SequenceReferenceEditPolicy.SEQUENCE_REFERENCE) != null) { SequenceReferenceEditPolicy references = (SequenceReferenceEditPolicy) hostConnectionEditPart.getEditPolicy(SequenceReferenceEditPolicy.SEQUENCE_REFERENCE); @@ -281,12 +282,12 @@ public class UpdateWeakReferenceForExecSpecEditPolicy extends UpdateWeakReferenc CompoundCommand compoundCommand = new CompoundCommand(); // Gets weak references - HashMap<EditPart, String> weakReferences = new HashMap<>(); + HashMap<EditPart, String> weakReferences = new HashMap<EditPart, String>(); weakReferences.putAll(references.getWeakReferences()); // for each weak reference move it for (Iterator<EditPart> iterator = weakReferences.keySet().iterator(); iterator.hasNext();) { - EditPart editPart = iterator.next(); + EditPart editPart = (EditPart) iterator.next(); if (!SenderRequestUtils.isASender(request, editPart)) {// avoid loop UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG, "+--> try to Move " + editPart);//$NON-NLS-1$ ArrayList<EditPart> senderList = SenderRequestUtils.getSenders(request); @@ -310,5 +311,3 @@ public class UpdateWeakReferenceForExecSpecEditPolicy extends UpdateWeakReferenc return command; } } - - diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java index eefba57dc43..e802e340ab7 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/ConnectMessageToGridEditPolicy.java @@ -19,6 +19,7 @@ import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.edit.command.SetCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.EditPart; import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand; @@ -130,7 +131,7 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem getDiagramEventBroker().addNotificationListener(rowSource, this); } // target - if (targetAnchor.getId() != null && !(targetAnchor.getId().equals(""))) { + if (null != targetEditPart && targetAnchor.getId() != null && !(targetAnchor.getId().equals(""))) { Message m = (Message) connectionEditPart.resolveSemanticElement(); double absoluteY = computeAnchorPositionNotation(targetAnchor, targetEditPart); @@ -197,35 +198,37 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem if (sourceAnchor.getId() != null && !(sourceAnchor.getId().equals(""))) { ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); Message m = (Message) connectionEditPart.resolveSemanticElement(); - GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); - int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); + if (connectionEditPart.getSource() instanceof GraphicalEditPart) { + GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); + int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); - // Ensure that the target is always below the source - Edge edge = (Edge) connectionEditPart.getNotationView(); - IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); - GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); - if (null != targetEditpart && null != targetAnchor) { - int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); - if (targetAnchorY <= sourceAnchorY) { - sourceAnchorY = targetAnchorY - 1; + // Ensure that the target is always below the source + Edge edge = (Edge) connectionEditPart.getNotationView(); + IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); + EditPart targetEditpart = connectionEditPart.getTarget(); + if (targetEditpart instanceof GraphicalEditPart && null != targetAnchor) { + int targetAnchorY = computeAnchorPositionNotation(targetAnchor, (GraphicalEditPart) targetEditpart); + if (targetAnchorY <= sourceAnchorY) { + sourceAnchorY = targetAnchorY - 1; + } } - } - try { - GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRID_MANAGEMENT); - if (grilling != null) { - if (rowSource == null) { - if (m.getSendEvent() == null) { - rowSource = grilling.createRowTolisten(sourceAnchorY, m); - } else { - rowSource = grilling.createRowTolisten(sourceAnchorY, m.getSendEvent()); + try { + GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRID_MANAGEMENT); + if (grilling != null) { + if (rowSource == null) { + if (m.getSendEvent() == null) { + rowSource = grilling.createRowTolisten(sourceAnchorY, m); + } else { + rowSource = grilling.createRowTolisten(sourceAnchorY, m.getSendEvent()); + } } - } - getDiagramEventBroker().addNotificationListener(rowSource, this); + getDiagramEventBroker().addNotificationListener(rowSource, this); + } + } catch (NoGrillElementFound e) { + UMLDiagramEditorPlugin.log.error(e); } - } catch (NoGrillElementFound e) { - UMLDiagramEditorPlugin.log.error(e); } } } @@ -236,36 +239,38 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem IdentityAnchor targetAnchor = (IdentityAnchor) notification.getNewValue(); if (targetAnchor.getId() != null && !(targetAnchor.getId().equals(""))) { ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost(); - GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); - Message m = (Message) connectionEditPart.resolveSemanticElement(); - int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); + if (connectionEditPart.getTarget() instanceof GraphicalEditPart) { + GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); + Message m = (Message) connectionEditPart.resolveSemanticElement(); + int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); - // Ensure that the target is always below the source - Edge edge = (Edge) connectionEditPart.getNotationView(); - IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); - GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); - if (null != sourceEditpart && null != sourceAnchor) { - int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); - if (targetAnchorY <= sourceAnchorY) { - targetAnchorY = sourceAnchorY + 1; + // Ensure that the target is always below the source + Edge edge = (Edge) connectionEditPart.getNotationView(); + IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); + EditPart sourceEditpart = connectionEditPart.getSource(); + if (sourceEditpart instanceof GraphicalEditPart && null != sourceAnchor) { + int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, (GraphicalEditPart) sourceEditpart); + if (targetAnchorY <= sourceAnchorY) { + targetAnchorY = sourceAnchorY + 1; + } } - } - try { - GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRID_MANAGEMENT); - if (grilling != null) { - if (rowTarget == null) { - if (m.getReceiveEvent() == null) { - rowTarget = grilling.createRowTolisten(targetAnchorY, m); - } else { - rowTarget = grilling.createRowTolisten(targetAnchorY, m.getReceiveEvent()); + try { + GridManagementEditPolicy grilling = (GridManagementEditPolicy) diagramEditPart.getEditPolicy(GridManagementEditPolicy.GRID_MANAGEMENT); + if (grilling != null) { + if (rowTarget == null) { + if (m.getReceiveEvent() == null) { + rowTarget = grilling.createRowTolisten(targetAnchorY, m); + } else { + rowTarget = grilling.createRowTolisten(targetAnchorY, m.getReceiveEvent()); + } } + getDiagramEventBroker().addNotificationListener(rowTarget, this); } - getDiagramEventBroker().addNotificationListener(rowTarget, this); + } catch (NoGrillElementFound e) { + UMLDiagramEditorPlugin.log.error(e); } - } catch (NoGrillElementFound e) { - UMLDiagramEditorPlugin.log.error(e); } } } @@ -275,23 +280,24 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem Edge edge = (Edge) connectionEditPart.getNotationView(); if (edge.getSourceAnchor() != null && rowSource != null) { IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); - GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); - int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); + if (connectionEditPart.getSource() instanceof GraphicalEditPart) { + GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); + int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); - // Ensure that the target is always below the source - IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); - GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); - if (null != targetEditpart && null != targetAnchor) { - int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); - if (targetAnchorY <= sourceAnchorY) { - sourceAnchorY = targetAnchorY - 1; + // Ensure that the target is always below the source + IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); + EditPart targetEditpart = connectionEditPart.getTarget(); + if (targetEditpart instanceof GraphicalEditPart && null != targetAnchor) { + int targetAnchorY = computeAnchorPositionNotation(targetAnchor, (GraphicalEditPart) targetEditpart); + if (targetAnchorY <= sourceAnchorY) { + sourceAnchorY = targetAnchorY - 1; + } } - } - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+--> SOURCE change for " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + sourceAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - updatePositionGridAxis((DecorationNode) rowSource, 0, sourceAnchorY); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+--> SOURCE change for " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + sourceAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + updatePositionGridAxis((DecorationNode) rowSource, 0, sourceAnchorY); + } } - } if (notification.getEventType() == Notification.SET && notification.getFeature().equals(NotationPackage.eINSTANCE.getEdge_Target())) { @@ -300,21 +306,23 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem Edge edge = (Edge) connectionEditPart.getNotationView(); if (edge.getTargetAnchor() != null && rowTarget != null) { IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); - GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); - int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); + if (connectionEditPart.getTarget() instanceof GraphicalEditPart) { + GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); + int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); - // Ensure that the target is always below the source - IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); - GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); - if (null != sourceEditpart && null != sourceAnchor) { - int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); - if (targetAnchorY <= sourceAnchorY) { - targetAnchorY = sourceAnchorY + 1; + // Ensure that the target is always below the source + IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); + EditPart sourceEditpart = connectionEditPart.getSource(); + if (sourceEditpart instanceof GraphicalEditPart && null != sourceAnchor) { + int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, (GraphicalEditPart) sourceEditpart); + if (targetAnchorY <= sourceAnchorY) { + targetAnchorY = sourceAnchorY + 1; + } } - } - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+--> SOURCE change for " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + targetAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - updatePositionGridAxis((DecorationNode) rowTarget, 0, targetAnchorY); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+--> SOURCE change for " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + targetAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + updatePositionGridAxis((DecorationNode) rowTarget, 0, targetAnchorY); + } } } @@ -326,39 +334,43 @@ public class ConnectMessageToGridEditPolicy extends GraphicalEditPolicyEx implem Edge edge = (Edge) connectionEditPart.getNotationView(); if (notification.getNotifier().equals(edge.getSourceAnchor()) && rowSource != null) { IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); - GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); - int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); + if (connectionEditPart.getSource() instanceof GraphicalEditPart) { + GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); + int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); - // Ensure that the target is always below the source - IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); - GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); - if (null != targetEditpart && null != targetAnchor) { - int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); - if (targetAnchorY <= sourceAnchorY) { - sourceAnchorY = targetAnchorY - 1; + // Ensure that the target is always below the source + IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); + EditPart targetEditpart = connectionEditPart.getTarget(); + if (targetEditpart instanceof GraphicalEditPart && null != targetAnchor) { + int targetAnchorY = computeAnchorPositionNotation(targetAnchor, (GraphicalEditPart) targetEditpart); + if (targetAnchorY <= sourceAnchorY) { + sourceAnchorY = targetAnchorY - 1; + } } - } - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+--> SOURCE change for " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + sourceAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - updatePositionGridAxis((DecorationNode) rowSource, 0, sourceAnchorY); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+--> SOURCE change for " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + sourceAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + updatePositionGridAxis((DecorationNode) rowSource, 0, sourceAnchorY); + } } if (notification.getNotifier().equals(edge.getTargetAnchor()) && rowTarget != null) { - GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); - IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); - int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); + if (connectionEditPart.getTarget() instanceof GraphicalEditPart) { + GraphicalEditPart targetEditpart = (GraphicalEditPart) connectionEditPart.getTarget(); + IdentityAnchor targetAnchor = (IdentityAnchor) edge.getTargetAnchor(); + int targetAnchorY = computeAnchorPositionNotation(targetAnchor, targetEditpart); - // Ensure that the target is always below the source - IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); - GraphicalEditPart sourceEditpart = (GraphicalEditPart) connectionEditPart.getSource(); - if (null != sourceEditpart && null != sourceAnchor) { - int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, sourceEditpart); - if (targetAnchorY <= sourceAnchorY) { - targetAnchorY = sourceAnchorY + 1; + // Ensure that the target is always below the source + IdentityAnchor sourceAnchor = (IdentityAnchor) edge.getSourceAnchor(); + EditPart sourceEditpart = connectionEditPart.getSource(); + if (sourceEditpart instanceof GraphicalEditPart && null != sourceAnchor) { + int sourceAnchorY = computeAnchorPositionNotation(sourceAnchor, (GraphicalEditPart) sourceEditpart); + if (targetAnchorY <= sourceAnchorY) { + targetAnchorY = sourceAnchorY + 1; + } } - } - UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+-->TARGET change " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + targetAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - updatePositionGridAxis((DecorationNode) rowTarget, 0, targetAnchorY); + UMLDiagramEditorPlugin.log.trace(LogOptions.SEQUENCE_DEBUG_REFERENCEGRID, "+-->TARGET change " + ((NamedElement) connectionEditPart.resolveSemanticElement()).getName() + " to " + targetAnchorY + " ");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + updatePositionGridAxis((DecorationNode) rowTarget, 0, targetAnchorY); + } } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java index 70a8dd2aeb1..a459e048731 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/GridManagementEditPolicy.java @@ -70,7 +70,7 @@ public class GridManagementEditPolicy extends GraphicalEditPolicyEx implements A public static String COLUMN = "COLUMN_"; //$NON-NLS-1$ public static String ROW = "ROW_"; //$NON-NLS-1$ - public int threshold = 5; + public static int threshold = 5; /** * @return the threshold diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java index c3256ec48c0..2919ae9914d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/referencialgrilling/LifeLineGraphicalNodeEditPolicy.java @@ -131,6 +131,9 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol if (location != displayEvent.getRealEventLocation(location)) { request.setLocation(displayEvent.getRealEventLocation(location)); } + } else if (os instanceof MessageEnd) { + // Event of Exec Spec have been already replaced. Only one message can be related to start or finish. + return UnexecutableCommand.INSTANCE; } return super.getConnectionCreateCommand(request); @@ -383,8 +386,8 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol request.setExtendedData(extendedData); } // add a param if we must replace an event of the execution specification - OccurrenceSpecification os = displayEvent.getActionExecutionSpecificationEvent(getHostFigure().getParent().getParent(), ((CreateRequest) request).getLocation()); - if (os != null) { + OccurrenceSpecification os = displayEvent.getActionExecutionSpecificationEvent(null, ((CreateRequest) request).getLocation()); + if (os instanceof ExecutionOccurrenceSpecification) { Map<String, Object> extendedData = request.getExtendedData(); extendedData.put(org.eclipse.papyrus.uml.service.types.utils.SequenceRequestConstant.MESSAGE_RECEIVEEVENT_REPLACE_EXECUTIONEVENT, os); request.setExtendedData(extendedData); @@ -600,6 +603,7 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol */ private boolean isAllowedMessageEnd(CreateConnectionViewAndElementRequest request) { Boolean allowed = true; + // check if target is lower than source if (!precisionMode) { Point targetLocation = request.getLocation(); Map<String, Object> extendedData = request.getExtendedData(); @@ -608,6 +612,11 @@ public class LifeLineGraphicalNodeEditPolicy extends DefaultGraphicalNodeEditPol allowed &= isTargetLowerThanSource(SequenceUtil.getSnappedLocation(getHost(), (Point) sourceLocation), targetLocation); } } + + // Check if we are in a execution event, and if the event have been already be replaced, we can't allow it. + OccurrenceSpecification os = displayEvent.getActionExecutionSpecificationEvent(null, ((CreateRequest) request).getLocation()); + allowed &= !(null != os && !(os instanceof ExecutionOccurrenceSpecification)); + return allowed; } |