diff options
author | Jessy Mallet | 2016-06-24 16:07:21 +0000 |
---|---|---|
committer | Laurent Redor | 2016-07-06 16:47:47 +0000 |
commit | fa3d1d6c8b52f6e3f803b651cd0237df890eb0d6 (patch) | |
tree | fe3c46740fc9ce63518252415cac6d14649b27c1 | |
parent | e09517be10bbf33eb1e3a3292c33be881a7261b4 (diff) | |
download | org.eclipse.sirius-fa3d1d6c8b52f6e3f803b651cd0237df890eb0d6.tar.gz org.eclipse.sirius-fa3d1d6c8b52f6e3f803b651cd0237df890eb0d6.tar.xz org.eclipse.sirius-fa3d1d6c8b52f6e3f803b651cd0237df890eb0d6.zip |
[497403] Add compartments SwtBot tests
* Add tests to check regions container size after creation when this
container is defined by a specific size or not. If the region has a
predefined size, the regions container is created with predefined size.
* Add of tests to check container size after collapsing. When a
region is collapsed, the container is collapsed too and there is no
blank space created in the container.
Bug: 497403
Cherry-picked-from: 495119
Change-Id: I0290ed995f660a595bef644c6a7f92195ad917db
Signed-off-by: Jessy Mallet <jessy.mallet@obeo.fr>
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
5 files changed, 1082 insertions, 21 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/My.aird b/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/My.aird index 242c28d470..b30402e92f 100644 --- a/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/My.aird +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/My.aird @@ -210,7 +210,7 @@ <styles xmi:type="notation:DiagramStyle" xmi:id="_xGlbYkgKEeWO8ekbzmZQXg"/> </data> </ownedAnnotationEntries> - <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_x0rQcEgKEeWO8ekbzmZQXg" name="P1" width="5" height="5" childrenPresentation="VerticalStack"> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_x0rQcEgKEeWO8ekbzmZQXg" name="P1" width="-1" height="-1" childrenPresentation="VerticalStack"> <target xmi:type="ecore:EPackage" href="My.ecore#//P1"/> <semanticElements xmi:type="ecore:EPackage" href="My.ecore#//P1"/> <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_-_YwYHfwEeWQo7JxcqP_Mw" borderSize="5" borderSizeComputationExpression="5" borderColor="156,12,12"> @@ -371,7 +371,7 @@ </ownedDiagramElements> </ownedDiagramElements> </ownedDiagramElements> - <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_x0r3gEgKEeWO8ekbzmZQXg" name="az" width="5" height="5" childrenPresentation="VerticalStack"> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_x0r3gEgKEeWO8ekbzmZQXg" name="az" width="-1" height="-1" childrenPresentation="VerticalStack"> <target xmi:type="ecore:EPackage" href="My.ecore#//az"/> <semanticElements xmi:type="ecore:EPackage" href="My.ecore#//az"/> <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_x0r3gUgKEeWO8ekbzmZQXg" borderSize="5" borderSizeComputationExpression="5" borderColor="156,12,12"> diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/compartments.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/compartments.odesign index e1c7b5f0af..25935926b1 100644 --- a/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/compartments.odesign +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/compartments/compartments.odesign @@ -69,13 +69,35 @@ <labelBorderStyle href="environment:/viewpoint#//@labelBorderStyles/@labelBorderStyleDescriptions.1"/> </style> </conditionnalStyles> + <conditionnalStyles predicateExpression="[name.startsWith('Hide')/]"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="20" arcHeight="20" borderSizeComputationExpression="1" borderLineStyle="dot" labelAlignment="LEFT" hideLabelByDefault="true" backgroundStyle="Liquid" backgroundColor="//@userColorsPalettes[name='Colors']/@entries[name='regionInterpolatedColor']" foregroundColor="//@userColorsPalettes[name='Colors']/@entries[name='regionInterpolatedColor']"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='red']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='red']"/> + </style> + </conditionnalStyles> </subContainerMappings> - <style xsi:type="style:FlatContainerStyleDescription" borderSizeComputationExpression="5" roundedCorner="true" widthComputationExpression="5" heightComputationExpression="5"> + <style xsi:type="style:FlatContainerStyleDescription" borderSizeComputationExpression="5" roundedCorner="true"> <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_red']"/> <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> </style> + <conditionnalStyles predicateExpression="[name.startsWith('Hide')/]"> + <style xsi:type="style:FlatContainerStyleDescription" borderSizeComputationExpression="5" hideLabelByDefault="true" roundedCorner="true"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_red']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </conditionnalStyles> + <conditionnalStyles predicateExpression="[name.startsWith('Init')/]"> + <style xsi:type="style:FlatContainerStyleDescription" borderSizeComputationExpression="5" roundedCorner="true" widthComputationExpression="8" heightComputationExpression="8"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_red']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </conditionnalStyles> </containerMappings> <toolSections name="default"> <ownedTools xsi:type="tool:NodeCreationDescription" name="EAttribute" nodeMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack']/@subContainerMappings[name='ListRegions']/@subNodeMappings[name='Attributes']"> @@ -133,6 +155,90 @@ </firstModelOperations> </initialOperation> </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="OneClassInEPackage" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Left_C' + container.eClassifiers->size()"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="TwoClassesInEPackage" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C0"/> + </subModelOperations> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C1"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="EPackageWithHideLabel" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Hide' + container.eSubpackages->size()"/> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="EPackageWithDefinedSize" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Init_p' + container.eSubpackages->size()"/> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="OneClassInEPackageWithDefinedSize" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Init_p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Left_C' + container.eClassifiers->size()"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="TwoClassesInEPackageWithDefinedSize" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20VStack']/@defaultLayer/@containerMappings[name='VStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Init_p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C0"/> + </subModelOperations> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C1"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> </toolSections> </defaultLayer> </ownedRepresentations> @@ -211,6 +317,22 @@ <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> </style> + <conditionnalStyles predicateExpression="[name.startsWith('Hide')/]"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="20" arcHeight="20" borderSizeComputationExpression="4" hideLabelByDefault="true" roundedCorner="true"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_red']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </conditionnalStyles> + <conditionnalStyles predicateExpression="[name.startsWith('Init')/]"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="20" arcHeight="20" borderSizeComputationExpression="4" roundedCorner="true" widthComputationExpression="8" heightComputationExpression="8"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_red']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </conditionnalStyles> </containerMappings> <toolSections name="default"> <ownedTools xsi:type="tool:NodeCreationDescription" name="EAttribute" nodeMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack']/@subContainerMappings[name='HListRegions']/@subNodeMappings[name='HAttributes']"> @@ -268,6 +390,90 @@ </firstModelOperations> </initialOperation> </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="OneClassInEPackage" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Left_C' + container.eClassifiers->size()"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="TwoClassesInEPackage" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C0"/> + </subModelOperations> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C1"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="EPackageWithHideLabel" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Hide' + container.eSubpackages->size()"/> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="EPackageWithDefinedSize" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Init_p' + container.eSubpackages->size()"/> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="OneClassInEPackageWithDefinedSize" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Init_p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Left_C' + container.eClassifiers->size()"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:ContainerCreationDescription" name="TwoClassesInEPackageWithDefinedSize" containerMappings="//@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack'] //@ownedViewpoints[name='Compartments']/@ownedRepresentations[name='Diag%20with%20HStack']/@defaultLayer/@containerMappings[name='HStack']/@subContainerMappings[name='FreeFormRegions']"> + <variable name="container"/> + <viewVariable name="containerView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EPackage" referenceName="eSubpackages"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'Init_p' + container.eSubpackages->size()"/> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C0"/> + </subModelOperations> + <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EClass" referenceName="eClassifiers" variableName="newClass"> + <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="Left_C1"/> + </subModelOperations> + </subModelOperations> + </firstModelOperations> + </initialOperation> + </ownedTools> </toolSections> </defaultLayer> </ownedRepresentations> diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/ICompartmentTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/ICompartmentTests.java index 413d20ace9..ab4321183e 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/ICompartmentTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/compartment/ICompartmentTests.java @@ -57,10 +57,28 @@ public interface ICompartmentTests { public static final String NEW_REGION_CONTAINER_NAME = "p3"; + public static final String NEW_REGION_CONTAINER_WITH_DEFINED_SIZE_NAME = "Init_p3"; + + public static final String PACKAGE_CREATION_DEFINED_SIZE_TOOL_NAME = "EPackageWithDefinedSize"; + + public static final String PACKAGE_CREATION_HIDE_LABEL_TOOL_NAME = "EPackageWithHideLabel"; + + public static final String PACKAGE_ONE_CLASS_CREATION_TOOL_NAME = "OneClassInEPackage"; + + public static final String PACKAGE_TWO_CLASS_CREATION_TOOL_NAME = "TwoClassesInEPackage"; + + public static final String PACKAGE_ONE_CLASS_CREATION_WITH_DEFINED_SIZE_TOOL_NAME = "OneClassInEPackageWithDefinedSize"; + + public static final String PACKAGE_TWO_CLASS_CREATION_WITH_DEFINED_SIZE_TOOL_NAME = "TwoClassesInEPackageWithDefinedSize"; + public static final String LEFT_CLASS_NAME = "Left_class1"; public static final String LEFT_CLASS2_NAME = "Left_class2"; + public static final String LEFT_CLASS_C0_NAME = "Left_C0"; + + public static final String LEFT_CLASS_C1_NAME = "Left_C1"; + public static final String CENTER_CLASS_NAME = "Center_class2"; public static final String RIGHT_CLASS_NAME = "Right_class3"; diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/AbstractCompartmentTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/AbstractCompartmentTest.java index 9031abd47e..b2ef03d7a1 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/AbstractCompartmentTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/AbstractCompartmentTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2016 Obeo. * 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 @@ -68,7 +68,7 @@ public abstract class AbstractCompartmentTest extends AbstractSiriusSwtBotGefTes * the representation instance name */ protected void openRepresentation(String representationName, String representationInstanceName) { - editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), representationName, representationInstanceName, DDiagram.class); + editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), representationName, representationInstanceName, DDiagram.class, true, true); } /** diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/CompartmentsCreationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/CompartmentsCreationTest.java index d4da9a1971..42ca5e0d34 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/CompartmentsCreationTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/compartment/CompartmentsCreationTest.java @@ -18,6 +18,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Insets; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.ecore.EObject; @@ -28,7 +29,10 @@ import org.eclipse.emf.edit.provider.ComposedAdapterFactory; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl; +import org.eclipse.gef.LayerConstants; +import org.eclipse.gef.editparts.LayerManager; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.handles.CompartmentCollapseHandle; import org.eclipse.gmf.runtime.notation.LayoutConstraint; import org.eclipse.gmf.runtime.notation.Location; import org.eclipse.gmf.runtime.notation.Node; @@ -45,9 +49,12 @@ import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramElementContain import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNodeEditPart; import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeListElementEditPart; +import org.eclipse.sirius.diagram.ui.tools.api.layout.LayoutUtils; import org.eclipse.sirius.ecore.extender.tool.api.ModelUtils; +import org.eclipse.sirius.tests.swtbot.support.api.condition.CheckEditPartResized; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; +import org.eclipse.swtbot.swt.finder.waits.ICondition; import org.eclipse.ui.PlatformUI; /** @@ -59,6 +66,162 @@ import org.eclipse.ui.PlatformUI; */ public class CompartmentsCreationTest extends AbstractCompartmentTest { + /** Location where the end-user click to create a container. */ + private static final Point CONTAINER_CREATION_LOCATION = new Point(400, 300); + + /** + * Location used with the first one, {{@link #CONTAINER_CREATION_LOCATION}, + * to draw a rectangle for the creation of the container. + */ + private static final Point CONTAINER_SECOND_CREATION_LOCATION = new Point(600, 500); + + /** Location of the first region. */ + private static final Point ORIGIN_LOCATION = new Point(0, 0); + + /** Auto sized dimension */ + private static final Dimension DIM_AUTO_SIZED = new Dimension(-1, -1); + + // CONTAINER WITH {-1, -1} as computation expressions + + /** Bounds of a container with computation expression equal to -1. */ + private static final Rectangle CONTAINER_BOUNDS_AUTO_SIZED = new Rectangle(CONTAINER_CREATION_LOCATION, DIM_AUTO_SIZED); + + /** + * Bounds of a HStack container with computation expression equal to -1, but + * created directly with one region: the size is increased to allow the + * auto-sized region. + */ + private static final Rectangle CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_VSTACK = new Rectangle(CONTAINER_CREATION_LOCATION, new Dimension(74, 78)); + + /** + * Bounds of a container with computation expression equal to -1, but + * created directly with two regions. Same size as one region but plus the + * NEW_DEFAULT_CONTAINER_DIMENSION in height. + */ + private static final Rectangle CONTAINER_BOUNDS_AUTO_SIZED_WITH_TWO_REGIONS_VSTACK = CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_VSTACK.getCopy() + .setHeight(CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_VSTACK.height + LayoutUtils.NEW_DEFAULT_CONTAINER_DIMENSION.height); + + /** + * Bounds of a VStack container with computation expression equal to -1, but + * created directly with one region: the size is increased to allow the + * auto-sized region. + */ + private static final Rectangle CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_HSTACK = new Rectangle(CONTAINER_CREATION_LOCATION, new Dimension(72, 76)); + + /** + * Bounds of a container with computation expression equal to -1 and without + * label. + */ + private static final Rectangle CONTAINER_BOUNDS_DEFAULT_SIZE = new Rectangle(CONTAINER_CREATION_LOCATION, LayoutUtils.NEW_DEFAULT_CONTAINER_DIMENSION); + + /** + * GMF bounds of the first region in a VStack container with computation + * expression equal to -1. + */ + private static final Rectangle REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED = new Rectangle(ORIGIN_LOCATION, DIM_AUTO_SIZED); + + /** + * GMF bounds of the second region in a VStack container with computation + * expression equal to -1. + */ + private static final Rectangle REGION_BOUNDS_SECOND_AUTO_SIZED_VSTACK = REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED.getTranslated(0, LayoutUtils.NEW_DEFAULT_CONTAINER_DIMENSION.height); + + /** + * GMF bounds of the second region in a VStack container with computation + * expression equal to -1. + */ + private static final Rectangle REGION_BOUNDS_SECOND_AUTO_SIZED_HSTACK = REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED.getTranslated(LayoutUtils.NEW_DEFAULT_CONTAINER_DIMENSION.width, 0); + + /** + * Draw2D bounds of the first region in a VStack container with computation + * expression equal to -1. + */ + private static final Rectangle REGION_BOUNDS_FIRST_DRAW2D = new Rectangle(ORIGIN_LOCATION, new Dimension(62, LayoutUtils.NEW_DEFAULT_CONTAINER_DIMENSION.height)); + + /** + * Draw2D bounds of the second region in a VStack container with computation + * expression equal to -1. + */ + private static final Rectangle REGION_BOUNDS_SECOND_DRAW2D_VSTACK = REGION_BOUNDS_FIRST_DRAW2D.getTranslated(0, LayoutUtils.NEW_DEFAULT_CONTAINER_DIMENSION.height); + + /** + * Draw2D bounds of the second region in a HStack container with computation + * expression equal to -1. + */ + private static final Rectangle REGION_BOUNDS_SECOND_DRAW2D_HSTACK = REGION_BOUNDS_FIRST_DRAW2D.getTranslated(REGION_BOUNDS_FIRST_DRAW2D.width, 0); + + /** + * Bounds of a container with computation expression equal to -1, but + * created directly with two regions. Same size as one region but plus the + * size of the second region in width. + */ + private static final Rectangle CONTAINER_BOUNDS_AUTO_SIZED_WITH_TWO_REGIONS_HSTACK = CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_HSTACK.getCopy() + .setWidth(CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_HSTACK.width + REGION_BOUNDS_SECOND_DRAW2D_HSTACK.width); + + // CONTAINER DRAWN AT CREATION (with a size of 200x200} + + /** + * Dimension corresponding to the rectangle drawn during creation. The + * dimension is expanded by {1x1} because of a bug that be fixed later. + */ + private static final Dimension DIM_DRAWN_SIZE = CONTAINER_SECOND_CREATION_LOCATION.getDifference(CONTAINER_CREATION_LOCATION).expand(1, 1); + + /** + * Bounds of a container initialized by the end-user at the creation with a + * rectangle of {200x200}. + */ + private static final Rectangle CONTAINER_BOUNDS_DRAWN = new Rectangle(CONTAINER_CREATION_LOCATION, DIM_DRAWN_SIZE); + + /** Bounds of the first region in a drawn VStack container. */ + private static final Rectangle REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER = new Rectangle(ORIGIN_LOCATION, new Dimension(189, 163)); + + /** Bounds of the first region in a drawn HStack container. */ + private static final Rectangle REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER = new Rectangle(ORIGIN_LOCATION, new Dimension(191, 165)); + + /** Bounds of the first region in a drawn HStack container. */ + private static final Rectangle REGION_BOUNDS_FIRST_IN_DRAWN_HSTACK_CONTAINER = REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER.getCopy().setWidth(REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER.width / 2); + + /** + * Bounds of the second region in a drawn VStack container. The same as the + * first but shift of the width of the first and plus one pixel for the + * separator. + */ + private static final Rectangle REGION_BOUNDS_SECOND_IN_DRAWN_HSTACK_CONTAINER = REGION_BOUNDS_FIRST_IN_DRAWN_HSTACK_CONTAINER.getTranslated(REGION_BOUNDS_FIRST_IN_DRAWN_HSTACK_CONTAINER.width, 0) + .expand(new Insets(0, 0, 0, 1)); + + // CONTAINER WITH COMPUTATION EXPRESSIONS EQUAL TO 8 + + /** Dimension corresponding to computation expressions equal to 8. */ + private static final Dimension DIM_80_DEFINED_SIZE = new Dimension(8 * LayoutUtils.SCALE, 8 * LayoutUtils.SCALE); + + /** + * Dimension corresponding to computation expressions equal to 8 and 2 + * regions. The container is increased in height because the 2 regions are + * higher than the free container space. + */ + private static final Dimension DIM_80_DEFINED_SIZE_WITH_2_REGIONS = new Dimension(8 * LayoutUtils.SCALE, 93); + + /** Bounds of a container with computation expression equal to 8. */ + private static final Rectangle CONTAINER_BOUNDS_80_FIXED_SIZE = new Rectangle(CONTAINER_CREATION_LOCATION, DIM_80_DEFINED_SIZE); + + /** + * Bounds of a container with computation expressions equal to 8 and 2 + * regions. + */ + private static final Rectangle CONTAINER_BOUNDS_80_FIXED_SIZE_WITH_2_REGIONS = new Rectangle(CONTAINER_CREATION_LOCATION, DIM_80_DEFINED_SIZE_WITH_2_REGIONS); + + /** + * Bounds of the first region in a VStack container computation expressions + * equal to 8. + */ + private static final Rectangle REGION_BOUNDS_IN_VSTACK_CONTAINER_80_FIXED_SIZE = new Rectangle(ORIGIN_LOCATION, new Dimension(68, 42)); + + /** + * Bounds of the first region in a VStack container computation expressions + * equal to 8. + */ + private static final Rectangle REGION_BOUNDS_IN_HSTACK_CONTAINER_80_FIXED_SIZE = new Rectangle(ORIGIN_LOCATION, new Dimension(70, 44)); + private String oldFont; /** @@ -99,6 +262,7 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { private void childrenPresentationTest(String representationName, String representationInstanceName, ContainerLayout initialContainerLayout) { openRepresentation(representationName, representationInstanceName); + editor.maximize(); ContainerMapping rcMapping = getActualMapping(FIRST_REGION_CONTAINER_NAME); checkChildrenPresentation(FIRST_REGION_CONTAINER_NAME, rcMapping, initialContainerLayout); @@ -159,6 +323,7 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { private void doTestContainerListCreation(String representationName, String representationInstanceName) { openRepresentation(representationName, representationInstanceName); + editor.maximize(); createElement(CLASS_LIST_CREATION_TOOL_NAME, FIRST_REGION_CONTAINER_NAME); checkElement(NEW_CLASS_LIST_4_NAME, FIRST_REGION_CONTAINER_NAME, CLASS_LIST_CREATION_TOOL_NAME); } @@ -176,11 +341,13 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { * created. */ public void testCompartmentCreationInVerticalStack() { - compartmentCreationTest(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME, new Point(400, 300)); + compartmentCreationTest(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME, CONTAINER_CREATION_LOCATION); } private void compartmentCreationTest(String representationName, String representationInstanceName, Point regionContainerLocation) { openRepresentation(representationName, representationInstanceName); + editor.maximize(); + createRegionContainerDiagram(PACKAGE_CREATION_TOOL_NAME, regionContainerLocation); checkRegionContainerInDiagram(NEW_REGION_CONTAINER_NAME); @@ -214,6 +381,7 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { private void doTestNodeCreationInFreeFormContainer(String representationName, String representationInstanceName) { openRepresentation(representationName, representationInstanceName); + editor.maximize(); createElement(CLASS_NODE_CREATION_TOOL_NAME, LEFT_PKG_NAME); checkElement(NEW_CLASS_1_NAME, LEFT_PKG_NAME, CLASS_NODE_CREATION_TOOL_NAME); } @@ -238,6 +406,7 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { private void doTestItemCreationInListContainer(String representationName, String representationInstanceName) { openRepresentation(representationName, representationInstanceName); + editor.maximize(); createElement(ATTRIBUTE_CREATION_TOOL_NAME, RIGHT_CLASS_NAME); checkElement(NEW_ATTRIBUTE_NAME, RIGHT_CLASS_NAME, ATTRIBUTE_CREATION_TOOL_NAME); } @@ -246,14 +415,15 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { * Create a new node using the defined Node Creation tool, at the given * position. * - * @param CREATION_TOOL_NAME - * Tool name to select + * @param creationToolName + * Name of the tool to use to create the new element * @param targetEditPartName - * The target edit part name + * The name of the target edit part (container of the new + * element) */ - private void createElement(String CREATION_TOOL_NAME, String targetEditPartName) { + private void createElement(String creationToolName, String targetEditPartName) { // Select the tool - editor.activateTool(CREATION_TOOL_NAME); + editor.activateTool(creationToolName); // Click in the target edit part to create element on it editor.click(targetEditPartName); } @@ -379,6 +549,7 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { */ public void testCreationOfNewHorizontalRegionContainerOutsideEditor() throws Exception { openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); @@ -406,6 +577,7 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { */ public void testCreationOfNewVerticalRegionContainerOutsideEditor() throws Exception { openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); @@ -422,10 +594,6 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { checkBounds("aaa", new Rectangle(0, 80, 154, 40), currentDraw2DBounds); } - private void checkSize(String label, Dimension expectedGmfSize, Dimension expectedFigureSize) { - checkBounds(label, new Rectangle(0, 0, expectedGmfSize.width(), expectedGmfSize.height()), new Rectangle(0, 0, expectedFigureSize.width(), expectedFigureSize.height()), true); - } - /** * Check the GMF and Draw2d bounds (or size) of the edit part with given * <code>label</code>. @@ -438,7 +606,7 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { * The expected draw2d bounds, if the width or height is equals * to -1, we ignore it. * - * @return The current Draw2d bounds + * @return A copy of the current Draw2d bounds */ private Rectangle checkBounds(String label, Rectangle expectedGmfBounds, Rectangle expectedFigureBounds) { return checkBounds(label, expectedGmfBounds, expectedFigureBounds, false); @@ -459,13 +627,37 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { * true if only the size must be check (and not the location), * false otherwise. * - * @return The current Draw2d bounds + * @return A copy of the current Draw2d bounds */ private Rectangle checkBounds(String label, Rectangle expectedGmfBounds, Rectangle expectedFigureBounds, boolean onlyCheckSize) { return checkBounds(label, expectedGmfBounds, expectedFigureBounds, onlyCheckSize, 0, 0); } /** + * Check the GMF and Draw2d bounds (or size) of the edit part with given + * <code>label</code>. + * + * @param label + * The label of the edit part to check + * @param expectedGmfBounds + * The expected GMF bounds + * @param expectedFigureBounds + * The expected draw2d bounds, if the width or height is equals + * to -1, we ignore it. + * @param widthDelta + * The width delta to consider the width as equal (because of + * font size that can be slightly different on each OS). + * @param heightDelta + * The height delta to consider the height as equal (because of + * font size that can be slightly different on each OS). + * + * @return A copy of the current Draw2d bounds + */ + private Rectangle checkBounds(String label, Rectangle expectedGmfBounds, Rectangle expectedFigureBounds, int widthDelta, int heightDelta) { + return checkBounds(label, expectedGmfBounds, expectedFigureBounds, false, widthDelta, heightDelta); + } + + /** * Check that the bounds (GMF and Draw2D) are as expected. * * @param label @@ -482,10 +674,13 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { * false otherwise. * @param widthDelta The width delta to * consider the width as equal (because of font size that can be * slightly different on each OS). + * @param widthDelta + * The width delta to consider the width as equal (because of + * font size that can be slightly different on each OS). * @param heightDelta * The height delta to consider the height as equal (because of * font size that can be slightly different on each OS). - * @return the current DrawD2 bounds + * @return A copy of the current DrawD2 bounds */ private Rectangle checkBounds(String label, Rectangle expectedGmfBounds, Rectangle expectedFigureBounds, boolean onlyCheckSize, int widthDelta, int heightDelta) { SWTBotGefEditPart swtBotEditPart = editor.getEditPart(label, AbstractDiagramElementContainerEditPart.class); @@ -494,7 +689,13 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { IFigure mainFigure = editPart.getMainFigure(); if (onlyCheckSize) { - assertEquals("Wrong GMF size for " + label, expectedGmfBounds.getSize(), getBounds((Node) editPart.getNotationView()).getSize()); + if (widthDelta == 0 && heightDelta == 0) { + assertEquals("Wrong GMF size for " + label, expectedGmfBounds.getSize(), getBounds((Node) editPart.getNotationView()).getSize()); + } else { + Dimension gmfSize = getBounds((Node) editPart.getNotationView()).getSize(); + assertEquals("Wrong GMF width for " + label, expectedGmfBounds.width(), gmfSize.width(), widthDelta); + assertEquals("Wrong GMF height for " + label, expectedGmfBounds.height(), gmfSize.height(), heightDelta); + } if (expectedFigureBounds.width() != -1 && expectedFigureBounds.height() != -1) { if (widthDelta == 0 && heightDelta == 0) { assertEquals("Wrong Draw2D size for " + label, expectedFigureBounds.getSize(), mainFigure.getBounds().getSize()); @@ -511,7 +712,14 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { } } } else { - assertEquals("Wrong GMF bounds for " + label, expectedGmfBounds, getBounds((Node) editPart.getNotationView())); + if (widthDelta == 0 && heightDelta == 0) { + assertEquals("Wrong GMF bounds for " + label, expectedGmfBounds, getBounds((Node) editPart.getNotationView())); + } else { + Rectangle gmfBounds = getBounds((Node) editPart.getNotationView()); + assertEquals("Wrong GMF location for " + label, expectedGmfBounds.getLocation(), gmfBounds.getLocation()); + assertEquals("Wrong GMF width for " + label, expectedGmfBounds.width(), gmfBounds.width(), widthDelta); + assertEquals("Wrong GMF height for " + label, expectedGmfBounds.height(), gmfBounds.height(), heightDelta); + } if (expectedFigureBounds.width() != -1 && expectedFigureBounds.height() != -1) { if (widthDelta == 0 && heightDelta == 0) { assertEquals("Wrong Draw2D bounds for " + label, expectedFigureBounds, mainFigure.getBounds()); @@ -531,7 +739,78 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { } } } - return (Rectangle) mainFigure.getBounds(); + return (Rectangle) mainFigure.getBounds().getCopy(); + } + + /** + * Check the GMF and Draw2d bounds (or size) of the edit part under the + * given <code>point</code>. + * + * @param point + * A point on the edit part to check + * @param expectedGmfBounds + * The expected GMF bounds + * @param expectedFigureBounds + * The expected draw2d bounds, if the width or height is equals + * to -1, we ignore it. + * @param onlyCheckSize + * true if only the size must be check (and not the location), + * false otherwise. + * + * @return A copy of the current Draw2d bounds + */ + private Rectangle checkBoundsWithPosition(Point point, Rectangle expectedGmfBounds, Rectangle expectedFigureBounds, boolean onlyCheckSize) { + SWTBotGefEditPart swtBotEditPart = editor.getEditPart(point, AbstractDiagramElementContainerEditPart.class); + AbstractDiagramElementContainerEditPart editPart = (AbstractDiagramElementContainerEditPart) swtBotEditPart.part(); + + IFigure mainFigure = editPart.getMainFigure(); + + if (onlyCheckSize) { + assertEquals("Wrong GMF size for figure at position " + point, expectedGmfBounds.getSize(), getBounds((Node) editPart.getNotationView()).getSize()); + if (expectedFigureBounds.width() != -1 && expectedFigureBounds.height() != -1) { + assertEquals("Wrong Draw2D size for figure at position " + point, expectedFigureBounds.getSize(), mainFigure.getBounds().getSize()); + } else { + if (expectedFigureBounds.width() != -1) { + assertEquals("Wrong Draw2D width for figure at position " + point, expectedFigureBounds.width(), mainFigure.getBounds().width()); + } + if (expectedFigureBounds.height() != -1) { + assertEquals("Wrong Draw2D height for figure at position " + point, expectedFigureBounds.height(), mainFigure.getBounds().height()); + } + } + } else { + assertEquals("Wrong GMF bounds for figure at position " + point, expectedGmfBounds, getBounds((Node) editPart.getNotationView())); + if (expectedFigureBounds.width() != -1 && expectedFigureBounds.height() != -1) { + assertEquals("Wrong Draw2D bounds for figure at position " + point, expectedFigureBounds, mainFigure.getBounds()); + } else { + assertEquals("Wrong Draw2D x for figure at position " + point, expectedFigureBounds.x(), mainFigure.getBounds().x()); + assertEquals("Wrong Draw2D y for figure at position " + point, expectedFigureBounds.y(), mainFigure.getBounds().y()); + if (expectedFigureBounds.width() != -1) { + assertEquals("Wrong Draw2D width for figure at position " + point, expectedFigureBounds.width(), mainFigure.getBounds().width()); + } + if (expectedFigureBounds.height() != -1) { + assertEquals("Wrong Draw2D height for figure at position " + point, expectedFigureBounds.height(), mainFigure.getBounds().height()); + } + } + } + return (Rectangle) mainFigure.getBounds().getCopy(); + } + + /** + * Check the GMF and Draw2d bounds of the edit part under the given + * <code>point</code>. + * + * @param point + * A point on the edit part to check + * @param expectedGmfBounds + * The expected GMF bounds + * @param expectedFigureBounds + * The expected draw2d bounds, if the width or height is equals + * to -1, we ignore it. + * + * @return A copy of the current Draw2d bounds + */ + private Rectangle checkBounds(Point point, Rectangle expectedGmfBounds, Rectangle expectedFigureBounds) { + return checkBoundsWithPosition(point, expectedGmfBounds, expectedFigureBounds, false); } private Rectangle getBounds(Node notationView) { @@ -590,4 +869,562 @@ public class CompartmentsCreationTest extends AbstractCompartmentTest { Job.getJobManager().join(ResourceSyncClientNotifier.FAMILY, new NullProgressMonitor()); } } + + /** + * Test creation of regions container with vertical stack and with no + * region. Check auto-size gmf size for container (because of computation + * expressions equal to -1). + */ + public void testCreationOfNewVerticalRegionContainerWithoutRegion() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagram(PACKAGE_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, new Rectangle(CONTAINER_CREATION_LOCATION, new Dimension(44, 49)), 0, 1); + } + + /** + * Test creation of regions container with vertical stack and which contains + * one region. Check auto-size gmf size for container and region (because of + * computation expressions equal to -1). + */ + public void testCreationOfNewVerticalRegionContainerWithOneRegion() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_ONE_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_VSTACK, 0, 1); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED, REGION_BOUNDS_FIRST_DRAW2D); + } + + /** + * Test creation of regions container with vertical stack which contains two + * regions. Check auto-size gmf size for container and regions (because of + * computation expressions equal to -1). + */ + public void testCreationOfNewVerticalRegionContainerWithTwoRegions() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_TWO_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_AUTO_SIZED_WITH_TWO_REGIONS_VSTACK, 0, 1); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED, REGION_BOUNDS_FIRST_DRAW2D); + checkBounds(LEFT_CLASS_C1_NAME, REGION_BOUNDS_SECOND_AUTO_SIZED_VSTACK, REGION_BOUNDS_SECOND_DRAW2D_VSTACK); + } + + /** + * Test creation of regions container with vertical stack and defined size + * for the container. Check specific size (gmf and Draw2D) for container + * because of specific computation expressions. + */ + public void testCreationOfNewVerticalRegionContainerWithDefinedSize() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagram(PACKAGE_CREATION_DEFINED_SIZE_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_WITH_DEFINED_SIZE_NAME, CONTAINER_BOUNDS_80_FIXED_SIZE, CONTAINER_BOUNDS_80_FIXED_SIZE); + } + + /** + * Test creation of regions container with vertical stack. The container has + * a defined size and contains one region. Check specific size for region, + * auto-size gmf size and specific draw2D size for container. + */ + public void testCreationOfNewVerticalRegionContainerWithDefinedSizeAndOneRegion() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_ONE_CLASS_CREATION_WITH_DEFINED_SIZE_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_WITH_DEFINED_SIZE_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_80_FIXED_SIZE); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_IN_VSTACK_CONTAINER_80_FIXED_SIZE, REGION_BOUNDS_IN_VSTACK_CONTAINER_80_FIXED_SIZE, 0, 1); + } + + /** + * Test creation of regions container with vertical stack. The container has + * a defined size and contains two regions. Check specific size for regions, + * auto-size gmf size for container. Draw2D height size for container is + * changed because the two regions need a higher container (the size + * increase in direction of the stack). + */ + public void testCreationOfNewVerticalRegionContainerWithDefinedSizeAndTwoRegions() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_TWO_CLASS_CREATION_WITH_DEFINED_SIZE_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + // The GMF bounds are not consistent with draw2d bounds as the container + // is too small for two regions. The draw2d is increased. Add 3 as + // height delta (1 pixel per text line). + checkBounds(NEW_REGION_CONTAINER_WITH_DEFINED_SIZE_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_80_FIXED_SIZE_WITH_2_REGIONS, 0, 3); + Rectangle firstRegionGMFBounds = REGION_BOUNDS_IN_VSTACK_CONTAINER_80_FIXED_SIZE.getCopy().setHeight(REGION_BOUNDS_IN_VSTACK_CONTAINER_80_FIXED_SIZE.height / 2); + // TODO: Inconsistency between GMF size and Draw2D size. The GMF height + // is computed from the initial container height (half of space for + // regions == 21). But the minimal draw2d needed space is more. This can + // be considered as a bug, but it can occurs only is the specifier + // defines a container too small for containing its regions. + Rectangle firstRegionD2DBounds = REGION_BOUNDS_IN_VSTACK_CONTAINER_80_FIXED_SIZE.getCopy().setHeight(27); + Rectangle realFirstRegionD2DBounds = checkBounds(LEFT_CLASS_C0_NAME, firstRegionGMFBounds, firstRegionD2DBounds, 0, 1); + // The second is the same but shift after the first and with one more + // pixel for the separator (the location is not checked as it depends on + // the first region size that depends on Font). + checkBounds(LEFT_CLASS_C1_NAME, firstRegionGMFBounds.getTranslated(0, firstRegionGMFBounds.height), + realFirstRegionD2DBounds.getTranslated(0, realFirstRegionD2DBounds.height).expand(new Insets(0, 0, 1, 0)), true, 0, 1); + } + + /** + * Test creation of regions container with vertical stack and end-user + * defined size. Check specific size (gmf and Draw2D) of the container + * (match with rectangle draw). + */ + public void testCreationOfNewVerticalRegionContainerWithoutRegionAndRectangleDraw() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_DRAWN, CONTAINER_BOUNDS_DRAWN); + } + + /** + * Test creation of regions container with vertical stack which contains one + * region and end-user defined size. Check specific size for region, + * auto-size gmf size and specific Draw2D size for container. + */ + public void testCreationOfNewVerticalRegionContainerWithOneRegionAndRectangleDraw() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_ONE_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DRAWN); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER, REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER, 0, 1); + } + + /** + * Test creation of regions container with vertical stack which contains two + * regions and end-user defined size. Check specific size for regions, + * auto-size gmf size for container. + */ + public void testCreationOfNewVerticalRegionContainerWithTwoRegionsAndRectangleDraw() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_TWO_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DRAWN); + Rectangle firstRegionBounds = REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER.getCopy().setHeight(REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER.height / 2); + checkBounds(LEFT_CLASS_C0_NAME, firstRegionBounds, firstRegionBounds); + // The second is the same but shift after the first (plus one pixel for + // the separator). + Rectangle secondRegionBounds = firstRegionBounds.getTranslated(0, firstRegionBounds.height).setHeight(firstRegionBounds.height + 1); + checkBounds(LEFT_CLASS_C1_NAME, secondRegionBounds, secondRegionBounds, 0, 1); + } + + /** + * Test use of regions collapsed in container with vertical stack which + * contains two regions. Check auto-size gmf size for container and regions + * when collapsing. Height container must change because of collapsing. + */ + public void testCollapseOfNewVerticalRegionContainerWithTwoRegions() { + testCreationOfNewVerticalRegionContainerWithTwoRegions(); + + SWTBotGefEditPart editPartToResize = editor.getEditPart(NEW_REGION_CONTAINER_NAME, AbstractDiagramElementContainerEditPart.class); + ICondition editPartResizedCondition = new CheckEditPartResized(editPartToResize); + + // selection of the second region + editor.click(new Point(420, 400)); + + // collapse of the second region + editor.click(new Point(460, 380)); + + bot.waitUntil(editPartResizedCondition); + + // check collapse + int heightCollapseSize = 12; + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, + CONTAINER_BOUNDS_AUTO_SIZED_WITH_TWO_REGIONS_VSTACK.getCopy().setHeight(CONTAINER_BOUNDS_AUTO_SIZED_WITH_TWO_REGIONS_VSTACK.height - heightCollapseSize), 0, 3); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED, REGION_BOUNDS_FIRST_DRAW2D, 0, 1); + checkBounds(LEFT_CLASS_C1_NAME, REGION_BOUNDS_SECOND_AUTO_SIZED_VSTACK, REGION_BOUNDS_SECOND_DRAW2D_VSTACK.getCopy().setHeight(REGION_BOUNDS_SECOND_DRAW2D_VSTACK.height - heightCollapseSize), + 0, 1); + } + + /** + * Test creation of regions container with vertical stack and hide Label. + * Check auto-size gmf size for container (because of computation + * expressions equal to -1). + */ + public void testCreationOfNewVerticalRegionContainerWithoutRegionAndHideLabel() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagram(PACKAGE_CREATION_HIDE_LABEL_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(CONTAINER_CREATION_LOCATION, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DEFAULT_SIZE); + } + + /** + * Test resizing of new regions container with vertical stack which contains + * one region. Check specific size for region, auto-size gmf size and + * specific Draw2D size for container. + */ + public void testResizeOfNewVerticalRegionContainerWithOneRegionAndRectangleDraw() { + openRepresentation(VERTICAL_STACK_REPRESENTATION_NAME, VERTICAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_ONE_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + Rectangle realContainerBounds = checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DRAWN); + Rectangle realRegionBounds = checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER, REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER, 0, 1); + Dimension regionDelta = realRegionBounds.getSize().getShrinked(REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER.getSize()); + // Resize container + SWTBotGefEditPart editPartToResize = editor.getEditPart(NEW_REGION_CONTAINER_NAME, AbstractDiagramElementContainerEditPart.class); + editPartToResize.select(); + ICondition editPartResizedCondition = new CheckEditPartResized(editPartToResize); + editor.drag(realContainerBounds.getBottom(), realContainerBounds.getBottom().getTranslated(0, -60)); + bot.waitUntil(editPartResizedCondition); + + // Height bounds must decrease of 60 px because of resizing of 60 px. + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, realContainerBounds.getResized(0, -60)); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_IN_DRAWN_VSTACK_CONTAINER.getResized(0, -60).getResized(regionDelta), realRegionBounds.getResized(0, -60), 0, 1); + } + + /** + * Test creation of regions container with horizontal stack. Check auto-size + * gmf size for container (because of computation expressions equal to -1). + */ + public void testCreationOfNewHorizontalRegionContainerWithoutRegion() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagram(PACKAGE_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + // The D2D dimension is computed according to label size. + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, new Rectangle(CONTAINER_CREATION_LOCATION, new Dimension(42, 47)), 0, 1); + } + + /** + * Test creation of regions container with horizontal stack which contains + * one region. Check auto-size gmf size for container and region (because of + * computation expressions equal to -1). + */ + public void testCreationOfNewHorizontalRegionContainerWithOneRegion() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_ONE_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + // The D2D dimension is computed according to label size (of container + // and of region), the container is increased according to the first + // region size. + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_AUTO_SIZED_WITH_ONE_REGION_HSTACK, 0, 1); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED, REGION_BOUNDS_FIRST_DRAW2D); + } + + /** + * Test creation of regions container with horizontal stack which contains + * two regions. Check auto-size gmf size for container and regions (because + * of computation expressions equal to -1). + */ + public void testCreationOfNewHorizontalRegionContainerWithTwoRegions() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_TWO_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_AUTO_SIZED_WITH_TWO_REGIONS_HSTACK, 0, 1); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED, REGION_BOUNDS_FIRST_DRAW2D); + checkBounds(LEFT_CLASS_C1_NAME, REGION_BOUNDS_SECOND_AUTO_SIZED_HSTACK, REGION_BOUNDS_SECOND_DRAW2D_HSTACK); + } + + /** + * Test creation of regions container with horizontal stack and defined size + * for the container. Check specific size (gmf and Draw2D) for container + * because of specific computation expressions. + */ + public void testCreationOfNewHorizontalRegionContainerWithDefinedSize() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagram(PACKAGE_CREATION_DEFINED_SIZE_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_WITH_DEFINED_SIZE_NAME, CONTAINER_BOUNDS_80_FIXED_SIZE, CONTAINER_BOUNDS_80_FIXED_SIZE); + } + + /** + * Test creation of regions container with horizontal stack. The container + * has a defined size and contains one region. Check specific size for + * region, auto-size gmf size and specific draw2D size for container. + */ + public void testCreationOfNewHorizontalRegionContainerWithDefinedSizeAndOneRegion() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_ONE_CLASS_CREATION_WITH_DEFINED_SIZE_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_WITH_DEFINED_SIZE_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_80_FIXED_SIZE); + // All the free space. + Rectangle firstRegionBounds = REGION_BOUNDS_IN_HSTACK_CONTAINER_80_FIXED_SIZE; + checkBounds(LEFT_CLASS_C0_NAME, firstRegionBounds, firstRegionBounds, 0, 1); + } + + /** + * Test creation of regions container with horizontal stackThe container has + * a defined size and contains two regions. Check specific size for regions, + * auto-size gmf size for container. Draw2D height size for container must + * change because of addition of two regions size. + */ + public void testCreationOfNewHorizontalRegionContainerWithDefinedSizeAndTwoRegions() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagram(PACKAGE_TWO_CLASS_CREATION_WITH_DEFINED_SIZE_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_WITH_DEFINED_SIZE_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_80_FIXED_SIZE); + Rectangle firstRegionBounds = REGION_BOUNDS_IN_HSTACK_CONTAINER_80_FIXED_SIZE.getCopy().setWidth(REGION_BOUNDS_IN_HSTACK_CONTAINER_80_FIXED_SIZE.width / 2); + checkBounds(LEFT_CLASS_C0_NAME, firstRegionBounds, firstRegionBounds, 0, 1); + // The second is the same but shift after the first. + checkBounds(LEFT_CLASS_C1_NAME, firstRegionBounds.getTranslated(firstRegionBounds.width, 0), firstRegionBounds.getTranslated(firstRegionBounds.width, 0), 0, 1); + } + + /** + * Test creation of regions container with horizontal stack. Check defined + * size of the container (match with rectangle draw). + */ + public void testCreationOfNewHorizontalRegionContainerWithoutRegionAndRectangleDraw() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_DRAWN, CONTAINER_BOUNDS_DRAWN); + } + + /** + * Test creation of regions container with horizontal stack which contains + * one region. Check specific size for region and auto-size gmf size and + * specific Draw2D size for container match with rectangle draw). + */ + public void testCreationOfNewHorizontalRegionContainerWithOneRegionAndRectangleDraw() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_ONE_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DRAWN); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER, REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER, 0, 1); + } + + /** + * Test creation of regions container with horizontal stack which contains + * two regions. Check specific size for regions, auto-size gmf size for + * container. + */ + public void testCreationOfNewHorizontalRegionContainerWithTwoRegionsAndRectangleDraw() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_TWO_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DRAWN); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_IN_DRAWN_HSTACK_CONTAINER, REGION_BOUNDS_FIRST_IN_DRAWN_HSTACK_CONTAINER, 0, 1); + // The second is the same but shift after the first. + checkBounds(LEFT_CLASS_C1_NAME, REGION_BOUNDS_SECOND_IN_DRAWN_HSTACK_CONTAINER, REGION_BOUNDS_SECOND_IN_DRAWN_HSTACK_CONTAINER, 0, 1); + } + + /** + * Test use of regions collapsed in container with horizontal stack which + * contains two regions. Check specific size for regions, auto-size gmf size + * for container when collapsing. Container size (gmf or Draw2D) must not + * change because nothing has been collapse (regions are already + * auto-sized). + */ + public void testCollapseOfNewHorizontalRegionContainerWithTowRegions() { + testCreationOfNewHorizontalRegionContainerWithTwoRegions(); + + // selection of the second region + editor.click(new Point(470, 360)); + + // collapse of the second region + editor.click(new Point(520, 338)); + + // check collapse + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_AUTO_SIZED_WITH_TWO_REGIONS_HSTACK, 0, 1); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_DRAW2D_AUTO_SIZED, REGION_BOUNDS_FIRST_DRAW2D); + checkBounds(LEFT_CLASS_C1_NAME, REGION_BOUNDS_SECOND_AUTO_SIZED_HSTACK, REGION_BOUNDS_SECOND_DRAW2D_HSTACK); + } + + /** + * Test use of regions collapsed in container with horizontal stack which + * contains two regions. Check specific size for regions, auto-size gmf size + * for container when collapsing. Container size (gmf or Draw2D) must not + * change. Second region is collapsed so container width change. + */ + public void testCollapseOfNewHorizontalRegionContainerWithTowRegionsAndRectangleDraw() { + testCreationOfNewHorizontalRegionContainerWithTwoRegionsAndRectangleDraw(); + + SWTBotGefEditPart editPartToResize = editor.getEditPart(NEW_REGION_CONTAINER_NAME, AbstractDiagramElementContainerEditPart.class); + ICondition editPartResizedCondition = new CheckEditPartResized(editPartToResize); + + // selection of the second region + editor.click(new Point(540, 420)); + + // collapse of the second region + // Retrieve the toggle figure location (to click on it) + SWTBotGefEditPart swtBotEditPart = editor.getEditPart(LEFT_CLASS_C1_NAME, AbstractDiagramElementContainerEditPart.class); + AbstractDiagramElementContainerEditPart editPart = (AbstractDiagramElementContainerEditPart) swtBotEditPart.part(); + IFigure handleLayer = LayerManager.Helper.find(editPart).getLayer(LayerConstants.HANDLE_LAYER); + Point toggleFigureLocation = new Point(585, 340); + if (handleLayer != null) { + for (Object figure : handleLayer.getChildren()) { + if (figure instanceof CompartmentCollapseHandle) { + toggleFigureLocation = ((CompartmentCollapseHandle) figure).getLocation(); + // Use the center of the figure + Dimension size = ((CompartmentCollapseHandle) figure).getSize(); + toggleFigureLocation.translate(size.width / 2, size.height / 2); + + } + } + } + editor.click(toggleFigureLocation); + + bot.waitUntil(editPartResizedCondition); + + // check collapse + int widthCollapseSize = 34; + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DRAWN.getCopy().setWidth(CONTAINER_BOUNDS_DRAWN.width - widthCollapseSize)); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_FIRST_IN_DRAWN_HSTACK_CONTAINER, REGION_BOUNDS_FIRST_IN_DRAWN_HSTACK_CONTAINER, 0, 1); + // TODO: For HStack, when collapsing the last region, its width is set + // to -1. But for VStack, in same scenario, its height is not set to -1. + // Why? + checkBounds(LEFT_CLASS_C1_NAME, REGION_BOUNDS_SECOND_IN_DRAWN_HSTACK_CONTAINER.getCopy().setWidth(-1), + REGION_BOUNDS_SECOND_IN_DRAWN_HSTACK_CONTAINER.getCopy().setWidth(REGION_BOUNDS_SECOND_IN_DRAWN_HSTACK_CONTAINER.width - widthCollapseSize), 0, 1); + } + + /** + * Test creation of regions container with horizontal stack and Hide label. + * Check auto-size gmf size for container (because of computation + * expressions equal to -1). + */ + public void testCreationOfNewHorizontalRegionContainerWithoutRegionAndHideLabel() { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container without region + createRegionContainerDiagram(PACKAGE_CREATION_HIDE_LABEL_TOOL_NAME, CONTAINER_CREATION_LOCATION); + + checkBounds(CONTAINER_CREATION_LOCATION, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DEFAULT_SIZE); + } + + /** + * Test creation of regions container with horizontal stack which contains + * one region and then resizing the container. Check specific size for + * region and auto-size gmf size and specific Draw2D size for container + * match with rectangle draw). + * + * @throws Exception + * In case of problem during semantic modification outside the + * editor. + */ + public void testResizeOfNewHorizontalRegionContainerWithOneRegionAndRectangleDraw() throws Exception { + openRepresentation(HORIZONTAL_STACK_REPRESENTATION_NAME, HORIZONTAL_STACK_REPRESENTATION_INSTANCE_NAME); + editor.maximize(); + + assertEquals("Session should not be dirty.", SessionStatus.SYNC, localSession.getOpenedSession().getStatus()); + + // Create a new ePackage container with one region + createRegionContainerDiagramWithRectangleDraw(PACKAGE_ONE_CLASS_CREATION_TOOL_NAME, CONTAINER_CREATION_LOCATION, CONTAINER_SECOND_CREATION_LOCATION); + + Rectangle realContainerBounds = checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, CONTAINER_BOUNDS_DRAWN); + Rectangle realRegionBounds = checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER, REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER, 0, 1); + // Resize the container + SWTBotGefEditPart editPartToResize = editor.getEditPart(NEW_REGION_CONTAINER_NAME, AbstractDiagramElementContainerEditPart.class); + editPartToResize.select(); + ICondition editPartResizedCondition = new CheckEditPartResized(editPartToResize); + editor.drag(realContainerBounds.getRight(), realContainerBounds.getRight().getTranslated(-60, 0)); + bot.waitUntil(editPartResizedCondition); + + // Width bounds must decrease of 60px because of resizing of 60 px. + checkBounds(NEW_REGION_CONTAINER_NAME, CONTAINER_BOUNDS_AUTO_SIZED, realContainerBounds.getResized(-60, 0)); + checkBounds(LEFT_CLASS_C0_NAME, REGION_BOUNDS_IN_DRAWN_HSTACK_CONTAINER.getResized(-60, 0), realRegionBounds.getResized(-60, 0), 0, 1); + } + + /** + * Create a new node using the given tool directly in the diagram + * representation. + * + * @param CREATION_TOOL_NAME + * Tool name to select + */ + private void createRegionContainerDiagramWithRectangleDraw(String creationToolName, Point location, Point target) { + // Select the tool + editor.activateTool(creationToolName); + editor.drag(location, target); + } } |