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 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity | |
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>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity')
2 files changed, 126 insertions, 16 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; } - } |