aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2018-07-24 08:50:46 -0400
committerNicolas FAUVERGUE2018-07-24 09:57:50 -0400
commit892cb3c424d47082d850b38a6c793692817c7a8a (patch)
treea12120fccb1a4808a8b9b55cb9aae28a3d1912fb
parentaa9490b90434811a4f38075ff24d0869106c8a03 (diff)
downloadorg.eclipse.papyrus-892cb3c424d47082d850b38a6c793692817c7a8a.tar.gz
org.eclipse.papyrus-892cb3c424d47082d850b38a6c793692817c7a8a.tar.xz
org.eclipse.papyrus-892cb3c424d47082d850b38a6c793692817c7a8a.zip
Bug 479981 - [Component Diagram] Components-in-component misplaced
Change-Id: Ie7b8879202ff0cd43cd86afab28e185542ac7c4b Signed-off-by: atischenko <tischenko@montages.com> Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CompositeCompartmentCreationEditPolicy.java72
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java25
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/model/ComponentDiagram.gmfgen12
-rwxr-xr-xplugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPart.java2
-rwxr-xr-xplugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartCN.java2
-rwxr-xr-xplugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartPCN.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java5
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/AllTests.java6
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/AllDropTests.java25
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/TestDropComponent.java163
11 files changed, 314 insertions, 3 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CompositeCompartmentCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CompositeCompartmentCreationEditPolicy.java
new file mode 100644
index 00000000000..fcc56d8c702
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CompositeCompartmentCreationEditPolicy.java
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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.diagram.component.custom.edit.policies;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEditPolicy;
+import org.eclipse.uml2.uml.Component;
+
+/**
+ * This policy used to reparent in case when semantically child {@link Component} contained in parnet {@link Component}
+ * but graphically child {@link Component} contained in another place.
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=479981
+ */
+public class CompositeCompartmentCreationEditPolicy extends DefaultCreationEditPolicy {
+
+ /**
+ * Reparent only view if child is {@link Component}
+ * if other case
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEditPolicy#getReparentCommand(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)
+ */
+ @Override
+ protected ICommand getReparentCommand(IGraphicalEditPart gep) {
+ if (gep.resolveSemanticElement() instanceof Component) {
+ return getReparentViewCommand(gep);
+ }
+
+ return super.getReparentCommand(gep);
+ }
+
+ /**
+ * In case when element is {@link Component} don't check is newContext already contain element
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy#shouldReparent(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ protected boolean shouldReparent(EObject element, EObject newContext) {
+ if (element instanceof Component) {
+ return !(element == null || element == newContext || isContainedIn(element, newContext));
+ }
+ return super.shouldReparent(element, newContext);
+ }
+
+ /**
+ * pivate method isContainedIn({@link EObject} element, {@link EObject} newContext) from {@link CreationEditPolicy}
+ */
+ private boolean isContainedIn(EObject element, EObject newContext) {
+ EObject container = newContext.eContainer();
+ while (container != null) {
+ if (container.equals(element)) {
+ return true;
+ }
+ container = container.eContainer();
+ }
+ return false;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
index 11872844fc9..82c14b4c907 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/edit/policies/CustomDiagramDragDropEditPolicy.java
@@ -64,6 +64,7 @@ import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Collaboration;
import org.eclipse.uml2.uml.CollaborationUse;
import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.ConnectableElement;
import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Constraint;
@@ -196,6 +197,8 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
case ComponentEditPartPCN.VISUAL_ID:
case InterfaceEditPartPCN.VISUAL_ID:
return dropChildNode(dropRequest, semanticElement, nodeVISUALID, linkVISUALID);
+ case ComponentEditPartCN.VISUAL_ID:
+ return dropComponentToComponent(dropRequest, semanticElement, nodeVISUALID, linkVISUALID);
// Test ChildNode... End
// Test TopLevelNode... Start
case DependencyNodeEditPart.VISUAL_ID:
@@ -289,6 +292,28 @@ public class CustomDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPo
}
/**
+ * Drop the component into another component.
+ *
+ * @param dropRequest
+ * the drop request
+ * @param semanticElement
+ * the semantic element
+ * @param nodeVISUALID
+ * the node visualid
+ * @param linkVISUALID
+ * the link visualid
+ * @return the command
+ */
+ private Command dropComponentToComponent(DropObjectsRequest dropRequest, Element semanticElement, String nodeVISUALID, String linkVISUALID) {
+ GraphicalEditPart graphicalParentEditPart = (GraphicalEditPart) getHost();
+ EObject graphicalParentObject = graphicalParentEditPart.resolveSemanticElement();
+ if (graphicalParentObject instanceof Component) {
+ return new ICommandProxy(getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticElement));
+ }
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ /**
* Drop dependency node.
*
* @param dropRequest
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/model/ComponentDiagram.gmfgen b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/model/ComponentDiagram.gmfgen
index fa89a066497..1d8a8abd312 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/model/ComponentDiagram.gmfgen
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/model/ComponentDiagram.gmfgen
@@ -2891,6 +2891,10 @@
xsi:type="gmfgen:CustomBehaviour"
key="org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY"
editPolicyQualifiedClassName="org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy"/>
+ <behaviour
+ xsi:type="gmfgen:CustomBehaviour"
+ key="org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CREATION_ROLE"
+ editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CompositeCompartmentCreationEditPolicy"/>
</compartments>
<compartments
visualID="7006"
@@ -3036,6 +3040,10 @@
xsi:type="gmfgen:CustomBehaviour"
key="org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY"
editPolicyQualifiedClassName="org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy"/>
+ <behaviour
+ xsi:type="gmfgen:CustomBehaviour"
+ key="org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CREATION_ROLE"
+ editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CompositeCompartmentCreationEditPolicy"/>
</compartments>
<compartments
visualID="7004"
@@ -3065,6 +3073,10 @@
xsi:type="gmfgen:CustomBehaviour"
key="org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY"
editPolicyQualifiedClassName="org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy"/>
+ <behaviour
+ xsi:type="gmfgen:CustomBehaviour"
+ key="org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CREATION_ROLE"
+ editPolicyQualifiedClassName="org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CompositeCompartmentCreationEditPolicy"/>
</compartments>
<compartments
visualID="7008"
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPart.java
index 98a14c456eb..92d2b292627 100755
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPart.java
@@ -31,6 +31,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEdit
import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.LinkLFShapeCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.PasteEditPolicy;
+import org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CompositeCompartmentCreationEditPolicy;
import org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CustomDiagramDragDropEditPolicy;
import org.eclipse.papyrus.uml.diagram.component.part.Messages;
@@ -76,6 +77,7 @@ public class ComponentCompositeCompartmentEditPart extends LinkLFShapeCompartmen
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy());
installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
+ installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompositeCompartmentCreationEditPolicy());
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartCN.java
index 2d6b6630bea..04f133017f3 100755
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartCN.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartCN.java
@@ -31,6 +31,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEdit
import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.LinkLFShapeCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.PasteEditPolicy;
+import org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CompositeCompartmentCreationEditPolicy;
import org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CustomDiagramDragDropEditPolicy;
import org.eclipse.papyrus.uml.diagram.component.part.Messages;
@@ -76,6 +77,7 @@ public class ComponentCompositeCompartmentEditPartCN extends LinkLFShapeCompartm
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy());
installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
+ installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompositeCompartmentCreationEditPolicy());
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartPCN.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartPCN.java
index 54fffc3eca2..a379fb394b4 100755
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartPCN.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/src-gen/org/eclipse/papyrus/uml/diagram/component/edit/parts/ComponentCompositeCompartmentEditPartPCN.java
@@ -31,6 +31,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEdit
import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.LinkLFShapeCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomContainerEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.PasteEditPolicy;
+import org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CompositeCompartmentCreationEditPolicy;
import org.eclipse.papyrus.uml.diagram.component.custom.edit.policies.CustomDiagramDragDropEditPolicy;
import org.eclipse.papyrus.uml.diagram.component.part.Messages;
@@ -76,6 +77,7 @@ public class ComponentCompositeCompartmentEditPartPCN extends LinkLFShapeCompart
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new CustomContainerEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy());
installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
+ installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompositeCompartmentCreationEditPolicy());
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF
index d210a41e2a1..01836f79323 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF
@@ -7,7 +7,8 @@ Require-Bundle: org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="[1.2.0,2.0
org.eclipse.papyrus.uml.diagram.common;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.uml.tools;bundle-version="[4.0.0,5.0.0)",
org.eclipse.papyrus.uml.diagram.clazz;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.papyrus.uml.diagram.composite;bundle-version="[3.0.0,4.0.0)"
+ org.eclipse.papyrus.uml.diagram.composite;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.papyrus.uml.diagram.component;bundle-version="[3.1.0,4.0.0)"
Bundle-Vendor: Eclipse Modeling Project
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java
index 664faf92418..b60a631ffaf 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java
@@ -27,6 +27,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
+import org.eclipse.papyrus.uml.diagram.component.part.UMLVisualIDRegistry;
import org.eclipse.papyrus.uml.diagram.composite.custom.helper.TypeHelper;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CompositeStructureDiagramEditPart;
import org.eclipse.papyrus.uml.diagram.dnd.Activator;
@@ -67,6 +68,10 @@ public class ClassifierAsPropertyToStructuredCompartmentDropStrategy extends Tra
}
protected boolean isStructuredClassifierEP(EditPart ep) {
+ String containerModelID = UMLVisualIDRegistry.getModelID((View) ep.getModel());
+ if (!CompositeStructureDiagramEditPart.MODEL_ID.equals(containerModelID)) {
+ return false;
+ }
if (false == ep instanceof GraphicalEditPart) {
return false;
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/AllTests.java
index dc503863b1c..c4d430a7cbc 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/AllTests.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/AllTests.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* Copyright (c) 2013, 2015 CEA LIST, Christian W. Damus, 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
@@ -16,6 +16,7 @@ package org.eclipse.papyrus.uml.diagram.component.test;
import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite;
import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite.DynamicClasses;
import org.eclipse.papyrus.uml.diagram.component.test.canonical.AllCanonicalTests;
+import org.eclipse.papyrus.uml.diagram.component.test.dnd.AllDropTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;
@@ -26,7 +27,8 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({
// canonical
AllCanonicalTests.class,
- RoundedCompartmentTest.class
+ RoundedCompartmentTest.class,
+ AllDropTests.class
// load
// LoadTests.class,
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/AllDropTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/AllDropTests.java
new file mode 100644
index 00000000000..f2e51b772c9
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/AllDropTests.java
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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.diagram.component.test.dnd;
+
+import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(ClassificationSuite.class)
+@SuiteClasses({
+ TestDropComponent.class
+})
+public class AllDropTests {
+}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/TestDropComponent.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/TestDropComponent.java
new file mode 100644
index 00000000000..15183ace59d
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/dnd/TestDropComponent.java
@@ -0,0 +1,163 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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.diagram.component.test.dnd;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.papyrus.commands.ICreationCommand;
+import org.eclipse.papyrus.infra.gmfdiag.menu.utils.DeleteActionUtil;
+import org.eclipse.papyrus.uml.diagram.component.CreateComponentDiagramCommand;
+import org.eclipse.papyrus.uml.diagram.component.edit.parts.ComponentCompositeCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.component.edit.parts.ComponentEditPart;
+import org.eclipse.papyrus.uml.diagram.component.edit.parts.ComponentEditPartCN;
+import org.eclipse.papyrus.uml.diagram.component.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.component.test.IComponentDiagramTestsConstants;
+import org.eclipse.papyrus.uml.diagram.tests.canonical.AbstractPapyrusSemanticTestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestDropComponent extends AbstractPapyrusSemanticTestCase {
+
+ protected IGraphicalEditPart topComponent;
+
+ protected IGraphicalEditPart topCompartment;
+
+ protected IGraphicalEditPart childComponent;
+
+ @Before
+ public void init() {
+ topComponent = createChild(ComponentEditPart.VISUAL_ID, getDiagramEditPart());
+ topCompartment = findChildBySemanticHint(topComponent, ComponentCompositeCompartmentEditPart.VISUAL_ID);
+ childComponent = createChild(ComponentEditPartCN.VISUAL_ID, topCompartment);
+ }
+
+ @Test
+ public void testDropChildComponentFromComponentToDiagram() {
+ IGraphicalEditPart diagram = getDiagramEditPart();
+ Request req = createDragDropRequest(childComponent);
+ Command command = diagram.getCommand(req);
+ assertNotNull("Drop component from component to diagram command must not be null", command);
+
+ int diagramChildrenBefore = diagram.getChildren().size();
+ executeOnUIThread(command);
+ assertEquals(diagramChildrenBefore + 1, diagram.getChildren().size());
+ }
+
+ @Test
+ public void testHideAndDropChildComponentToComponent() {
+ EObject childComponentSemantic = childComponent.resolveSemanticElement();
+
+ Command command = DeleteActionUtil.getDeleteFromDiagramCommand(childComponent);
+ assertNotNull("ComponentEditPartCN should have posible to be deleted from diagram", command);
+ int childrenBefore = topCompartment.getChildren().size();
+ executeOnUIThread(command);
+ assertEquals(childrenBefore - 1, topCompartment.getChildren().size());
+
+ Request req = createDropObjectRequest(childComponentSemantic);
+ command = topCompartment.getCommand(req);
+ assertNotNull("ComponentEditPartCN must be dropable to top component editpart", command);
+ execute(command);
+ assertEquals(childrenBefore, topCompartment.getChildren().size());
+ }
+
+ @Test
+ public void testHideChild_DropToDiagram_DropToParentComponent() {
+ EObject childComponentSemantic = childComponent.resolveSemanticElement();
+ IGraphicalEditPart diagram = getDiagramEditPart();
+
+ Command command = DeleteActionUtil.getDeleteFromDiagramCommand(childComponent);
+ assertNotNull("ComponentEditPartCN should have posible to be deleted from diagram", command);
+ int childrenBefore = topCompartment.getChildren().size();
+ executeOnUIThread(command);
+ assertEquals(childrenBefore - 1, topCompartment.getChildren().size());
+
+ Request req = createDropObjectRequest(childComponentSemantic);
+ command = diagram.getCommand(req);
+ int diagramCgildrenBefore = diagram.getChildren().size();
+ assertNotNull("Component must be dropable to diagram", command);
+ execute(command);
+ assertEquals(diagramCgildrenBefore + 1, diagram.getChildren().size());
+
+ IGraphicalEditPart componentToDrop = null;
+ // find component to drop
+ for (Object child : diagram.getChildren()) {
+ IGraphicalEditPart childEP = (IGraphicalEditPart) child;
+ if (childEP.resolveSemanticElement() == childComponentSemantic) {
+ componentToDrop = childEP;
+ break;
+ }
+ }
+ assertNotNull("Cannot find dropped component to diagram", componentToDrop);
+ req = createDragDropRequest(componentToDrop);
+ command = topCompartment.getCommand(req);
+ assertNotNull("ComponentEditPart must be dropable from diagram to self semantically parent", command);
+ execute(command);
+ assertEquals(diagramCgildrenBefore, diagram.getChildren().size());
+ assertEquals(childrenBefore, topCompartment.getChildren().size());
+ }
+
+ @Override
+ protected ICreationCommand getDiagramCommandCreation() {
+ return new CreateComponentDiagramCommand();
+ }
+
+ @Override
+ protected String getProjectName() {
+ return IComponentDiagramTestsConstants.PROJECT_NAME;
+ }
+
+ @Override
+ protected String getFileName() {
+ return IComponentDiagramTestsConstants.FILE_NAME;
+ }
+
+ protected Request createDropObjectRequest(EObject objectToDrop) {
+ DropObjectsRequest result = new DropObjectsRequest();
+ result.setObjects(Arrays.asList(objectToDrop));
+ result.setType(org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.REQ_DROP_OBJECTS);
+ result.setLocation(new Point(1, 1));
+ return result;
+ }
+
+ protected Request createDragDropRequest(IGraphicalEditPart editPart) {
+ ChangeBoundsRequest result = new ChangeBoundsRequest();
+ result.setEditParts(editPart);
+ result.setLocation(new Point(1, 1));
+ result.setType(org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.REQ_DROP);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.uml.diagram.tests.canonical.AbstractPapyrusSemanticTestCase#getTypeByID(java.lang.String)
+ */
+ @Override
+ protected IElementType getTypeByID(final String vid) {
+ return UMLElementTypes.getElementType(vid);
+ }
+
+
+}