Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-07-22 08:12:04 +0000
committerGerrit Code Review @ Eclipse.org2014-07-22 08:12:04 +0000
commitb43b0ac90fa7d890f6b3d807a4dbb5042bd4d480 (patch)
tree5648a0809e0a31f5d5c6a5812e5431b4d1ae23b6
parenta398c7a71967b519286c1c2e5209fb54af99e1d5 (diff)
parent8e8e946fc91e77bac899a8cccd4aae717e609ee8 (diff)
downloadorg.eclipse.papyrus-b43b0ac90fa7d890f6b3d807a4dbb5042bd4d480.tar.gz
org.eclipse.papyrus-b43b0ac90fa7d890f6b3d807a4dbb5042bd4d480.tar.xz
org.eclipse.papyrus-b43b0ac90fa7d890f6b3d807a4dbb5042bd4d480.zip
Merge "[425853] Cannot create input/output expansion nodes in borders of Expansion Regions"
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/META-INF/MANIFEST.MF1
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/part/ActivityGroup/CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPart.java30
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml6
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionNodeHelper.java35
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionRegionHelper.java72
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF4
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/content/UMLActivityTestModel.uml6
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/AllTests.java4
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/helper/ExpansionRegionHelperTest.java126
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/part/ExpansionRegionCompartmentEPTest.java110
10 files changed, 391 insertions, 3 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/META-INF/MANIFEST.MF
index 44b29b1bae1..fdce6e2a85e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@ Export-Package: org.eclipse.papyrus.uml.diagram.activity,
org.eclipse.papyrus.uml.diagram.activity.edit.dialogs,
org.eclipse.papyrus.uml.diagram.activity.edit.helpers,
org.eclipse.papyrus.uml.diagram.activity.edit.part,
+ org.eclipse.papyrus.uml.diagram.activity.edit.part.ActivityGroup;x-friends:="org.eclipse.papyrus.uml.diagram.activity.tests",
org.eclipse.papyrus.uml.diagram.activity.edit.parts,
org.eclipse.papyrus.uml.diagram.activity.edit.policies,
org.eclipse.papyrus.uml.diagram.activity.expressions,
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/part/ActivityGroup/CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/part/ActivityGroup/CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPart.java
index b62ee351c5c..dd438d7cb3e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/part/ActivityGroup/CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/part/ActivityGroup/CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPart.java
@@ -14,10 +14,16 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.activity.edit.part.ActivityGroup;
+import java.util.List;
+
import org.eclipse.draw2d.IFigure;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ExpansionRegionStructuredActivityNodeContentCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.activity.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool;
/**
* Set in order to have Generation Gap Pattern.
@@ -50,4 +56,28 @@ public class CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPa
public boolean isSelectable() {
return false;
}
+
+ @Override
+ public EditPart getTargetEditPart(Request request) {
+ if (request instanceof AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest) {
+ List<?> createElementsTypes = ((AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest) request).getElementTypes();
+ if (areAllNodesAffixed(createElementsTypes)) {
+ return getParent();
+ }
+ }
+ return super.getTargetEditPart(request);
+ }
+
+ private boolean areAllNodesAffixed(List<?> types) {
+ for(Object type : types) {
+ if (!isAffixedNodeType(type)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean isAffixedNodeType(Object type) {
+ return UMLElementTypes.ExpansionNode_3074.equals(type) || UMLElementTypes.ExpansionNode_3075.equals(type);
+ }
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml b/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml
index 470d733c637..cf2b73b299c 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/plugin.xml
@@ -720,7 +720,8 @@
<metamodelType id="org.eclipse.papyrus.uml.ExpansionNode" name="UML::ExpansionNode"
eclass="ExpansionNode"
icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/ExpansionNode.gif"
- kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType" >
+ kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
+ edithelper="org.eclipse.papyrus.uml.service.types.helper.ExpansionNodeHelper">
<param name="semanticHint" value="UML::ExpansionNode"/>
</metamodelType>
@@ -728,7 +729,8 @@
<metamodelType id="org.eclipse.papyrus.uml.ExpansionRegion" name="UML::ExpansionRegion"
eclass="ExpansionRegion"
icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/ExpansionRegion.gif"
- kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType" >
+ kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
+ edithelper="org.eclipse.papyrus.uml.service.types.helper.ExpansionRegionHelper">
<param name="semanticHint" value="UML::ExpansionRegion"/>
</metamodelType>
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionNodeHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionNodeHelper.java
new file mode 100644
index 00000000000..544ec7ef403
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionNodeHelper.java
@@ -0,0 +1,35 @@
+package org.eclipse.papyrus.uml.service.types.helper;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.uml2.uml.ExpansionRegion;
+
+
+public class ExpansionNodeHelper extends ActivityNodeHelper {
+
+ /**
+ * Parameter name for {@link ConfigureRequest}
+ * Used to pass the parent EObject to actual new element to set it in referenced not containment list.
+ */
+ public static final String IN_EXPANSION_REGION = "IN_EXPANSION_REGION";
+
+ /**
+ * Parameter name for {@link ConfigureRequest}
+ * Used to determine feature to add new element in referenced not containment parent list.
+ */
+ public static final String EXPANSION_REGION_FEATURE = "EXPANSION_REGION_FEATURE";
+
+ @Override
+ protected ICommand getConfigureCommand(ConfigureRequest req) {
+ EObject expectedExpansionRegion = (EObject)req.getParameter(IN_EXPANSION_REGION);
+ if (expectedExpansionRegion instanceof ExpansionRegion) {
+ EObject feature = (EObject)req.getParameter(EXPANSION_REGION_FEATURE);
+ return new SetValueCommand(new SetRequest(expectedExpansionRegion, (EReference)feature, req.getElementToConfigure()));
+ }
+ return super.getConfigureCommand(req);
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionRegionHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionRegionHelper.java
new file mode 100644
index 00000000000..64bee5c7ea2
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/ExpansionRegionHelper.java
@@ -0,0 +1,72 @@
+package org.eclipse.papyrus.uml.service.types.helper;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.uml2.uml.ExpansionNode;
+import org.eclipse.uml2.uml.ExpansionRegion;
+import org.eclipse.uml2.uml.StructuredActivityNode;
+import org.eclipse.uml2.uml.UMLPackage;
+
+public class ExpansionRegionHelper extends ActivityNodeHelper {
+
+ @Override
+ protected ICommand getCreateCommand(CreateElementRequest req) {
+ CreateElementRequest createRequest = isRequestToCreateExpansionNode(req) ? getCreateExpansionRegionAffixedChildRequest(req) : req;
+ return super.getCreateCommand(createRequest);
+ }
+
+ /**
+ * This method return new request for creation {@link ExpansionNode} with right containment feature {@link ExpansionRegion#getInputElements()} and
+ * {@link ExpansionRegion#getOutputElements()} are referenced list and
+ * cannot contains {@link ExpansionNode}. Thats why we add new {@link ExpansionNode} element to {@link StructuredActivityNode#getNodes()}
+ * containment list
+ *
+ * @param ItemSemanticPolicy
+ * {@link CreateElementRequest}
+ * @return {@link CreateElementRequest} with changed containment feature
+ */
+ protected CreateElementRequest getCreateExpansionRegionAffixedChildRequest(CreateElementRequest req) {
+ if(req == null) {
+ return null;
+ }
+ CreateElementRequest result = new CreateElementRequest(req.getEditingDomain(), req.getContainer(), req.getElementType());
+ result.setParameter(ExpansionNodeHelper.IN_EXPANSION_REGION, req.getContainer());
+ result.setParameter(ExpansionNodeHelper.EXPANSION_REGION_FEATURE, req.getContainmentFeature());
+ result.setContainmentFeature(UMLPackage.eINSTANCE.getStructuredActivityNode_Node());
+ return result;
+ }
+
+ /**
+ * Method check CreateEmentRequest to create {@link ExpansionNode} It check new ElementType and check containmentFeature
+ *
+ * @param ItemSematicPolicy
+ * {@link CreateElementRequest}
+ * @return
+ */
+ protected boolean isRequestToCreateExpansionNode(CreateElementRequest req) {
+ IElementType newElementType = req.getElementType();
+ EReference feature = req.getContainmentFeature();
+ return isExpansionNodeType(newElementType) && isExpansionNodeFeature(feature);
+ }
+
+ /**
+ * Check can this feature add {@link ExpansionNode} to {@link ExpansionRegion#getInputElements()} or {@link ExpansionRegion#getOutputElements()}
+ *
+ * @param {@link CreateElementRequest} containment feature.
+ */
+ protected boolean isExpansionNodeFeature(EReference feature) {
+ return UMLPackage.eINSTANCE.getExpansionRegion_InputElement().equals(feature) || UMLPackage.eINSTANCE.getExpansionRegion_OutputElement().equals(feature);
+ }
+
+ /**
+ * Check is this type {@link ExpansionNode}
+ *
+ * @param type
+ * the {@link CreateElementRequest} new {@link IElementType}
+ */
+ protected boolean isExpansionNodeType(IElementType type) {
+ return UMLPackage.eINSTANCE.getExpansionNode().equals(type.getEClass());
+ }
+}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF
index cbda3200461..f95c35a2132 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/META-INF/MANIFEST.MF
@@ -14,7 +14,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
org.junit;bundle-version="4.10.0",
org.eclipse.papyrus.junit.utils;bundle-version="1.0.0",
- org.eclipse.gmf.tooling.runtime
+ org.eclipse.gmf.tooling.runtime,
+ org.eclipse.papyrus.uml.service.types,
+ org.eclipse.uml2.uml.editor
Export-Package: org.eclipse.papyrus.uml.diagram.activity.tests
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/content/UMLActivityTestModel.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/content/UMLActivityTestModel.uml
new file mode 100644
index 00000000000..f45714db6fe
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/content/UMLActivityTestModel.uml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_GcwzAA7AEeSzbqt4C6pm3Q">
+ <packagedElement xmi:type="uml:Activity" xmi:id="_JoZBgA7AEeSzbqt4C6pm3Q" node="_M_2FgA7AEeSzbqt4C6pm3Q">
+ <node xmi:type="uml:ExpansionRegion" xmi:id="_M_2FgA7AEeSzbqt4C6pm3Q"/>
+ </packagedElement>
+</uml:Model>
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/AllTests.java
index ef14d9dea23..6609b4300c6 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/AllTests.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/AllTests.java
@@ -14,6 +14,8 @@
package org.eclipse.papyrus.uml.diagram.activity.tests;
import org.eclipse.papyrus.uml.diagram.activity.tests.canonical.AllCanonicalTests;
+import org.eclipse.papyrus.uml.diagram.activity.tests.edit.helper.ExpansionRegionHelperTest;
+import org.eclipse.papyrus.uml.diagram.activity.tests.edit.part.ExpansionRegionCompartmentEPTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -25,6 +27,8 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({
// canonical
AllCanonicalTests.class,
+ExpansionRegionHelperTest.class,
+ExpansionRegionCompartmentEPTest.class
})
public class AllTests {
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/helper/ExpansionRegionHelperTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/helper/ExpansionRegionHelperTest.java
new file mode 100644
index 00000000000..0439bfbe6ff
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/helper/ExpansionRegionHelperTest.java
@@ -0,0 +1,126 @@
+package org.eclipse.papyrus.uml.diagram.activity.tests.edit.helper;
+
+import static org.junit.Assert.assertNotEquals;
+
+import java.rmi.UnexpectedException;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.papyrus.uml.diagram.activity.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.service.types.command.CreateEditBasedElementCommand;
+import org.eclipse.papyrus.uml.service.types.helper.ExpansionNodeHelper;
+import org.eclipse.papyrus.uml.service.types.helper.ExpansionRegionHelper;
+import org.eclipse.uml2.uml.ExpansionRegion;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.editor.presentation.UMLEditor;
+
+
+public class ExpansionRegionHelperTest extends TestCase {
+
+ public final static String TEST_UML_MODEL = "platform:/plugin/org.eclipse.papyrus.uml.diagram.activity.tests/content/UMLActivityTestModel.uml";
+
+ private MockExpansionRegionHelper myHelperInstance;
+
+ private UMLEditor myUMLEditor;
+
+ private TransactionalEditingDomain myEditingDomain;
+
+ public ExpansionRegionHelperTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myHelperInstance = new MockExpansionRegionHelper();
+ myUMLEditor = new UMLEditor();
+ myEditingDomain = new TransactionalEditingDomainImpl(myUMLEditor.getAdapterFactory()) {
+
+ @Override
+ public boolean isReadOnly(Resource resource) {
+ return false;
+ }
+ };
+ }
+
+ public void testExpansionNodeCreateCommand() throws Exception {
+ CreateElementRequest expansionNodeCreateRequest = initCreateElementRequest(UMLElementTypes.ExpansionNode_3074, UMLPackage.eINSTANCE.getExpansionRegion_InputElement());
+ ICommand command = myHelperInstance.getCreateCommand(expansionNodeCreateRequest);
+ commonExpansionRegionCreateChildTest(command);
+ CreateEditBasedElementCommand createCommand = (CreateEditBasedElementCommand)command;
+ assertNotEquals(expansionNodeCreateRequest, createCommand.getCreateRequest());
+ CreateElementRequest changedRequest = createCommand.getCreateRequest();
+ assertEquals(changedRequest.getContainer(), expansionNodeCreateRequest.getContainer());
+ assertEquals(changedRequest.getContainmentFeature(), UMLPackage.eINSTANCE.getStructuredActivityNode_Node());
+ assertEquals(changedRequest.getParameter(ExpansionNodeHelper.IN_EXPANSION_REGION), changedRequest.getContainer());
+ assertEquals(changedRequest.getParameter(ExpansionNodeHelper.EXPANSION_REGION_FEATURE), UMLPackage.eINSTANCE.getExpansionRegion_InputElement());
+ }
+
+ public void testExpansionRegionContainmentChildCreateCommand() throws Exception {
+ CreateElementRequest expansionRegionContainmentCreateRequest = initCreateElementRequest(UMLElementTypes.StructuredActivityNode_3065, UMLPackage.eINSTANCE.getStructuredActivityNode_Node());
+ ICommand command = myHelperInstance.getCreateCommand(expansionRegionContainmentCreateRequest);
+ commonExpansionRegionCreateChildTest(command);
+ CreateEditBasedElementCommand createCommand = (CreateEditBasedElementCommand)command;
+ assertEquals(expansionRegionContainmentCreateRequest, createCommand.getCreateRequest());
+ }
+
+ public void testExpansionRegionBadCreateCommand() throws Exception {
+ CreateElementRequest badCreateCommandRequest = initCreateElementRequest(UMLElementTypes.ExpansionNode_3074, UMLPackage.eINSTANCE.getStructuredActivityNode_Edge());
+ ICommand command = myHelperInstance.getCreateCommand(badCreateCommandRequest);
+ assertFalse(command.canExecute());
+ }
+
+ private void commonExpansionRegionCreateChildTest(ICommand command) throws Exception {
+ assertNotNull(command);
+ assertTrue(command.canExecute());
+ assertEquals(CreateEditBasedElementCommand.class, command.getClass());
+ }
+
+ private CreateElementRequest initCreateElementRequest(IElementType childType, EReference feature) throws UnexpectedException {
+ CreateElementRequest req = new CreateElementRequest(childType);
+ req.setContainer(loadExpansionRegion());
+ req.setContainmentFeature(feature);
+ req.setEditingDomain(myEditingDomain);
+ return req;
+ }
+
+ private ExpansionRegion loadExpansionRegion() throws UnexpectedException {
+ ResourceSet resourceSet = myUMLEditor.getEditingDomain().getResourceSet();
+ Resource resource = resourceSet.getResource(URI.createURI(TEST_UML_MODEL), true);
+ for(Iterator<EObject> i = resource.getAllContents(); i.hasNext();) {
+ EObject content = i.next();
+ if(content instanceof ExpansionRegion) {
+ return (ExpansionRegion)content;
+ }
+ }
+ throw new UnexpectedException("ExpansionRegion element was not fount in " + TEST_UML_MODEL);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ myEditingDomain = null;
+ myUMLEditor = null;
+ myHelperInstance = null;
+ super.tearDown();
+ }
+
+ private static class MockExpansionRegionHelper extends ExpansionRegionHelper {
+
+ @Override
+ public ICommand getCreateCommand(CreateElementRequest req) {
+ return super.getCreateCommand(req);
+ }
+
+ }
+}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/part/ExpansionRegionCompartmentEPTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/part/ExpansionRegionCompartmentEPTest.java
new file mode 100644
index 00000000000..09a1be16c1a
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity.tests/src/org/eclipse/papyrus/uml/diagram/activity/tests/edit/part/ExpansionRegionCompartmentEPTest.java
@@ -0,0 +1,110 @@
+package org.eclipse.papyrus.uml.diagram.activity.tests.edit.part;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.activity.edit.part.ActivityGroup.CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ExpansionRegionEditPart;
+import org.eclipse.papyrus.uml.diagram.activity.edit.parts.ExpansionRegionStructuredActivityNodeContentCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.activity.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool;
+import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.junit.Test;
+
+public class ExpansionRegionCompartmentEPTest extends TestCase {
+
+ private MockExpansionRegionEditPart myParentEP;
+
+ private MockCustomExpansionRegionCompartmentEditPart myCompartmentEP;
+
+ public ExpansionRegionCompartmentEPTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myParentEP = createParentEditPart();
+ myCompartmentEP = createCompartmentEP(myParentEP);
+ myParentEP.createDefaultEditPolicies();
+ myCompartmentEP.createDefaultEditPolicies();
+ }
+
+ private MockExpansionRegionEditPart createParentEditPart() {
+ EObject expansionRegionView = UMLFactory.eINSTANCE.createExpansionRegion();
+ View nodeView = NotationFactory.eINSTANCE.createShape();
+ nodeView.setElement(expansionRegionView);
+ nodeView.setType("" + ExpansionRegionEditPart.VISUAL_ID);
+ return new MockExpansionRegionEditPart(nodeView);
+ }
+
+ private MockCustomExpansionRegionCompartmentEditPart createCompartmentEP(ExpansionRegionEditPart parentEP) {
+ View decoratorView = NotationFactory.eINSTANCE.createDecorationNode();
+ decoratorView.setType("" + ExpansionRegionStructuredActivityNodeContentCompartmentEditPart.VISUAL_ID);
+ parentEP.getNotationView().insertChild(decoratorView);
+ MockCustomExpansionRegionCompartmentEditPart compartment = new MockCustomExpansionRegionCompartmentEditPart(decoratorView);
+ compartment.setParent(parentEP);
+ return compartment;
+ }
+
+ @Test
+ public void testExpansionNodeCreationRequest() {
+ assertEquals(myParentEP, getTestTargetEditPart(UMLElementTypes.ExpansionNode_3074, UMLElementTypes.ExpansionNode_3075));
+ }
+
+ @Test
+ public void testMixedElementTypesCreationRequest() {
+ assertNotNull(getTestTargetEditPart(UMLElementTypes.ExpansionNode_3074, UMLElementTypes.LoopNode_3071));
+ }
+
+ @Test
+ public void testAlienCreationRequest() {
+ assertEquals(myCompartmentEP, getTestTargetEditPart(UMLElementTypes.StructuredActivityNode_3065));
+ }
+
+ private EditPart getTestTargetEditPart(IElementType... types) {
+ List<IElementType> typesList = Arrays.asList(types);
+ CreateAspectUnspecifiedTypeRequest req = new AspectUnspecifiedTypeCreationTool(typesList).new CreateAspectUnspecifiedTypeRequest(typesList, PreferencesHint.USE_DEFAULTS);
+ return myCompartmentEP.getTargetEditPart(req);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ myCompartmentEP = null;
+ myParentEP = null;
+ super.tearDown();
+ }
+
+ private static class MockCustomExpansionRegionCompartmentEditPart extends CustomExpansionRegionStructuredActivityNodeContentCompartmentEditPart {
+
+ public MockCustomExpansionRegionCompartmentEditPart(View view) {
+ super(view);
+ }
+
+ @Override
+ public void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ }
+ }
+
+ private static class MockExpansionRegionEditPart extends ExpansionRegionEditPart {
+
+ public MockExpansionRegionEditPart(View view) {
+ super(view);
+ }
+
+ @Override
+ public void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ }
+ }
+}

Back to the top