Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/PartitionMoveCommand.java')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/PartitionMoveCommand.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/PartitionMoveCommand.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/PartitionMoveCommand.java
new file mode 100644
index 00000000000..fee89cfc39e
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/command/PartitionMoveCommand.java
@@ -0,0 +1,73 @@
+package org.eclipse.papyrus.uml.service.types.command;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
+import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+
+/**
+ * All ActivityPartition semantic children containment Activity.
+ * Standard command cannot move ActivityPartition children to Activity or
+ * Activity children to ActivityPartition because command move children
+ * only from one parent to another.
+ *
+ */
+public class PartitionMoveCommand extends MoveElementsCommand {
+
+ /**
+ * Default constructor
+ * @param request
+ */
+ public PartitionMoveCommand(MoveRequest request) {
+ super(request);
+ }
+
+ /**
+ * For ability to move children from one container to this same container
+ * we need to remove this check from base canExecute command
+ * <code>
+ * if (container.equals(element.eContainer())
+ * && feature == element.eContainmentFeature()) {
+ * // Don't allow the reparenting
+ * return false;
+ * }
+ * </code>
+ */
+ @Override
+ public boolean canExecute() {
+ EObject container = getTargetContainer();
+
+ if(container == null || getElementsToMove() == null || getElementsToMove().isEmpty()) {
+ return false;
+ }
+
+ for(Iterator i = getElementsToMove().keySet().iterator(); i.hasNext();) {
+ EObject element = (EObject)i.next();
+ EReference feature = getTargetFeature(element);
+
+ if(feature == null || !container.eClass().getEAllReferences().contains(feature)) {
+ // If the target feature doesn't exist in the target container,
+ // don't allow the move.
+ return false;
+ }
+
+ // IF the element is the parent of the target container...
+ if(EcoreUtil.isAncestor(element, getTargetContainer())) {
+ // Don't allow the reparenting
+ return false;
+ }
+
+ // IF the container can not contain the element...
+ if(!PackageUtil.canContain(getTargetContainer().eClass(), feature, element.eClass(), false)) {
+ // Don't allow the reparenting
+ return false;
+ }
+ }
+
+ return true;
+ }
+}

Back to the top