diff options
author | Pauline DEVILLE | 2017-07-26 12:37:20 +0000 |
---|---|---|
committer | Jeremie Tatibouet | 2017-09-01 11:51:33 +0000 |
commit | dbed75841f555b94d00e960fb95894342cb61df5 (patch) | |
tree | ad0c7e39eb928231c2a7aef91bf18bce3f73774a | |
parent | c23cc77868bd36203e0bb2618d5fbe8570fc74f2 (diff) | |
download | org.eclipse.papyrus-dbed75841f555b94d00e960fb95894342cb61df5.tar.gz org.eclipse.papyrus-dbed75841f555b94d00e960fb95894342cb61df5.tar.xz org.eclipse.papyrus-dbed75841f555b94d00e960fb95894342cb61df5.zip |
Bug 405580 - [Activity] ActivityEdges are always created under the
activity without consideration of its source and target elements.
Change-Id: Ie3d840f5c9bde4a7e0c0768c4a7a88a93a7c7a44
Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
10 files changed, 310 insertions, 149 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/commands/ActivityEdgeReparentCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/commands/ActivityEdgeReparentCommand.java new file mode 100644 index 00000000000..af105953f83 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/commands/ActivityEdgeReparentCommand.java @@ -0,0 +1,80 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST 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: + * Pauline DEVILLE (CEA LIST) - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.activity.commands; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.papyrus.uml.tools.utils.ActivityEdgeUtil; +import org.eclipse.uml2.uml.Activity; +import org.eclipse.uml2.uml.ActivityEdge; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.StructuredActivityNode; + +/** + * Customized ActivityEdge reparent command, takes changing of container into account. + */ +public class ActivityEdgeReparentCommand extends AbstractTransactionalCommand { + + private ActivityEdge edge; + + /** + * Constructor. + * + * @param domain + * @param edge + */ + public ActivityEdgeReparentCommand(TransactionalEditingDomain domain, ActivityEdge edge) { + super(domain, "ActivityEdge reparent command", null); //$NON-NLS-1$ + this.edge = edge; + } + + /** + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + * + * @param monitor + * @param info + * @return + * @throws ExecutionException + */ + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + changeContainer(edge); + return CommandResult.newOKCommandResult(); + } + + /** + * change the container of an edge, if necessary + * + * @param edge + */ + private boolean changeContainer(ActivityEdge edge) { + Element proposedContainer = ActivityEdgeUtil.deduceContainer(edge.getSource(), edge.getTarget()); + if (proposedContainer == null) { + return false; // edge is not valid + } + if (proposedContainer != edge.getOwner()) { + if (proposedContainer instanceof Activity) { + ((Activity) proposedContainer).getEdges().add(edge); // will remove edge automatically from original container + } else if (proposedContainer instanceof StructuredActivityNode) { + ((StructuredActivityNode) proposedContainer).getEdges().add(edge); + } + } + return true; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityCompartmentCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityCompartmentCreationEditPolicy.java index 7deefb539ef..a92e4a4ddd8 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityCompartmentCreationEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/ActivityCompartmentCreationEditPolicy.java @@ -26,57 +26,87 @@ import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper; import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEditPolicy; +import org.eclipse.papyrus.uml.diagram.activity.commands.ActivityEdgeReparentCommand; import org.eclipse.papyrus.uml.service.types.helper.ActivityNodeHelper; +import org.eclipse.uml2.uml.ActivityEdge; +import org.eclipse.uml2.uml.ActivityNode; import org.eclipse.uml2.uml.ActivityPartition; +import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.InterruptibleActivityRegion; +import org.eclipse.uml2.uml.Pin; /** - * Class provide extended reparent command in case drag&drop from ActivityPartition - * or InterruptibleActivityRegion + * Class provide extended reparent command in case of: + * - drag&drop from ActivityPartition or InterruptibleActivityRegion + * - drag&drop of an ActivityEdge (reparent according to its new container) */ -public class ActivityCompartmentCreationEditPolicy extends DefaultCreationEditPolicy{ +public class ActivityCompartmentCreationEditPolicy extends DefaultCreationEditPolicy { /** * Set in moveRequest additional parameters then reparent from ActivityPartition * or InterruptibleActivityRegion + * Reparent ActivityEdge if necessary */ @Override protected ICommand getReparentCommand(IGraphicalEditPart gep) { - CompositeCommand cc = new CompositeCommand(DiagramUIMessages.AddCommand_Label); - View container = (View)getHost().getModel(); + CompositeCommand cc = new CompositeCommand(DiagramUIMessages.AddCommand_Label); + View container = (View) getHost().getModel(); EObject context = ViewUtil.resolveSemanticElement(container); - View view = (View)gep.getModel(); + View view = (View) gep.getModel(); EObject element = ViewUtil.resolveSemanticElement(view); TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()) .getEditingDomain(); // semantic - if ( element != null ) { + if (element != null) { + // Set in moveRequest additional parameters then reparent from ActivityPartition + // or InterruptibleActivityRegion MoveRequest req = new MoveRequest(editingDomain, context, element); - EObject currentParentSemantic = ((IGraphicalEditPart)gep.getParent()).resolveSemanticElement(); + EObject currentParentSemantic = ((IGraphicalEditPart) gep.getParent()).resolveSemanticElement(); if (currentParentSemantic instanceof ActivityPartition) { req.setParameter(ActivityNodeHelper.OUT_FROM_PARTITION, currentParentSemantic); } if (currentParentSemantic instanceof InterruptibleActivityRegion) { req.setParameter(ActivityNodeHelper.OUT_FROM_INTERRUPTIBLE_REGION, currentParentSemantic); } - Command moveSemanticCmd = - getHost().getCommand( - new EditCommandRequestWrapper(req)); + Command moveSemanticCmd = getHost().getCommand(new EditCommandRequestWrapper(req)); - if (moveSemanticCmd == null) { return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE; } - - cc.compose ( new CommandProxy(moveSemanticCmd) ); + + cc.compose(new CommandProxy(moveSemanticCmd)); + + // Reparent ActivityEdge if necessary + if (context != null && shouldReparent(element, context)) { + if (element instanceof ActivityNode) { + ActivityNode activityNode = (ActivityNode) element; + // correct container of ControlFlow + for (ActivityEdge edge : activityNode.getOutgoings()) { + cc.compose(new ActivityEdgeReparentCommand(editingDomain, edge)); + } + for (ActivityEdge edge : activityNode.getIncomings()) { + cc.compose(new ActivityEdgeReparentCommand(editingDomain, edge)); + } + // correct container of ObjectFlow + for (Element ownedElement : activityNode.getOwnedElements()) { + if (ownedElement instanceof Pin) { + for (ActivityEdge edge : ((Pin) ownedElement).getOutgoings()) { + cc.compose(new ActivityEdgeReparentCommand(editingDomain, edge)); + } + for (ActivityEdge edge : ((Pin) ownedElement).getIncomings()) { + cc.compose(new ActivityEdgeReparentCommand(editingDomain, edge)); + } + } + } + } + } } - // + // notation cc.compose(getReparentViewCommand(gep)); return cc; } - } diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ControlFlowReorientCommand.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ControlFlowReorientCommand.java index 49a7d777c31..e4a0f5e8dec 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ControlFlowReorientCommand.java +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ControlFlowReorientCommand.java @@ -21,9 +21,12 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
+import org.eclipse.papyrus.uml.tools.utils.ControlFlowUtil;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ControlFlow;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.StructuredActivityNode;
/**
* <pre>
@@ -39,11 +42,10 @@ public class ControlFlowReorientCommand extends EditElementCommand { protected final EObject newEnd;
/**
- * <pre>
* Constructor.
*
- * @param request the re-orient relationship request.
- * </pre>
+ * @param request
+ * the re-orient relationship request.
*/
public ControlFlowReorientCommand(ReorientRelationshipRequest request) {
super(request.getLabel(), request.getRelationship(), request);
@@ -53,53 +55,51 @@ public class ControlFlowReorientCommand extends EditElementCommand { }
/**
- * <pre>
* @see org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand#canExecute()
*
* @return true if the command is executable.
- * </pre>
*/
public boolean canExecute() {
- if(false == getElementToEdit() instanceof ControlFlow) {
+ if (false == getElementToEdit() instanceof ControlFlow) {
return false;
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
return canReorientSource();
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
return canReorientTarget();
}
return false;
}
protected boolean canReorientSource() {
- if(!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
+ if (!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
return false;
}
- if(!(getLink().eContainer() instanceof Activity)) {
+ if (!(getLink().eContainer() instanceof Activity) && !(getLink().eContainer() instanceof StructuredActivityNode)) {
return false;
}
- return true;
+ return ControlFlowUtil.canExistControlFlow((Element) getLink().eContainer(), getLink(), getNewSource(), getOldTarget());
}
protected boolean canReorientTarget() {
- if(!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
+ if (!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
return false;
}
- if(!(getLink().eContainer() instanceof Activity)) {
+ if (!(getLink().eContainer() instanceof Activity) && !(getLink().eContainer() instanceof StructuredActivityNode)) {
return false;
}
- return true;
+ return ControlFlowUtil.canExistControlFlow((Element) getLink().eContainer(), getLink(), getOldSource(), getNewTarget());
}
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- if(!canExecute()) {
+ if (!canExecute()) {
throw new ExecutionException("Invalid arguments in reorient link command"); //$NON-NLS-1$
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
return reorientSource();
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
return reorientTarget();
}
throw new IllegalStateException();
@@ -116,22 +116,22 @@ public class ControlFlowReorientCommand extends EditElementCommand { }
protected ControlFlow getLink() {
- return (ControlFlow)getElementToEdit();
+ return (ControlFlow) getElementToEdit();
}
protected ActivityNode getOldSource() {
- return (ActivityNode)oldEnd;
+ return (ActivityNode) oldEnd;
}
protected ActivityNode getNewSource() {
- return (ActivityNode)newEnd;
+ return (ActivityNode) newEnd;
}
protected ActivityNode getOldTarget() {
- return (ActivityNode)oldEnd;
+ return (ActivityNode) oldEnd;
}
protected ActivityNode getNewTarget() {
- return (ActivityNode)newEnd;
+ return (ActivityNode) newEnd;
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ObjectFlowReorientCommand.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ObjectFlowReorientCommand.java index f90be80b1a5..b886bd7ada9 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ObjectFlowReorientCommand.java +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/ObjectFlowReorientCommand.java @@ -25,7 +25,9 @@ import org.eclipse.papyrus.uml.tools.utils.ObjectFlowUtil; import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ControlFlow;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ObjectFlow;
+import org.eclipse.uml2.uml.StructuredActivityNode;
/**
* <pre>
@@ -41,11 +43,10 @@ public class ObjectFlowReorientCommand extends EditElementCommand { protected final EObject newEnd;
/**
- * <pre>
* Constructor.
*
- * @param request the re-orient relationship request.
- * </pre>
+ * @param request
+ * the re-orient relationship request.
*/
public ObjectFlowReorientCommand(ReorientRelationshipRequest request) {
super(request.getLabel(), request.getRelationship(), request);
@@ -55,53 +56,51 @@ public class ObjectFlowReorientCommand extends EditElementCommand { }
/**
- * <pre>
* @see org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand#canExecute()
*
* @return true if the command is executable.
- * </pre>
*/
public boolean canExecute() {
- if(false == getElementToEdit() instanceof ObjectFlow) {
+ if (false == getElementToEdit() instanceof ObjectFlow) {
return false;
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
return canReorientSource();
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
return canReorientTarget();
}
return false;
}
protected boolean canReorientSource() {
- if(!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
+ if (!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
return false;
}
- if(!(getLink().eContainer() instanceof Activity)) {
+ if (!(getLink().eContainer() instanceof Activity) && !(getLink().eContainer() instanceof StructuredActivityNode)) {
return false;
}
- return ObjectFlowUtil.canExistObjectFlow((Activity)getLink().eContainer(), getLink(), getNewSource(), getLink().getTarget());
+ return ObjectFlowUtil.canExistObjectFlow((Element) getLink().eContainer(), getLink(), getNewSource(), getLink().getTarget());
}
protected boolean canReorientTarget() {
- if(!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
+ if (!(oldEnd instanceof ActivityNode && newEnd instanceof ActivityNode)) {
return false;
}
- if(!(getLink().eContainer() instanceof Activity)) {
+ if (!(getLink().eContainer() instanceof Activity) && !(getLink().eContainer() instanceof StructuredActivityNode)) {
return false;
}
- return ObjectFlowUtil.canExistObjectFlow((Activity)getLink().eContainer(), getLink(), getLink().getSource(), getNewTarget());
+ return ObjectFlowUtil.canExistObjectFlow((Element) getLink().eContainer(), getLink(), getLink().getSource(), getNewTarget());
}
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- if(!canExecute()) {
+ if (!canExecute()) {
throw new ExecutionException("Invalid arguments in reorient link command"); //$NON-NLS-1$
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
return reorientSource();
}
- if(reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
+ if (reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
return reorientTarget();
}
throw new IllegalStateException();
@@ -118,23 +117,23 @@ public class ObjectFlowReorientCommand extends EditElementCommand { }
protected ObjectFlow getLink() {
- return (ObjectFlow)getElementToEdit();
+ return (ObjectFlow) getElementToEdit();
}
protected ActivityNode getOldSource() {
- return (ActivityNode)oldEnd;
+ return (ActivityNode) oldEnd;
}
protected ActivityNode getNewSource() {
- return (ActivityNode)newEnd;
+ return (ActivityNode) newEnd;
}
protected ActivityNode getOldTarget() {
- return (ActivityNode)oldEnd;
+ return (ActivityNode) oldEnd;
}
protected ActivityNode getNewTarget() {
- return (ActivityNode)newEnd;
+ return (ActivityNode) newEnd;
}
-
+
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ControlFlowEditHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ControlFlowEditHelper.java index 5a8a21b5db7..ada300d207f 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ControlFlowEditHelper.java +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ControlFlowEditHelper.java @@ -30,10 +30,11 @@ import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipReques import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.service.types.command.ControlFlowReorientCommand;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
+import org.eclipse.papyrus.uml.tools.utils.ActivityEdgeUtil;
import org.eclipse.papyrus.uml.tools.utils.ControlFlowUtil;
-import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ControlFlow;
+import org.eclipse.uml2.uml.Element;
/**
* Edit helper class for binary {@link ControlFlow}
@@ -52,17 +53,17 @@ public class ControlFlowEditHelper extends ElementEditHelper { * Test if the relationship creation is allowed.
*
* @param source
- * the relationship source can be null
+ * the relationship source can be null
* @param target
- * the relationship target can be null
+ * the relationship target can be null
* @param sourceView
- * the relationship graphical source can be null
+ * the relationship graphical source can be null
* @param targetView
- * the relationship graphical target can be null
+ * the relationship graphical target can be null
* @return true if the creation is allowed
*/
protected boolean canCreate(EObject source, EObject target, View sourceView, View targetView) {
- return canCreate(source, target);
+ return canCreate(source, target);
}
/**
@@ -76,24 +77,24 @@ public class ControlFlowEditHelper extends ElementEditHelper { boolean noSourceOrTarget = (source == null || target == null);
boolean noSourceAndTarget = (source == null && target == null);
- if(!noSourceAndTarget && !canCreate(source, target, RequestParameterUtils.getSourceView(req), RequestParameterUtils.getTargetView(req))) {
+ if (!noSourceAndTarget && !canCreate(source, target, RequestParameterUtils.getSourceView(req), RequestParameterUtils.getTargetView(req))) {
// Abort creation.
return UnexecutableCommand.INSTANCE;
}
- if(noSourceOrTarget && !noSourceAndTarget) {
+ if (noSourceOrTarget && !noSourceAndTarget) {
// The request isn't complete yet. Return the identity command so
// that the create relationship gesture is enabled.
// this can be before first creation => check the source
- if(source != null && !(source instanceof ActivityNode)) {
+ if (source != null && !(source instanceof ActivityNode)) {
return UnexecutableCommand.INSTANCE;
}
return IdentityCommand.INSTANCE;
}
// Propose a semantic container for the new control flow.
- Activity proposedContainer = deduceContainer(req);
- if(proposedContainer == null) {
+ Element proposedContainer = deduceContainer(req);
+ if (proposedContainer == null) {
return UnexecutableCommand.INSTANCE;
}
@@ -101,26 +102,9 @@ public class ControlFlowEditHelper extends ElementEditHelper { return new CreateRelationshipCommand(req);
}
-
- protected Activity deduceContainer(CreateRelationshipRequest request) {
- return deduceContainer(request.getSource(), request.getTarget());
- }
-
- /**
- * @param source
- * @param target
- * @return
- */
- private Activity deduceContainer(EObject source, EObject target) {
- // Find container element for the new link.
- // Climb up by containment hierarchy starting from the source
- // and return the first element that is instance of the container class.
- for(EObject element = source; element != null; element = element.eContainer()) {
- if(element instanceof Activity) {
- return (Activity)element;
- }
- }
- return null;
+
+ protected Element deduceContainer(CreateRelationshipRequest request) {
+ return ActivityEdgeUtil.deduceContainer(request.getSource(), request.getTarget());
}
/**
@@ -133,13 +117,13 @@ public class ControlFlowEditHelper extends ElementEditHelper { protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- ControlFlow element = (ControlFlow)req.getElementToConfigure();
+ ControlFlow element = (ControlFlow) req.getElementToConfigure();
ActivityNode source = getSourceObject(req);
ActivityNode target = getTargetObject(req);
- if(source !=null) {
+ if (source != null) {
element.setSource(getSourceObject(req));
}
- if(target !=null) {
+ if (target != null) {
element.setTarget(target);
}
@@ -149,7 +133,7 @@ public class ControlFlowEditHelper extends ElementEditHelper { return CompositeCommand.compose(configureCommand, super.getConfigureCommand(req));
}
-
+
/**
* This method provides the object to be use as source.
@@ -158,7 +142,7 @@ public class ControlFlowEditHelper extends ElementEditHelper { */
protected ActivityNode getSourceObject(ConfigureRequest req) {
Object result = req.getParameter(CreateRelationshipRequest.SOURCE);
- return ( result instanceof ActivityNode) ? (ActivityNode)result : null;
+ return (result instanceof ActivityNode) ? (ActivityNode) result : null;
}
/**
@@ -168,26 +152,26 @@ public class ControlFlowEditHelper extends ElementEditHelper { */
protected ActivityNode getTargetObject(ConfigureRequest req) {
Object result = req.getParameter(CreateRelationshipRequest.TARGET);
- return ( result instanceof ActivityNode) ? (ActivityNode)result : null;
+ return (result instanceof ActivityNode) ? (ActivityNode) result : null;
}
/**
* {@inheritDoc}
*/
protected boolean canCreate(EObject source, EObject target) {
- if((source != null) && !(source instanceof ActivityNode)) {
+ if ((source != null) && !(source instanceof ActivityNode)) {
return false;
}
- if((target != null) && !(target instanceof ActivityNode)) {
+ if ((target != null) && !(target instanceof ActivityNode)) {
return false;
}
-
- Activity container = deduceContainer(source, target);
- if(container == null) {
+
+ Element container = ActivityEdgeUtil.deduceContainer(source, target);
+ if (container == null) {
return false;
}
- return ControlFlowUtil.canExistControlFlow(container, null, (ActivityNode)source, (ActivityNode)target);
+ return ControlFlowUtil.canExistControlFlow(container, null, (ActivityNode) source, (ActivityNode) target);
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ObjectFlowEditHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ObjectFlowEditHelper.java index 5f3b4562c4a..15d936b2e7e 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ObjectFlowEditHelper.java +++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ObjectFlowEditHelper.java @@ -30,9 +30,10 @@ import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipReques import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.service.types.command.ObjectFlowReorientCommand;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
+import org.eclipse.papyrus.uml.tools.utils.ActivityEdgeUtil;
import org.eclipse.papyrus.uml.tools.utils.ObjectFlowUtil;
-import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityNode;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ObjectFlow;
/**
@@ -52,13 +53,13 @@ public class ObjectFlowEditHelper extends ElementEditHelper { * Test if the relationship creation is allowed.
*
* @param source
- * the relationship source can be null
+ * the relationship source can be null
* @param target
- * the relationship target can be null
+ * the relationship target can be null
* @param sourceView
- * the relationship graphical source can be null
+ * the relationship graphical source can be null
* @param targetView
- * the relationship graphical target can be null
+ * the relationship graphical target can be null
* @return true if the creation is allowed
*/
protected boolean canCreate(EObject source, EObject target, View sourceView, View targetView) {
@@ -74,41 +75,29 @@ public class ObjectFlowEditHelper extends ElementEditHelper { EObject target = req.getTarget();
boolean noSourceOrTarget = (source == null || target == null);
boolean noSourceAndTarget = (source == null && target == null);
- if(!noSourceAndTarget && !canCreate(source, target, RequestParameterUtils.getSourceView(req), RequestParameterUtils.getTargetView(req))) {
+ if (!noSourceAndTarget && !canCreate(source, target, RequestParameterUtils.getSourceView(req), RequestParameterUtils.getTargetView(req))) {
// Abort creation.
return UnexecutableCommand.INSTANCE;
}
- if(noSourceOrTarget && !noSourceAndTarget) {
+ if (noSourceOrTarget && !noSourceAndTarget) {
// The request isn't complete yet. Return the identity command so
// that the create relationship gesture is enabled.
- if(source != null && !(source instanceof ActivityNode)) {
+ if (source != null && !(source instanceof ActivityNode)) {
return UnexecutableCommand.INSTANCE;
}
return IdentityCommand.INSTANCE;
}
// Propose a semantic container for the new control flow.
- Activity proposedContainer = deduceContainer(req);
- if(proposedContainer == null) {
+ Element proposedContainer = deduceContainer(req);
+ if (proposedContainer == null) {
return UnexecutableCommand.INSTANCE;
}
req.setContainer(proposedContainer);
return new CreateRelationshipCommand(req);
}
- protected Activity deduceContainer(CreateRelationshipRequest request) {
- return deduceContainer(request.getSource(), request.getTarget());
- }
-
- protected Activity deduceContainer(EObject source, EObject target) {
- // Find container element for the new link.
- // Climb up by containment hierarchy starting from the source
- // and return the first element that is instance of the container class.
- for(EObject element = source; element != null; element = element.eContainer()) {
- if(element instanceof Activity) {
- return (Activity)element;
- }
- }
- return null;
+ protected Element deduceContainer(CreateRelationshipRequest request) {
+ return ActivityEdgeUtil.deduceContainer(request.getSource(), request.getTarget());
}
/**
@@ -119,13 +108,13 @@ public class ObjectFlowEditHelper extends ElementEditHelper { ICommand configureCommand = new ConfigureElementCommand(req) {
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- ObjectFlow element = (ObjectFlow)req.getElementToConfigure();
+ ObjectFlow element = (ObjectFlow) req.getElementToConfigure();
ActivityNode source = getSourceObject(req);
ActivityNode target = getTargetObject(req);
- if(source != null) {
+ if (source != null) {
element.setSource(getSourceObject(req));
}
- if(target != null) {
+ if (target != null) {
element.setTarget(target);
}
return CommandResult.newOKCommandResult(element);
@@ -141,7 +130,7 @@ public class ObjectFlowEditHelper extends ElementEditHelper { */
protected ActivityNode getSourceObject(ConfigureRequest req) {
Object result = req.getParameter(CreateRelationshipRequest.SOURCE);
- return (result instanceof ActivityNode) ? (ActivityNode)result : null;
+ return (result instanceof ActivityNode) ? (ActivityNode) result : null;
}
/**
@@ -151,24 +140,24 @@ public class ObjectFlowEditHelper extends ElementEditHelper { */
protected ActivityNode getTargetObject(ConfigureRequest req) {
Object result = req.getParameter(CreateRelationshipRequest.TARGET);
- return (result instanceof ActivityNode) ? (ActivityNode)result : null;
+ return (result instanceof ActivityNode) ? (ActivityNode) result : null;
}
/**
* {@inheritDoc}
*/
protected boolean canCreate(EObject source, EObject target) {
- if((source != null) && !(source instanceof ActivityNode)) {
+ if ((source != null) && !(source instanceof ActivityNode)) {
return false;
}
- if((target != null) && !(target instanceof ActivityNode)) {
+ if ((target != null) && !(target instanceof ActivityNode)) {
return false;
}
-
- Activity container = deduceContainer(source, target);
- if(container == null) {
+
+ Element container = ActivityEdgeUtil.deduceContainer(source, target);
+ if (container == null) {
return false;
}
- return ObjectFlowUtil.canExistObjectFlow(container, null, (ActivityNode)source, (ActivityNode)target);
+ return ObjectFlowUtil.canExistObjectFlow(container, null, (ActivityNode) source, (ActivityNode) target);
}
}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ActivityEdgeUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ActivityEdgeUtil.java new file mode 100644 index 00000000000..9065a91021b --- /dev/null +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ActivityEdgeUtil.java @@ -0,0 +1,48 @@ +/***************************************************************************** + * Copyright (c) 2017 CEA LIST 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: + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.tools.utils; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.uml2.uml.Activity; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.StructuredActivityNode; + +public class ActivityEdgeUtil { + + + /** + * Deduce the container of the ActivityEgde + * The first StructuredActivityNode or the first Activity (16.14.55.6 in [UML 2.5]) + * + * @param source + * @param target + * @return the deduce container + */ + public static Element deduceContainer(EObject source, EObject target) { + // Find container element for the new link. + // Climb up by containment hierarchy starting from the source + // and return the first element that is instance of the container class. + for (EObject element = source; element != null; element = element.eContainer()) { + if (element instanceof Activity) { + return (Activity) element; + } else if (element instanceof StructuredActivityNode) { + if (((StructuredActivityNode) element).allOwnedElements().contains(target)) { + return (StructuredActivityNode) element; + } + } + } + return null; + } + +} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ControlFlowUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ControlFlowUtil.java index c728baa5a19..e7acab7ee10 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ControlFlowUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ControlFlowUtil.java @@ -12,9 +12,9 @@ *****************************************************************************/
package org.eclipse.papyrus.uml.tools.utils;
-import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ControlFlow;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.InitialNode;
import org.eclipse.uml2.uml.ObjectFlow;
@@ -35,7 +35,7 @@ public class ControlFlowUtil { * @param target
* @return
*/
- public static boolean canExistControlFlow(Activity container, ControlFlow linkInstance, ActivityNode source, ActivityNode target) {
+ public static boolean canExistControlFlow(Element container, ControlFlow linkInstance, ActivityNode source, ActivityNode target) {
try {
if (target instanceof InitialNode) {
return false;
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ObjectFlowUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ObjectFlowUtil.java index c0600c96b39..57518cea863 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ObjectFlowUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ObjectFlowUtil.java @@ -14,12 +14,12 @@ package org.eclipse.papyrus.uml.tools.utils; import org.eclipse.emf.common.util.EList;
import org.eclipse.uml2.uml.Action;
-import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.ActivityEdge;
import org.eclipse.uml2.uml.ActivityNode;
import org.eclipse.uml2.uml.ActivityParameterNode;
import org.eclipse.uml2.uml.ConditionalNode;
import org.eclipse.uml2.uml.DecisionNode;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ExpansionRegion;
import org.eclipse.uml2.uml.FinalNode;
import org.eclipse.uml2.uml.ForkNode;
@@ -82,7 +82,7 @@ public class ObjectFlowUtil { * @param target
* @return
*/
- public static boolean canExistObjectFlow(Activity container, ObjectFlow linkInstance, ActivityNode source, ActivityNode target) {
+ public static boolean canExistObjectFlow(Element container, ObjectFlow linkInstance, ActivityNode source, ActivityNode target) {
try {
if (source instanceof Action) {
// rule validateObjectFlow_validateNoActions
@@ -99,7 +99,7 @@ public class ObjectFlowUtil { && !(source.getOwner() instanceof SequenceNode)
&& !(source.getOwner() instanceof ExpansionRegion)) {
if (target != null) {
- if(!isPinOwnedByStructuredActivityNode(target, (StructuredActivityNode)source.getOwner())) {
+ if (!isPinOwnedByStructuredActivityNode(target, (StructuredActivityNode) source.getOwner())) {
return false;
}
}
@@ -179,7 +179,7 @@ public class ObjectFlowUtil { && !(target.getOwner() instanceof SequenceNode)
&& !(target.getOwner() instanceof ExpansionRegion)) {
if (source != null) {
- if(!isPinOwnedByStructuredActivityNode(source, (StructuredActivityNode) target.getOwner())) {
+ if (!isPinOwnedByStructuredActivityNode(source, (StructuredActivityNode) target.getOwner())) {
return false;
}
}
@@ -315,16 +315,16 @@ public class ObjectFlowUtil { }
/**
- * Check if the pin is directly or indirectly owned by the structuredActivityNode
+ * Check if the pin is directly or indirectly owned by the structuredActivityNode
*
* @param pin
* @param owner
* @return
*/
public static boolean isPinOwnedByStructuredActivityNode(ActivityNode pin, StructuredActivityNode owner) {
- if(pin instanceof Pin) {
+ if (pin instanceof Pin) {
EList<ActivityNode> nodes = owner.allOwnedNodes();
- if(nodes.contains(pin)) {
+ if (nodes.contains(pin)) {
return true;
}
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestLinks.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestLinks.java index 60c6b5f1444..d697d7fcefb 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestLinks.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/canonical/TestLinks.java @@ -46,6 +46,7 @@ import org.eclipse.papyrus.uml.diagram.activity.edit.parts.StructuredActivityNod import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ValuePinInReduceActionAsCollectionEditPart; import org.eclipse.papyrus.uml.diagram.activity.providers.UMLElementTypes; import org.eclipse.papyrus.uml.diagram.activity.tests.IActivityDiagramTestsConstants; +import org.eclipse.uml2.uml.StructuredActivityNode; import org.junit.Assert; import org.junit.Test; @@ -158,6 +159,10 @@ public class TestLinks extends AbstractPapyrusTestCase { Assert.assertEquals(1, getDiagramEditPart().getConnections().size()); IGraphicalEditPart objectFlowConnection = (IGraphicalEditPart) getDiagramEditPart().getConnections().get(0); Assert.assertTrue(objectFlowConnection instanceof ObjectFlowEditPart); + + StructuredActivityNode structuredActivityNode = (StructuredActivityNode) getSemanticElement(structuredActivityNodeEP); + Assert.assertEquals(1, structuredActivityNode.getEdges().size()); + Assert.assertEquals(getSemanticElement(objectFlowConnection), structuredActivityNode.getEdges().get(0)); } @Test @@ -177,8 +182,12 @@ public class TestLinks extends AbstractPapyrusTestCase { Assert.assertEquals(1, getDiagramEditPart().getConnections().size()); IGraphicalEditPart objectFlowConnection = (IGraphicalEditPart) getDiagramEditPart().getConnections().get(0); Assert.assertTrue(objectFlowConnection instanceof ObjectFlowEditPart); + + StructuredActivityNode structuredActivityNode = (StructuredActivityNode) getSemanticElement(structuredActivityNodeEP); + Assert.assertEquals(1, structuredActivityNode.getEdges().size()); + Assert.assertEquals(getSemanticElement(objectFlowConnection), structuredActivityNode.getEdges().get(0)); } - + @Test public void testCreateControlFlowLink() { IGraphicalEditPart initialNodeEP = createChild(InitialNodeEditPart.VISUAL_ID, getActivityCompartmentEditPart()); @@ -195,6 +204,28 @@ public class TestLinks extends AbstractPapyrusTestCase { } @Test + public void testCreateControlFlowLinkInStructuredActivityNode() { + IGraphicalEditPart structuredActivityNodeEP = createChild(StructuredActivityNodeEditPart.VISUAL_ID, getActivityCompartmentEditPart()); + IGraphicalEditPart structuredActivityNodeCompartmentEP = findChildBySemanticHint(structuredActivityNodeEP, StructuredActivityNodeStructuredActivityNodeContentCompartmentEditPart.VISUAL_ID); + + IGraphicalEditPart initialNodeEP = createChild(InitialNodeEditPart.VISUAL_ID, structuredActivityNodeCompartmentEP); + IGraphicalEditPart readExtentActionEP = createChild(ReadExtentActionEditPart.VISUAL_ID, structuredActivityNodeCompartmentEP); + + Command endCommand = createLinkCommand(initialNodeEP, readExtentActionEP, UMLElementTypes.ControlFlow_Edge); + Assert.assertNotNull(endCommand); + Assert.assertTrue(endCommand.canExecute()); + + executeOnUIThread(endCommand); + Assert.assertEquals(1, getDiagramEditPart().getConnections().size()); + IGraphicalEditPart controlFlowConnection = (IGraphicalEditPart) getDiagramEditPart().getConnections().get(0); + Assert.assertTrue(controlFlowConnection instanceof ControlFlowEditPart); + + StructuredActivityNode structuredActivityNode = (StructuredActivityNode) getSemanticElement(structuredActivityNodeEP); + Assert.assertEquals(1, structuredActivityNode.getEdges().size()); + Assert.assertEquals(getSemanticElement(controlFlowConnection), structuredActivityNode.getEdges().get(0)); + } + + @Test public void testObjectFlowLinkReorient() { IGraphicalEditPart parameterNodeEP = createChild(ActivityParameterNodeEditPart.VISUAL_ID, (IGraphicalEditPart)getActivityCompartmentEditPart().getParent()); IGraphicalEditPart opaqueEP = createChild(OpaqueActionEditPart.VISUAL_ID, getActivityCompartmentEditPart()); |