diff options
author | Remi Schnekenburger | 2015-04-27 06:31:15 +0000 |
---|---|---|
committer | Remi Schnekenburger | 2015-04-27 06:31:15 +0000 |
commit | ad791127919679a3972182966868ddba3a428574 (patch) | |
tree | 92756d0649b2f84e1dcd6301df3d80e6cf5b3416 /extraplugins/umlrt | |
parent | b60272ea194c1dc1009051dde65162306a872156 (diff) | |
parent | 6daac06228f0cf85370e40bb060fc2f8f8bc0746 (diff) | |
download | org.eclipse.papyrus-ad791127919679a3972182966868ddba3a428574.tar.gz org.eclipse.papyrus-ad791127919679a3972182966868ddba3a428574.tar.xz org.eclipse.papyrus-ad791127919679a3972182966868ddba3a428574.zip |
Merge branch 'master' of
ssh://rschnekenbu@git.eclipse.org:29418/papyrus/org.eclipse.papyrus.git
Conflicts:
extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/advice/MessageSetEditHelperAdvice.java
extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/ProtocolContainerUtils.java
Diffstat (limited to 'extraplugins/umlrt')
3 files changed, 134 insertions, 2 deletions
diff --git a/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/advice/MessageSetEditHelperAdvice.java b/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/advice/MessageSetEditHelperAdvice.java index e971811e1f7..3c359824a3e 100644 --- a/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/advice/MessageSetEditHelperAdvice.java +++ b/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/advice/MessageSetEditHelperAdvice.java @@ -15,19 +15,25 @@ package org.eclipse.papyrus.umlrt.custom.advice; import java.util.Arrays; import java.util.List; +import java.util.Map; import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry; import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand; import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest; import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest; import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest; import org.eclipse.papyrus.umlrt.custom.IUMLRTElementTypes; +import org.eclipse.papyrus.umlrt.custom.utils.MessageUtils; import org.eclipse.papyrus.umlrt.internals.Activator; +import org.eclipse.uml2.uml.CallEvent; import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Operation; /** @@ -43,9 +49,33 @@ public class MessageSetEditHelperAdvice extends AbstractEditHelperAdvice { return super.getAfterEditContextCommand(request); } + + /** + * {@inheritDoc} + */ @Override - protected ICommand getAfterMoveCommand(MoveRequest request) { - return super.getAfterMoveCommand(request); + protected ICommand getAfterMoveCommand(final MoveRequest request) { + CompositeCommand compositeMoveCommand = new CompositeCommand("Composite Move Command"); + + Map<?, ?> elementsToMove = request.getElementsToMove(); + if (!elementsToMove.isEmpty()) { + for (Object elementToMove : elementsToMove.keySet()) { + if (elementToMove instanceof Operation) { + final Operation operation = (Operation) elementToMove; + final CallEvent callEvent = MessageUtils.getCallEvent(operation); + if (callEvent != null) { + MoveElementsCommand command = MessageUtils.createMoveCallEventCommand(request, callEvent); + compositeMoveCommand.add(command); + } + } + } + } + + if (compositeMoveCommand.isEmpty()) { + compositeMoveCommand.add(super.getAfterMoveCommand(request)); + } + + return compositeMoveCommand; } /** diff --git a/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/MessageUtils.java b/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/MessageUtils.java new file mode 100644 index 00000000000..abbab20c021 --- /dev/null +++ b/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/MessageUtils.java @@ -0,0 +1,78 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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.umlrt.custom.utils;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.uml2.uml.CallEvent;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+
+/**
+ * Utility class for UMLRT::Protocols
+ */
+public class MessageUtils {
+
+ /**
+ * Returns the corresponding CallEvent of a given operation if exists. Returns null otherwise.
+ *
+ * @param operation
+ */
+ public static CallEvent getCallEvent(Operation operation) {
+ CallEvent result = null;
+
+ Package nearestPackage = operation.getNearestPackage();
+ for (Element element : nearestPackage.getOwnedElements()) {
+ if (element instanceof CallEvent) {
+ final CallEvent callEvent = (CallEvent) element;
+ if (callEvent.getOperation().equals(operation)) {
+ result = callEvent;
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public static MoveElementsCommand createMoveCallEventCommand(final MoveRequest request, final CallEvent callEvent) {
+ MoveElementsCommand moveElementsCommand = new MoveElementsCommand(request) {
+ /**
+ * @see org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand#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 {
+ EObject protocolContainer = ProtocolContainerUtils.getProtocolContainer(request.getTargetContainer());
+ MoveRequest callEventMoveRequest = new MoveRequest(protocolContainer, callEvent);
+ MoveElementsCommand command = new MoveElementsCommand(callEventMoveRequest);
+ command.execute(monitor, info);
+
+ return super.doExecuteWithResult(monitor, info);
+ }
+ };
+ return moveElementsCommand;
+ }
+
+}
diff --git a/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/ProtocolContainerUtils.java b/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/ProtocolContainerUtils.java index 057887d716d..dc82c0a8860 100644 --- a/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/ProtocolContainerUtils.java +++ b/extraplugins/umlrt/org.eclipse.papyrus.umlrt/src/org/eclipse/papyrus/umlrt/custom/utils/ProtocolContainerUtils.java @@ -253,7 +253,31 @@ public class ProtocolContainerUtils { return returnList; } + /** + * Returns ProtocolContainer of a given UML::PackagableElement. + * @param element + * @return + */ + public static Package getProtocolContainer(PackageableElement element) { + return element.getNearestPackage(); + } + /** + * Returns ProtocolContainer of a given EObject. + * @param eObject + * @return + */ + public static EObject getProtocolContainer(EObject eObject) { + EObject result = null; + + if (eObject instanceof Package) { + result = eObject; + } else { + result = getProtocolContainer(eObject.eContainer()); + } + + return result; + } |