Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2013-12-15 00:11:59 +0000
committerCedric Dumoulin2014-01-27 13:56:46 +0000
commit48dea20c06b16191c24e963ca22a934d2cacc9a6 (patch)
tree6c102d8aeb01a0a673b75d368c36f5564260ccc8 /extraplugins/layers/org.eclipse.papyrus.layers.stackmodel
parent88e03a4d73d0c4056455ccdd9b6513fc0b4471be (diff)
downloadorg.eclipse.papyrus-48dea20c06b16191c24e963ca22a934d2cacc9a6.tar.gz
org.eclipse.papyrus-48dea20c06b16191c24e963ca22a934d2cacc9a6.tar.xz
org.eclipse.papyrus-48dea20c06b16191c24e963ca22a934d2cacc9a6.zip
bug 330199 - Add LayerTreeEventNotifier; Allow LayerStack to init added
layers.
Diffstat (limited to 'extraplugins/layers/org.eclipse.papyrus.layers.stackmodel')
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore12
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.genmodel4
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation8
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml14
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayerExpression.java25
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayersPackage.java200
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/AbstractLayerImpl.java14
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionImpl.java43
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerOperatorImpl.java14
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersPackageImpl.java28
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersStackImpl.java58
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/ILayersTreeEventListener.java66
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifier.java197
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactory.java68
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionInitWithApplicationImplTest.java55
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactoryTest.java90
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierTest.java356
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceLayersModelEventListener.java69
18 files changed, 1294 insertions, 27 deletions
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore
index 34bcd7b9851..ab6ed143d62 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore
@@ -46,6 +46,18 @@
<eParameters name="view" ordered="false" lowerBound="1" eType="ecore:EClass ../../org.eclipse.gmf.runtime.notation/model/notation.ecore#//View"/>
<eParameters name="property" lowerBound="1" upperBound="-1" eType="#//Property"/>
</eOperations>
+ <eOperations name="initLayer" ordered="false" lowerBound="1">
+ <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
+ <details key="documentation" value="Method called to specify that this Layer should be initialized for the specified LayerStack.&#xD;&#xA;Init this Layer for the specified LayersStack."/>
+ </eAnnotations>
+ <eParameters name="owningLayersStack" ordered="false" lowerBound="1" eType="#//LayersStack"/>
+ </eOperations>
+ <eOperations name="getLayersStack" ordered="false" lowerBound="1" eType="#//LayersStack"
+ eExceptions="#//NotFoundException">
+ <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
+ <details key="documentation" value="A checked version of getOwningLayersStack.&#xD;&#xA;"/>
+ </eAnnotations>
+ </eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false" lowerBound="1"
eType="#//String"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="description" ordered="false"
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.genmodel b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.genmodel
index 2809efd471d..1d146539256 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.genmodel
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.genmodel
@@ -88,6 +88,10 @@
<genParameters xsi:type="genmodel:GenParameter" ecoreParameter="layers.ecore#//LayerExpression/getPropertiesComputePropertyValueCommand/view"/>
<genParameters xsi:type="genmodel:GenParameter" ecoreParameter="layers.ecore#//LayerExpression/getPropertiesComputePropertyValueCommand/property"/>
</genOperations>
+ <genOperations xsi:type="genmodel:GenOperation" ecoreOperation="layers.ecore#//LayerExpression/initLayer">
+ <genParameters xsi:type="genmodel:GenParameter" ecoreParameter="layers.ecore#//LayerExpression/initLayer/owningLayersStack"/>
+ </genOperations>
+ <genOperations xsi:type="genmodel:GenOperation" ecoreOperation="layers.ecore#//LayerExpression/getLayersStack"/>
</genClasses>
<genClasses xsi:type="genmodel:GenClass" image="false" ecoreClass="layers.ecore#//ApplicationDependantElement">
<genFeatures xsi:type="genmodel:GenFeature" notify="false" createChild="false"
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation
index bbb74042bd1..e69e0aed413 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation
@@ -1042,6 +1042,14 @@
<element xmi:type="uml:Operation" href="layers.uml#_x2PfUO7HEeK0p4PkXjd-_Q"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_fO4GIe7IEeK0p4PkXjd-_Q" x="93" y="23"/>
</children>
+ <children xmi:type="notation:Shape" xmi:id="_Ps2L4WUaEeOlpfB_tZS-QA" type="3013" fontName="Segoe UI" lineColor="0">
+ <element xmi:type="uml:Operation" href="layers.uml#_Ps2L4GUaEeOlpfB_tZS-QA"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Ps2L4mUaEeOlpfB_tZS-QA"/>
+ </children>
+ <children xmi:type="notation:Shape" xmi:id="_kzSSwWUdEeOlpfB_tZS-QA" type="3013" fontName="Segoe UI" lineColor="0">
+ <element xmi:type="uml:Operation" href="layers.uml#_kzSSwGUdEeOlpfB_tZS-QA"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_kzSSwmUdEeOlpfB_tZS-QA"/>
+ </children>
<styles xmi:type="notation:TitleStyle" xmi:id="_9IyaiNjiEeKQqZMBCFd2Uw"/>
<styles xmi:type="notation:SortingStyle" xmi:id="_9IyaidjiEeKQqZMBCFd2Uw"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_9IyaitjiEeKQqZMBCFd2Uw"/>
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml
index 5b5e1cdddd2..1aa62fe98bc 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml
@@ -595,6 +595,20 @@ Setting the value of this node set the value of the subnodes.</body>
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_cpKoIO7IEeK0p4PkXjd-_Q" value="*"/>
</ownedParameter>
</ownedOperation>
+ <ownedOperation xmi:type="uml:Operation" xmi:id="_Ps2L4GUaEeOlpfB_tZS-QA" name="initLayer">
+ <ownedComment xmi:type="uml:Comment" xmi:id="_nC1a4GUaEeOlpfB_tZS-QA" annotatedElement="_Ps2L4GUaEeOlpfB_tZS-QA">
+ <body>Method called to specify that this Layer should be initialized for the specified LayerStack.&#xD;
+Init this Layer for the specified LayersStack.</body>
+ </ownedComment>
+ <ownedParameter xmi:type="uml:Parameter" xmi:id="_cr5cQGUaEeOlpfB_tZS-QA" name="owningLayersStack" type="_gT0asNa7EeKPiuTfpuvqHA"/>
+ </ownedOperation>
+ <ownedOperation xmi:type="uml:Operation" xmi:id="_kzSSwGUdEeOlpfB_tZS-QA" name="getLayersStack" raisedException="_k-dZENxGEeKwptaAAanMDg">
+ <ownedComment xmi:type="uml:Comment" xmi:id="_04NH4GUdEeOlpfB_tZS-QA" annotatedElement="_kzSSwGUdEeOlpfB_tZS-QA">
+ <body>A checked version of getOwningLayersStack.&#xD;
+</body>
+ </ownedComment>
+ <ownedParameter xmi:type="uml:Parameter" xmi:id="_r3jmwGUdEeOlpfB_tZS-QA" name="layersStack" type="_gT0asNa7EeKPiuTfpuvqHA" direction="return"/>
+ </ownedOperation>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_HoKjcNjjEeKQqZMBCFd2Uw" name="LayerOperator" isAbstract="true">
<generalization xmi:type="uml:Generalization" xmi:id="_OJCPcNjjEeKQqZMBCFd2Uw" general="_9IaAANjiEeKQqZMBCFd2Uw"/>
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayerExpression.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayerExpression.java
index 610f109efdc..566f3b50aa7 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayerExpression.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayerExpression.java
@@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.layers.stackmodel.LayersException;
+import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
import org.eclipse.papyrus.layers.stackmodel.command.ComputePropertyValueCommand;
@@ -218,6 +219,30 @@ public interface LayerExpression extends ApplicationDependantElement {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
+ * <!-- begin-model-doc -->
+ * Method called to specify that this Layer should be initialized for the specified LayerStack.
+ * Init this Layer for the specified LayersStack.
+ * <!-- end-model-doc -->
+ * @model owningLayersStackRequired="true" owningLayersStackOrdered="false"
+ * @generated
+ */
+ void initLayer(LayersStack owningLayersStack);
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * <!-- begin-model-doc -->
+ * A checked version of getOwningLayersStack.
+ *
+ * <!-- end-model-doc -->
+ * @model kind="operation" required="true" ordered="false" exceptions="org.eclipse.papyrus.layers.stackmodel.layers.NotFoundException"
+ * @generated
+ */
+ LayersStack getLayersStack() throws NotFoundException;
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
* @throws LayersException
* @model dataType="org.eclipse.papyrus.layers.stackmodel.layers.ComputePropertyValueCommand" viewMany="true" propertyRequired="true" propertyOrdered="false"
* @generated NOT
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayersPackage.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayersPackage.java
index 4b9f13a548b..3d2e11fc560 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayersPackage.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/LayersPackage.java
@@ -405,13 +405,31 @@ public interface LayersPackage extends EPackage {
int LAYER_EXPRESSION___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = APPLICATION_DEPENDANT_ELEMENT_OPERATION_COUNT + 2;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int LAYER_EXPRESSION___INIT_LAYER__LAYERSSTACK = APPLICATION_DEPENDANT_ELEMENT_OPERATION_COUNT + 3;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int LAYER_EXPRESSION___GET_LAYERS_STACK = APPLICATION_DEPENDANT_ELEMENT_OPERATION_COUNT + 4;
+
+ /**
* The number of operations of the '<em>Layer Expression</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
- int LAYER_EXPRESSION_OPERATION_COUNT = APPLICATION_DEPENDANT_ELEMENT_OPERATION_COUNT + 3;
+ int LAYER_EXPRESSION_OPERATION_COUNT = APPLICATION_DEPENDANT_ELEMENT_OPERATION_COUNT + 5;
/**
* The meta object id for the '{@link org.eclipse.papyrus.layers.stackmodel.layers.impl.LayerApplicationFactoryImpl <em>Layer Application Factory</em>}' class.
@@ -2068,6 +2086,24 @@ public interface LayersPackage extends EPackage {
int LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = LAYER_EXPRESSION___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK = LAYER_EXPRESSION___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int LAYER_OPERATOR___GET_LAYERS_STACK = LAYER_EXPRESSION___GET_LAYERS_STACK;
+
+ /**
* The number of operations of the '<em>Layer Operator</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -2203,6 +2239,24 @@ public interface LayersPackage extends EPackage {
int ABSTRACT_LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int ABSTRACT_LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK = LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int ABSTRACT_LAYER_OPERATOR___GET_LAYERS_STACK = LAYER_OPERATOR___GET_LAYERS_STACK;
+
+ /**
* The operation id for the '<em>Is Descriptor Set</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -2410,6 +2464,24 @@ public interface LayersPackage extends EPackage {
int ABSTRACT_LAYER___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = LAYER_EXPRESSION___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int ABSTRACT_LAYER___INIT_LAYER__LAYERSSTACK = LAYER_EXPRESSION___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int ABSTRACT_LAYER___GET_LAYERS_STACK = LAYER_EXPRESSION___GET_LAYERS_STACK;
+
+ /**
* The operation id for the '<em>Add Property Instance</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -3040,6 +3112,24 @@ public interface LayersPackage extends EPackage {
int TOP_LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = ABSTRACT_LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int TOP_LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK = ABSTRACT_LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int TOP_LAYER_OPERATOR___GET_LAYERS_STACK = ABSTRACT_LAYER_OPERATOR___GET_LAYERS_STACK;
+
+ /**
* The operation id for the '<em>Is Descriptor Set</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -3193,6 +3283,24 @@ public interface LayersPackage extends EPackage {
int STACKED_LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = ABSTRACT_LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int STACKED_LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK = ABSTRACT_LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int STACKED_LAYER_OPERATOR___GET_LAYERS_STACK = ABSTRACT_LAYER_OPERATOR___GET_LAYERS_STACK;
+
+ /**
* The operation id for the '<em>Is Descriptor Set</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -3328,6 +3436,24 @@ public interface LayersPackage extends EPackage {
int CUSTOM_LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = LAYER_OPERATOR___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int CUSTOM_LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK = LAYER_OPERATOR___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int CUSTOM_LAYER_OPERATOR___GET_LAYERS_STACK = LAYER_OPERATOR___GET_LAYERS_STACK;
+
+ /**
* The number of operations of the '<em>Custom Layer Operator</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -3724,6 +3850,24 @@ public interface LayersPackage extends EPackage {
int REG_EXP_LAYER___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = ABSTRACT_LAYER___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int REG_EXP_LAYER___INIT_LAYER__LAYERSSTACK = ABSTRACT_LAYER___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int REG_EXP_LAYER___GET_LAYERS_STACK = ABSTRACT_LAYER___GET_LAYERS_STACK;
+
+ /**
* The operation id for the '<em>Add Property Instance</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -3976,6 +4120,24 @@ public interface LayersPackage extends EPackage {
int LAYER___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = ABSTRACT_LAYER___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST;
/**
+ * The operation id for the '<em>Init Layer</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int LAYER___INIT_LAYER__LAYERSSTACK = ABSTRACT_LAYER___INIT_LAYER__LAYERSSTACK;
+
+ /**
+ * The operation id for the '<em>Get Layers Stack</em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ * @ordered
+ */
+ int LAYER___GET_LAYERS_STACK = ABSTRACT_LAYER___GET_LAYERS_STACK;
+
+ /**
* The operation id for the '<em>Add Property Instance</em>' operation.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -6497,6 +6659,26 @@ public interface LayersPackage extends EPackage {
EOperation getLayerExpression__GetPropertiesComputePropertyValueCommand__View_EList();
/**
+ * Returns the meta object for the '{@link org.eclipse.papyrus.layers.stackmodel.layers.LayerExpression#initLayer(org.eclipse.papyrus.layers.stackmodel.layers.LayersStack) <em>Init Layer</em>}' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @return the meta object for the '<em>Init Layer</em>' operation.
+ * @see org.eclipse.papyrus.layers.stackmodel.layers.LayerExpression#initLayer(org.eclipse.papyrus.layers.stackmodel.layers.LayersStack)
+ * @generated
+ */
+ EOperation getLayerExpression__InitLayer__LayersStack();
+
+ /**
+ * Returns the meta object for the '{@link org.eclipse.papyrus.layers.stackmodel.layers.LayerExpression#getLayersStack() <em>Get Layers Stack</em>}' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @return the meta object for the '<em>Get Layers Stack</em>' operation.
+ * @see org.eclipse.papyrus.layers.stackmodel.layers.LayerExpression#getLayersStack()
+ * @generated
+ */
+ EOperation getLayerExpression__GetLayersStack();
+
+ /**
* Returns the meta object for class '{@link org.eclipse.papyrus.layers.stackmodel.layers.ApplicationDependantElement <em>Application Dependant Element</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -8667,6 +8849,22 @@ public interface LayersPackage extends EPackage {
EOperation LAYER_EXPRESSION___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST = eINSTANCE.getLayerExpression__GetPropertiesComputePropertyValueCommand__View_EList();
/**
+ * The meta object literal for the '<em><b>Init Layer</b></em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ EOperation LAYER_EXPRESSION___INIT_LAYER__LAYERSSTACK = eINSTANCE.getLayerExpression__InitLayer__LayersStack();
+
+ /**
+ * The meta object literal for the '<em><b>Get Layers Stack</b></em>' operation.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ EOperation LAYER_EXPRESSION___GET_LAYERS_STACK = eINSTANCE.getLayerExpression__GetLayersStack();
+
+ /**
* The meta object literal for the '{@link org.eclipse.papyrus.layers.stackmodel.layers.impl.ApplicationDependantElementImpl <em>Application Dependant Element</em>}' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/AbstractLayerImpl.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/AbstractLayerImpl.java
index e293f1d5efc..8d0aeabe6ab 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/AbstractLayerImpl.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/AbstractLayerImpl.java
@@ -780,13 +780,13 @@ public abstract class AbstractLayerImpl extends LayerExpressionImpl implements A
* @return
* @throws NotFoundException
*/
- @Override
- public LayersStack getLayersStack() throws NotFoundException {
- // TODO: performance improvment. It is possible to avoid the lookup
- // by caching the LayersStack, or by setting a corresponding property
- // in the model
- return (LayersStack)ECoreUtils.lookupAncestorOfType(this, LayersPackage.eINSTANCE.getLayersStack());
- }
+// @Override
+// public LayersStack getLayersStack() throws NotFoundException {
+// // TODO: performance improvment. It is possible to avoid the lookup
+// // by caching the LayersStack, or by setting a corresponding property
+// // in the model
+// return (LayersStack)ECoreUtils.lookupAncestorOfType(this, LayersPackage.eINSTANCE.getLayersStack());
+// }
} //AbstractLayerImpl
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionImpl.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionImpl.java
index ad9cd1159ef..428ae846db4 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionImpl.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionImpl.java
@@ -14,7 +14,6 @@ package org.eclipse.papyrus.layers.stackmodel.layers.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
-
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
@@ -32,7 +31,6 @@ import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperator;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
import org.eclipse.papyrus.layers.stackmodel.layers.Property;
-import org.eclipse.papyrus.layers.stackmodel.layers.RegExpLayer;
/**
* <!-- begin-user-doc -->
@@ -181,12 +179,6 @@ ApplicationDependantElementImpl implements LayerExpression {
*/
protected LayerExpressionImpl() {
super();
-
- // Listen on this object attachment / detachment from its container.
- // When this node is atttached to a parent, the owningLayerStack property is set.
- // This is done in owningLayerChanged.
- eAdapters().add(containerListener);
-
}
/**
@@ -341,9 +333,13 @@ ApplicationDependantElementImpl implements LayerExpression {
* @generated NOT
*/
public LayersStack getLayersStack() throws NotFoundException {
- // TODO: implement this method
- // Ensure that you remove @generated or mark it @generated NOT
- throw new UnsupportedOperationException();
+
+ LayersStack res = getOwningLayersStack();
+ if( res != null) {
+ return res;
+ }
+
+ throw new NotFoundException("LayersStack is not set in the Layer '" + getName() +"'");
}
/**
@@ -380,6 +376,21 @@ ApplicationDependantElementImpl implements LayerExpression {
}
/**
+ * Init this Layer.
+ * Called by the LayerStack as soon as the layer is added in the tree of layers.
+ * This method can be subclassed to init a particular layer.
+ *
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated NOT
+ */
+ public void initLayer(LayersStack owningLayersStack) {
+
+ // the owning stack
+ setOwningLayersStack(owningLayersStack);
+ }
+
+ /**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
@@ -534,6 +545,16 @@ ApplicationDependantElementImpl implements LayerExpression {
catch (Throwable throwable) {
throw new InvocationTargetException(throwable);
}
+ case LayersPackage.LAYER_EXPRESSION___INIT_LAYER__LAYERSSTACK:
+ initLayer((LayersStack)arguments.get(0));
+ return null;
+ case LayersPackage.LAYER_EXPRESSION___GET_LAYERS_STACK:
+ try {
+ return getLayersStack();
+ }
+ catch (Throwable throwable) {
+ throw new InvocationTargetException(throwable);
+ }
}
return super.eInvoke(operationID, arguments);
}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerOperatorImpl.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerOperatorImpl.java
index fed5b7c13d5..93ae2abac7a 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerOperatorImpl.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerOperatorImpl.java
@@ -167,13 +167,13 @@ public abstract class LayerOperatorImpl extends LayerExpressionImpl implements L
* @return
* @throws NotFoundException
*/
- @Override
- public LayersStack getLayersStack() throws NotFoundException {
- // TODO: performance improvment. It is possible to avoid the lookup
- // by caching the LayersStack, or by setting a corresponding property
- // in the model
- return (LayersStack)ECoreUtils.lookupAncestorOfType(this, LayersPackage.eINSTANCE.getLayersStack());
- }
+// @Override
+// public LayersStack getLayersStack() throws NotFoundException {
+// // TODO: performance improvment. It is possible to avoid the lookup
+// // by caching the LayersStack, or by setting a corresponding property
+// // in the model
+// return (LayersStack)ECoreUtils.lookupAncestorOfType(this, LayersPackage.eINSTANCE.getLayersStack());
+// }
/**
* Propagate the change to children
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersPackageImpl.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersPackageImpl.java
index 4b97c4642a7..31d132a399a 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersPackageImpl.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersPackageImpl.java
@@ -895,6 +895,24 @@ public class LayersPackageImpl extends EPackageImpl implements LayersPackage {
* <!-- end-user-doc -->
* @generated
*/
+ public EOperation getLayerExpression__InitLayer__LayersStack() {
+ return layerExpressionEClass.getEOperations().get(3);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
+ public EOperation getLayerExpression__GetLayersStack() {
+ return layerExpressionEClass.getEOperations().get(4);
+ }
+
+ /**
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @generated
+ */
public EClass getApplicationDependantElement() {
return applicationDependantElementEClass;
}
@@ -2767,6 +2785,8 @@ public class LayersPackageImpl extends EPackageImpl implements LayersPackage {
createEOperation(layerExpressionEClass, LAYER_EXPRESSION___GET_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_PROPERTY);
createEOperation(layerExpressionEClass, LAYER_EXPRESSION___GET_VIEWS_COMPUTE_PROPERTY_VALUE_COMMAND__ELIST_PROPERTY);
createEOperation(layerExpressionEClass, LAYER_EXPRESSION___GET_PROPERTIES_COMPUTE_PROPERTY_VALUE_COMMAND__VIEW_ELIST);
+ createEOperation(layerExpressionEClass, LAYER_EXPRESSION___INIT_LAYER__LAYERSSTACK);
+ createEOperation(layerExpressionEClass, LAYER_EXPRESSION___GET_LAYERS_STACK);
applicationDependantElementEClass = createEClass(APPLICATION_DEPENDANT_ELEMENT);
createEReference(applicationDependantElementEClass, APPLICATION_DEPENDANT_ELEMENT__APPLICATION);
@@ -3167,6 +3187,12 @@ public class LayersPackageImpl extends EPackageImpl implements LayersPackage {
addEParameter(op, this.getProperty(), "property", 1, -1, IS_UNIQUE, IS_ORDERED);
addEException(op, this.getLayersException());
+ op = initEOperation(getLayerExpression__InitLayer__LayersStack(), null, "initLayer", 1, 1, IS_UNIQUE, !IS_ORDERED);
+ addEParameter(op, this.getLayersStack(), "owningLayersStack", 1, 1, IS_UNIQUE, !IS_ORDERED);
+
+ op = initEOperation(getLayerExpression__GetLayersStack(), this.getLayersStack(), "getLayersStack", 1, 1, IS_UNIQUE, !IS_ORDERED);
+ addEException(op, this.getNotFoundException());
+
initEClass(applicationDependantElementEClass, ApplicationDependantElement.class, "ApplicationDependantElement", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEReference(getApplicationDependantElement_Application(), this.getLayersStackApplication(), null, "application", null, 0, 1, ApplicationDependantElement.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, !IS_ORDERED);
@@ -3560,7 +3586,7 @@ public class LayersPackageImpl extends EPackageImpl implements LayersPackage {
* @generated
*/
protected void createExtendedMetaDataAnnotations() {
- String source = "http:///org/eclipse/emf/ecore/util/ExtendedMetaData";
+ String source = "http:///org/eclipse/emf/ecore/util/ExtendedMetaData";
addAnnotation
(badStateExceptionEDataType,
source,
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersStackImpl.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersStackImpl.java
index ddf7c7378ee..ce18474b5a5 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersStackImpl.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersStackImpl.java
@@ -31,6 +31,9 @@ import org.eclipse.papyrus.layers.stackmodel.layers.LayerExpression;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
import org.eclipse.papyrus.layers.stackmodel.layers.Property;
+import org.eclipse.papyrus.layers.stackmodel.notifier.ILayersTreeEventListener;
+import org.eclipse.papyrus.layers.stackmodel.notifier.LayersTreeEventNotifier;
+import org.eclipse.papyrus.layers.stackmodel.notifier.LayersTreeEventNotifierFactory;
/**
* <!-- begin-user-doc -->
@@ -109,12 +112,54 @@ MinimalEObjectImpl.Container implements LayersStack {
protected Diagram diagram;
/**
+ * Listener on layers tree events.
+ * This listener take in charge the initialization of added layers.
+ */
+ private ILayersTreeEventListener layersTreeEventListener = new ILayersTreeEventListener() {
+
+ @Override
+ public void layerSet(Notification notification) {
+ LayersStackImpl.this.layerAdded( (LayerExpression)notification.getNewValue() );
+ }
+
+ @Override
+ public void layerRemoved(Notification notification) {
+ // nothing to do
+
+ }
+
+ @Override
+ public void layerMoved(Notification notification) {
+ // nothing to do
+
+ }
+
+ @Override
+ public void layerAdded(Notification notification) {
+ LayersStackImpl.this.layerAdded( (LayerExpression)notification.getNewValue() );
+ }
+
+ };
+
+ /**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected LayersStackImpl() {
super();
+ init();
+ }
+
+ /**
+ * Init this object.
+ * Create a listener on tree events.
+ */
+ private void init() {
+
+ LayersTreeEventNotifier layersTreeEventnotifier = LayersTreeEventNotifierFactory.instance.adapt(this);
+
+ layersTreeEventnotifier.addLayersModelEventListener(layersTreeEventListener);
}
/**
@@ -474,4 +519,17 @@ MinimalEObjectImpl.Container implements LayersStack {
return result.toString();
}
+ /**
+ * A layer has been added to the layerTree.
+ * Init this layer.
+ * This method is called by the listener on layerTree events.
+ *
+ * @param addedLayer The added layer.
+ */
+ protected void layerAdded(LayerExpression addedLayer) {
+ // init the layer
+ addedLayer.initLayer(this);
+
+ }
+
} //LayersStackImpl
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/ILayersTreeEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/ILayersTreeEventListener.java
new file mode 100644
index 00000000000..1869150867d
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/ILayersTreeEventListener.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin - cedric.dumoulin@lifl.fr
+ ******************************************************************************/
+package org.eclipse.papyrus.layers.stackmodel.notifier;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperator;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+
+
+/**
+ * Class implementing this interface can listen to event from a {@link LayersStack}.
+ * Interface for listeners whising to be informed of change in the Tree of Layers structure.
+ * <br>
+ * Listeners of such events should register themself to the notifier {@link LayersTreeEventNotifier}.
+ * <br>
+ * The following events are fired:
+ * <ul>
+ * <li>LayerAdded</li>
+ * <li>LayerRemoved</li>
+ * <li>LayerMoved</li>
+ * <li>LayerSet</li>
+ * </ul>
+ *
+ * @author cedric dumoulin
+ *
+ */
+public interface ILayersTreeEventListener {
+
+ /**
+ * Method called when a layer is added to one layer.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void layerAdded( Notification notification );
+ /**
+ * Method called when a layer is removed from one layer.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void layerRemoved( Notification notification );
+ /**
+ * Method called when a layer is moved inside a {@link LayerOperator}.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void layerMoved( Notification notification );
+ /**
+ * Method called when a layer is set.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void layerSet( Notification notification );
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifier.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifier.java
new file mode 100644
index 00000000000..023fc0ae1a4
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifier.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin - cedric.dumoulin@lifl.fr
+ ******************************************************************************/
+package org.eclipse.papyrus.layers.stackmodel.notifier;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+
+
+/**
+ * Notifier/observers firing events concerning the structure of the tree of layers.
+ * Obeserver should implements {@link ILayersTreeEventListener} and register themself to this
+ * notifier.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class LayersTreeEventNotifier extends EContentAdapter {
+
+ /**
+ * List of listener to notify.
+ */
+ protected List<ILayersTreeEventListener> listeners = new ArrayList<ILayersTreeEventListener>();
+
+ /**
+ * Constructor.
+ *
+ * @param layersStack The observed {@link LayersStack}.
+ */
+ public LayersTreeEventNotifier() {
+ }
+
+ /**
+ * Dispose this object.
+ */
+ public void dispose() {
+ if(isDisposed()) {
+ return;
+ }
+ listeners.clear();
+ listeners = null;
+ }
+
+ /**
+ * Return true if the object is disposed.
+ * @return
+ */
+ public boolean isDisposed() {
+ return listeners==null;
+ }
+
+ /**
+ * Called when something happen on the tree.
+ * @see org.eclipse.emf.ecore.util.EContentAdapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ System.err.println( this.getClass().getSimpleName() + ".event received " + notification.getFeature());
+ // Self atttach
+ super.notifyChanged(notification);
+
+ // Check layers modification
+ // There is two sources: LayerOperator::layers and LayersStack::layers
+ if( notification.getFeature() == LayersPackage.eINSTANCE.getLayerOperator_Layers()
+ || notification.getFeature() == LayersPackage.eINSTANCE.getLayersStack_Layers() ) {
+ // LayerOperator::layers || LayersStack::layers
+ // check the event type.
+ switch(notification.getEventType()) {
+ case Notification.SET:
+ fireLayerSet(notification);
+ break;
+ case Notification.ADD:
+ // A layer is added
+ fireLayerAdded(notification);
+ break;
+ case Notification.REMOVE:
+ // A layer is removed
+ fireLayerRemoved(notification);
+ break;
+ case Notification.MOVE:
+ // A layer is moved
+ fireLayerMoved(notification);
+ break;
+ }
+ }
+ }
+
+ /**
+ * This Adapter is for {@link LayersTreeEventNotifier}.
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean isAdapterForType(Object type) {
+ return type == LayersTreeEventNotifier.class;
+ }
+
+ /**
+ * Add the specified listener to the list of listener.
+ * Do not add it if the listener is already in the list.
+ *
+ * @param listener
+ */
+ public void addLayersModelEventListener(ILayersTreeEventListener listener) {
+
+ if(listener == null ) {
+ return;
+ }
+
+ // Check if exist
+ if( listeners.contains(listener)) {
+ return;
+ }
+
+ listeners.add(listener);
+ }
+
+ /**
+ * Remove the specified listener from the list of listeners.
+ * @param listener
+ */
+ public void removeLayersModelEventListener(ILayersTreeEventListener listener) {
+
+ listeners.remove(listener);
+ }
+
+ /**
+ * Method called when a layer is added to one layer.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void fireLayerSet( Notification notification ) {
+
+ for(ILayersTreeEventListener listener : listeners) {
+ listener.layerSet(notification);
+ }
+ }
+
+ /**
+ * Method called when a layer is added to one layer.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void fireLayerAdded( Notification notification ) {
+
+ for(ILayersTreeEventListener listener : listeners) {
+ listener.layerAdded(notification);
+ }
+ }
+
+ /**
+ * Method called when a layer is removed from one layer.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void fireLayerRemoved( Notification notification ) {
+
+ for(ILayersTreeEventListener listener : listeners) {
+ listener.layerRemoved(notification);
+ }
+ }
+
+ /**
+ * Method called when a layer is moved in LayerStack.
+ * The event contains: the layer.
+ *
+ * @param notification
+ */
+ public void fireLayerMoved( Notification notification ) {
+
+ for(ILayersTreeEventListener listener : listeners) {
+ listener.layerMoved(notification);
+ }
+ }
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactory.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactory.java
new file mode 100644
index 00000000000..3953b496eff
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactory.java
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.layers.stackmodel.notifier;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+
+/**
+ * Factory used to create a {@link LayersTreeEventNotifier}.
+ * The factory ensures that there is only one Notifier for a given {@link LayersStack}.
+ * @author cedric dumoulin
+ *
+ */
+public class LayersTreeEventNotifierFactory extends AdapterFactoryImpl {
+
+ /**
+ * Global factory.
+ */
+ static public LayersTreeEventNotifierFactory instance = new LayersTreeEventNotifierFactory();
+
+ /**
+ * Convenience method.
+ * @param target
+ * @return
+ */
+ public LayersTreeEventNotifier adapt(Notifier target) {
+ return (LayersTreeEventNotifier)adapt(target, LayersTreeEventNotifier.class);
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#createAdapter(org.eclipse.emf.common.notify.Notifier)
+ *
+ * @param target
+ * @return
+ */
+ @Override
+ protected Adapter createAdapter(Notifier target) {
+ return new LayersTreeEventNotifier();
+ }
+
+ /**
+ * This Factory is for {@link LayersTreeEventNotifier}.
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#isFactoryForType(java.lang.Object)
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean isFactoryForType(Object type) {
+ return type == LayersTreeEventNotifier.class;
+ }
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionInitWithApplicationImplTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionInitWithApplicationImplTest.java
index 50794167b73..979a03aa816 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionInitWithApplicationImplTest.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayerExpressionInitWithApplicationImplTest.java
@@ -76,6 +76,7 @@ public class LayerExpressionInitWithApplicationImplTest {
);
TopLayerOperator top = (TopLayerOperator)factory.getLayer("top");
+ stack.setLayers(top);
TopLayerOperator container1 = (TopLayerOperator)factory.getLayer("top");
Layer layer1 = (Layer)factory.getLayer("layer1");
Layer layer2 = (Layer)factory.getLayer("layer1");
@@ -100,6 +101,59 @@ public class LayerExpressionInitWithApplicationImplTest {
}
/**
+ * Test if properties are set after adding a subtree
+ */
+ @Test
+ public void testAddSubTreeImpl() {
+ // Create requested objects
+ LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication();
+ Diagram diagram = NotationFactory.eINSTANCE.createDiagram();
+ // Create stack
+ LayersStack stack = application.getLayersStackFor(diagram);
+
+ // Create layers
+ LayersFactoryTestUtils factory = new LayersFactoryTestUtils(application);
+ factory.newTopLayer("top",
+ factory.newLayer("layer1"),
+ factory.newLayer("layer2"),
+ factory.newTopLayer("container1",
+ factory.newLayer("layer3") )
+ );
+
+ factory.newTopLayer("container2",
+ factory.newLayer("layer21"),
+ factory.newLayer("layer22")
+ );
+
+ TopLayerOperator top = (TopLayerOperator)factory.getLayer("top");
+ stack.setLayers(top);
+ TopLayerOperator container2 = (TopLayerOperator)factory.getLayer("container2");
+ Layer layer21 = (Layer)factory.getLayer("layer21");
+ Layer layer22 = (Layer)factory.getLayer("layer22");
+
+ // action
+ // Add subtree
+ top.getLayers().add(container2);
+
+ // Assert
+ assertNotNull("object created", top);
+ assertEquals("application initialized", application, top.getApplication() );
+
+ assertNotNull("object created", container2);
+ assertEquals("application initialized", application, container2.getApplication() );
+ assertEquals("container (stack) initialized", stack, container2.getOwningLayersStack() );
+
+ assertNotNull("object created", layer21);
+ assertEquals("application initialized", application, layer21.getApplication() );
+ assertEquals("container (stack) initialized", stack, layer21.getOwningLayersStack() );
+
+ assertNotNull("object created", layer22);
+ assertEquals("application initialized", application, layer22.getApplication() );
+ assertEquals("container (stack) initialized", stack, layer22.getOwningLayersStack() );
+
+ }
+
+ /**
* Test method for {@link org.eclipse.papyrus.layers.stackmodel.layers.impl.LayerExpressionImpl#isLayerEnabled()}.
*/
@Test
@@ -136,6 +190,7 @@ public class LayerExpressionInitWithApplicationImplTest {
);
TopLayerOperator top = (TopLayerOperator)factory.getLayer("top");
+ stack.setLayers(top);
TopLayerOperator container1 = (TopLayerOperator)factory.getLayer("top");
Layer layer1 = (Layer)factory.getLayer("layer1");
Layer layer2 = (Layer)factory.getLayer("layer1");
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactoryTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactoryTest.java
new file mode 100644
index 00000000000..18a4e058396
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierFactoryTest.java
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Copyright (c) 2013 Cedric Dumoulin.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.layers.stackmodel.notifier;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersFactory;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test if the factory return the same Notifier for a given {@link LayersStack}.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class LayersTreeEventNotifierFactoryTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#AdapterFactoryImpl()}.
+ */
+ @Test
+ public void testAdapterFactoryImpl() {
+
+ LayersStack stack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifierFactory factory = new LayersTreeEventNotifierFactory();
+
+ // Action
+ LayersTreeEventNotifier eventNotifier = (LayersTreeEventNotifier)factory.adapt(stack, LayersTreeEventNotifier.class);
+
+ // Assert
+ assertNotNull("object created", eventNotifier);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#AdapterFactoryImpl()}.
+ */
+ @Test
+ public void testReturnSameInstanceImpl() {
+
+ LayersStack stack1 = LayersFactory.eINSTANCE.createLayersStack();
+ LayersStack stack2 = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifierFactory factory = new LayersTreeEventNotifierFactory();
+
+ // Action
+ LayersTreeEventNotifier eventNotifier11 = (LayersTreeEventNotifier)factory.adapt(stack1, LayersTreeEventNotifier.class);
+ LayersTreeEventNotifier eventNotifier12 = (LayersTreeEventNotifier)factory.adapt(stack1, LayersTreeEventNotifier.class);
+
+ LayersTreeEventNotifier eventNotifier21 = (LayersTreeEventNotifier)factory.adapt(stack2, LayersTreeEventNotifier.class);
+ LayersTreeEventNotifier eventNotifier22 = (LayersTreeEventNotifier)factory.adapt(stack2, LayersTreeEventNotifier.class);
+
+ // Assert
+ assertNotNull("object created", eventNotifier11);
+ assertNotNull("object created", eventNotifier21);
+
+ assertNotEquals("instance are different between stack", eventNotifier11, eventNotifier21);
+
+ assertEquals("return the same instance", eventNotifier11, eventNotifier12);
+ assertEquals("return the same instance", eventNotifier21, eventNotifier22);
+ }
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierTest.java
new file mode 100644
index 00000000000..60a17207734
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/LayersTreeEventNotifierTest.java
@@ -0,0 +1,356 @@
+/*******************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin - cedric.dumoulin@lifl.fr
+ ******************************************************************************/
+package org.eclipse.papyrus.layers.stackmodel.notifier;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.papyrus.layers.stackmodel.layers.Layer;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayerExpression;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperator;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersFactory;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+import org.eclipse.papyrus.layers.stackmodel.util.TriggeredEventTraces;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+/**
+ * @author dumoulin
+ *
+ */
+public class LayersTreeEventNotifierTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#LayersTreeEventNotifier(org.eclipse.papyrus.layers.stackmodel.layers.LayersStack)}.
+ */
+ @Test
+ public void testLayersTreeEventNotifier() {
+
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+// // Add a trace listener
+// ILayersTreeEventListener listener = new TraceLayersModelEventListener();
+// notifier.addLayersModelEventListener(listener);
+
+ // Check creation
+ assertNotNull("notifier created", notifier);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#activate()}.
+ */
+ @Test
+ @Ignore
+ public void testActivate() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#deactivate()}.
+ */
+ @Test
+ @Ignore
+ public void testDeactivate() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#dispose()}.
+ */
+ @Test
+ public void testDispose() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ TraceLayersModelEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ // Add a layer
+ LayerOperator layerOp1 = LayersFactory.eINSTANCE.createStackedLayerOperator();
+ layersStack.setLayers(layerOp1);
+
+ // dispose notifier
+ assertFalse("notifier disposed", notifier.isDisposed());
+ notifier.dispose();
+ assertTrue("notifier disposed", notifier.isDisposed());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#addLayersModelEventListener(org.eclipse.papyrus.layers.runtime.ILayersTreeEventListener)}.
+ */
+ @Test
+ public void testAddLayersModelEventListener() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ ILayersTreeEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ // Check creation
+ assertNotNull("notifier created", notifier);
+ assertTrue( "listener added to internal list", notifier.listeners.contains(listener) );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#removeLayersModelEventListener(org.eclipse.papyrus.layers.runtime.ILayersTreeEventListener)}.
+ */
+ @Test
+ public void testRemoveLayersModelEventListener() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ ILayersTreeEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+ assertTrue( "listener added to internal list", notifier.listeners.contains(listener) );
+
+ // Remove the listener
+ notifier.removeLayersModelEventListener(listener);
+ assertFalse( "listener removed from internal list", notifier.listeners.contains(listener) );
+
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#fireLayerAdded(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireLayerAdded() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ TraceLayersModelEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ // Add a layer
+ LayerOperator layerOp1 = LayersFactory.eINSTANCE.createStackedLayerOperator();
+ System.err.println("setLayers(layerOp1)");
+ layersStack.setLayers(layerOp1);
+ // Check events
+ assertTrue("event recorded", traces.contains("layerSet"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+ assertEquals("one event recorded", "layerSet", traces.traces.get(0).name );
+
+ // Add a layer
+ Layer layer1 = LayersFactory.eINSTANCE.createLayer();
+ System.err.println("layerOp1.getLayers().add(layer1)");
+ layerOp1.getLayers().add(layer1);
+
+ // Check events
+ assertTrue("event recorded", traces.contains("layerAdded"));
+ assertEquals("one event recorded", 2, traces.traces.size() );
+ assertEquals("one event recorded", "layerAdded", traces.traces.get(1).name );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#fireLayerRemoved(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireLayerRemoved() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ TraceLayersModelEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ // Add a layer
+ LayerOperator layerOp1 = LayersFactory.eINSTANCE.createStackedLayerOperator();
+ layersStack.setLayers(layerOp1);
+
+ // Add a layer
+ Layer layer1 = LayersFactory.eINSTANCE.createLayer();
+ layerOp1.getLayers().add(layer1);
+
+ // Remove layer
+ traces.clear();
+ layerOp1.getLayers().remove(layer1);
+
+ // Check events
+ assertTrue("event recorded", traces.contains("layerRemoved"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+ assertEquals("one event recorded", "layerRemoved", traces.traces.get(0).name );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#fireLayerRemoved(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireLayerSetForRootLayer() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ TraceLayersModelEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ // Add a layer as root
+ LayerOperator layerOp1 = LayersFactory.eINSTANCE.createStackedLayerOperator();
+ layersStack.setLayers(layerOp1);
+
+ // Add a layer
+ Layer layer1 = LayersFactory.eINSTANCE.createLayer();
+ layerOp1.getLayers().add(layer1);
+
+ // Remove root layer
+ traces.clear();
+ layersStack.setLayers(null);
+
+ // Check events
+ assertTrue("event recorded", traces.contains("layerSet"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+ assertEquals("one event recorded", "layerSet", traces.traces.get(0).name );
+ // Note that no event is sent for the nested layer
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#fireLayerRemoved(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireEventWhenRootLayerIsReplaced() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ TraceLayersModelEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ // Add a layer as root
+ LayerOperator layerOp1 = LayersFactory.eINSTANCE.createStackedLayerOperator();
+ layersStack.setLayers(layerOp1);
+
+ // Add a layer
+ Layer layer1 = LayersFactory.eINSTANCE.createLayer();
+ layerOp1.getLayers().add(layer1);
+
+ // replace root layer
+ traces.clear();
+ Layer layer2 = LayersFactory.eINSTANCE.createLayer();
+ layersStack.setLayers(layer2);
+
+ // Check events
+ assertTrue("event recorded", traces.contains("layerSet"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+ assertEquals("one event recorded", "layerSet", traces.traces.get(0).name );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#fireLayerRemoved(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireEventWhenLayerIsReplaced() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ TraceLayersModelEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ // Add a layer as root
+ LayerOperator layerOp1 = LayersFactory.eINSTANCE.createStackedLayerOperator();
+ layersStack.setLayers(layerOp1);
+
+ // Add a layer
+ Layer layer1 = LayersFactory.eINSTANCE.createLayer();
+ layerOp1.getLayers().add(layer1);
+
+ // replace root layer
+ traces.clear();
+ Layer layer2 = LayersFactory.eINSTANCE.createLayer();
+ layerOp1.getLayers().set(0, layer2);
+
+ // Check events
+ assertTrue("event recorded", traces.contains("layerSet"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+ assertEquals("one event recorded", "layerSet", traces.traces.get(0).name );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.runtime.LayersTreeEventNotifier#fireLayerMoved(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireLayerMoved() {
+ // Create a notifier
+ LayersStack layersStack = LayersFactory.eINSTANCE.createLayersStack();
+ LayersTreeEventNotifier notifier = LayersTreeEventNotifierFactory.instance.adapt(layersStack);
+
+ // Add a trace listener
+ TraceLayersModelEventListener listener = new TraceLayersModelEventListener();
+ notifier.addLayersModelEventListener(listener);
+
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ // Add a layer
+ LayerOperator layerOp1 = LayersFactory.eINSTANCE.createStackedLayerOperator();
+ layersStack.setLayers(layerOp1);
+
+ // Add a layer
+ Layer layer1 = LayersFactory.eINSTANCE.createLayer();
+ layerOp1.getLayers().add(layer1);
+
+ // Add a layer
+ Layer layer2 = LayersFactory.eINSTANCE.createLayer();
+ layerOp1.getLayers().add(layer2);
+
+ // move layer
+ // EMF list are EList, which contains a move operation
+ traces.clear();
+ EList<LayerExpression> list = (EList<LayerExpression>)layerOp1.getLayers();
+ list.move(0, layer2);
+
+ // Check events
+ assertTrue("event recorded", traces.contains("layerMoved"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+ assertEquals("one event recorded", "layerMoved", traces.traces.get(0).name );
+ }
+
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceLayersModelEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceLayersModelEventListener.java
new file mode 100644
index 00000000000..2a730c14c06
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceLayersModelEventListener.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin - cedric.dumoulin@lifl.fr
+ ******************************************************************************/
+package org.eclipse.papyrus.layers.stackmodel.notifier;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.papyrus.layers.stackmodel.util.TriggeredEventTraces;
+
+
+/**
+ * A listener on {@link LayersModelEventNotifier}. This listener trace events from
+ * the notifier.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class TraceLayersModelEventListener implements ILayersTreeEventListener {
+
+ public TriggeredEventTraces<Notification> traces = new TriggeredEventTraces<Notification>();
+
+ /**
+ * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerAdded(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ public void layerSet(Notification notification) {
+ traces.addTrace("layerSet", notification);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerAdded(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ public void layerAdded(Notification notification) {
+ traces.addTrace("layerAdded", notification);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerRemoved(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ public void layerRemoved(Notification notification) {
+ traces.addTrace("layerRemoved", notification);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerMoved(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ public void layerMoved(Notification notification) {
+ traces.addTrace("layerMoved", notification);
+ }
+
+}

Back to the top