Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2013-12-12 08:42:45 +0000
committerCedric Dumoulin2014-01-27 13:56:16 +0000
commit18008b3f4473e694ac96d6b7d4b5944c1b58858f (patch)
treeb509acc3b2111097ae7aea68792b1967f8a33fde /extraplugins/layers/org.eclipse.papyrus.layers.stackmodel
parentcc50f3bce868ed95939cf6e55a70c309974187c6 (diff)
downloadorg.eclipse.papyrus-18008b3f4473e694ac96d6b7d4b5944c1b58858f.tar.gz
org.eclipse.papyrus-18008b3f4473e694ac96d6b7d4b5944c1b58858f.tar.xz
org.eclipse.papyrus-18008b3f4473e694ac96d6b7d4b5944c1b58858f.zip
First working RegExp
Add NotyfyingList and ExpressionMatcher Update layers model.
Diffstat (limited to 'extraplugins/layers/org.eclipse.papyrus.layers.stackmodel')
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/META-INF/MANIFEST.MF3
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore4
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation22
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml6
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcher.java153
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/RegExpLayer.java8
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/LayersPackageImpl.java4
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/RegExpLayerImpl.java314
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingList.java2
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcherTest.java195
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingListTest.java2
11 files changed, 617 insertions, 96 deletions
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/META-INF/MANIFEST.MF b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/META-INF/MANIFEST.MF
index e86c17d97e2..19497f1825a 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/META-INF/MANIFEST.MF
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore.xmi;bundle-version="2.9.0",
org.eclipse.uml2.uml;bundle-version="4.1.0",
org.eclipse.ocl.ecore;bundle-version="3.3.0",
- org.eclipse.emf.query.ocl;bundle-version="2.0.0"
+ org.eclipse.emf.query.ocl;bundle-version="2.0.0",
+ com.google.guava;bundle-version="11.0.2"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Bundle-Localization: plugin
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 dd85962cf69..a491914feb3 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.ecore
@@ -405,7 +405,7 @@
<eOperations name="deactivate" ordered="false" lowerBound="1">
<eParameters name="oldParentLayer" ordered="false" lowerBound="1" eType="#//AbstractLayerOperator"/>
</eOperations>
- <eOperations name="isDerivedView" ordered="false" upperBound="-1" eType="#//boolean"
+ <eOperations name="isDerivedView" ordered="false" lowerBound="1" eType="#//boolean"
eExceptions="#//LayersException">
<eParameters name="view" ordered="false" lowerBound="1" eType="ecore:EClass ../../org.eclipse.gmf.runtime.notation/model/notation.ecore#//View"/>
</eOperations>
@@ -416,7 +416,7 @@
<eParameters name="views" ordered="false" upperBound="-1" eType="ecore:EClass ../../org.eclipse.gmf.runtime.notation/model/notation.ecore#//View"/>
</eOperations>
<eOperations name="attachDerivedViews" ordered="false" lowerBound="1" eExceptions="#//LayersException"/>
- <eOperations name="lookupDerivedViews" ordered="false" lowerBound="1" eType="ecore:EClass ../../org.eclipse.gmf.runtime.notation/model/notation.ecore#//View"
+ <eOperations name="lookupDerivedViews" ordered="false" upperBound="-1" eType="ecore:EClass ../../org.eclipse.gmf.runtime.notation/model/notation.ecore#//View"
eExceptions="#//LayersException">
<eParameters name="views" ordered="false" upperBound="-1" eType="ecore:EClass ../../org.eclipse.gmf.runtime.notation/model/notation.ecore#//View"/>
</eOperations>
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 bcebd0a76d6..622401c1477 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.notation
@@ -838,7 +838,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_zpKe19a7EeKPiuTfpuvqHA"/>
</children>
<element xmi:type="uml:Class" href="layers.uml#_gT0asNa7EeKPiuTfpuvqHA"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="_zpKewda7EeKPiuTfpuvqHA" x="6" y="120" height="133"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_zpKewda7EeKPiuTfpuvqHA" x="6" y="78" height="133"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_52F7ENa7EeKPiuTfpuvqHA" type="2008" fontName="Segoe UI" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_52F7Eta7EeKPiuTfpuvqHA" source="ShadowFigure">
@@ -870,7 +870,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_52F7J9a7EeKPiuTfpuvqHA"/>
</children>
<element xmi:type="uml:Class" href="layers.uml#_51zAINa7EeKPiuTfpuvqHA"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="_52F7Eda7EeKPiuTfpuvqHA" x="414" y="330" height="115"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_52F7Eda7EeKPiuTfpuvqHA" x="480" y="348" width="115" height="193"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_AjwF4Na8EeKPiuTfpuvqHA" type="2008" fontName="Segoe UI" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_AjwF4ta8EeKPiuTfpuvqHA" source="ShadowFigure">
@@ -974,7 +974,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_vMkrRdjKEeKgkM6XJF9t4A"/>
</children>
<element xmi:type="uml:Class" href="layers.uml#_vMMQsNjKEeKgkM6XJF9t4A"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="_vMekkdjKEeKgkM6XJF9t4A" x="732" y="474" width="203"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_vMekkdjKEeKgkM6XJF9t4A" x="744" y="480" width="203"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_9IsT4NjiEeKQqZMBCFd2Uw" type="2008" fontName="Segoe UI" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_9IsT4tjiEeKQqZMBCFd2Uw" source="ShadowFigure">
@@ -1057,7 +1057,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_9IyakNjiEeKQqZMBCFd2Uw"/>
</children>
<element xmi:type="uml:Class" href="layers.uml#_9IaAANjiEeKQqZMBCFd2Uw"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="_9IsT4djiEeKQqZMBCFd2Uw" x="252" y="108" width="475" height="184"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_9IsT4djiEeKQqZMBCFd2Uw" x="252" y="78" width="475" height="214"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_Hoi98NjjEeKQqZMBCFd2Uw" type="2008" fontName="Segoe UI" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_Hoi98tjjEeKQqZMBCFd2Uw" source="ShadowFigure">
@@ -1249,7 +1249,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_zT_qd9t5EeKwptaAAanMDg"/>
</children>
<element xmi:type="uml:Class" href="layers.uml#_325AENt0EeKQqZMBCFd2Uw"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="_zT_qYdt5EeKwptaAAanMDg" x="234" y="24" height="45"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_zT_qYdt5EeKwptaAAanMDg" x="396" y="-48" height="45"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_z-jdcOHTEeKCZbxNW-U3VQ" type="2008" fontName="Segoe UI" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_z-jdcuHTEeKCZbxNW-U3VQ" source="ShadowFigure">
@@ -1337,7 +1337,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_z-jdh-HTEeKCZbxNW-U3VQ"/>
</children>
<element xmi:type="uml:Class" href="layers.uml#_z9aN8OHTEeKCZbxNW-U3VQ"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="_z-jdceHTEeKCZbxNW-U3VQ" x="558" y="642"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_z-jdceHTEeKCZbxNW-U3VQ" x="684" y="666"/>
</children>
<children xmi:type="notation:Shape" xmi:id="__1eoIOHTEeKCZbxNW-U3VQ" type="2008" fontName="Segoe UI" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="__1eoIuHTEeKCZbxNW-U3VQ" source="ShadowFigure">
@@ -1369,7 +1369,7 @@
<layoutConstraint xmi:type="notation:Bounds" xmi:id="__1eoN-HTEeKCZbxNW-U3VQ"/>
</children>
<element xmi:type="uml:Class" href="layers.uml#__1GNoOHTEeKCZbxNW-U3VQ"/>
- <layoutConstraint xmi:type="notation:Bounds" xmi:id="__1eoIeHTEeKCZbxNW-U3VQ" x="984" y="642"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="__1eoIeHTEeKCZbxNW-U3VQ" x="534" y="666"/>
</children>
<children xmi:type="notation:Shape" xmi:id="_7c7RQFVHEeOah7Z-UYdQAA" type="2006" fontName="Segoe UI" lineColor="0">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_7c7RQlVHEeOah7Z-UYdQAA" source="ShadowFigure">
@@ -1473,8 +1473,8 @@
<styles xmi:type="notation:FontStyle" xmi:id="_A2AAAdjLEeKgkM6XJF9t4A" fontName="Segoe UI"/>
<element xmi:type="uml:Association" href="layers.uml#_A1nlgNjLEeKgkM6XJF9t4A"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_A2AAAtjLEeKgkM6XJF9t4A" points="[4, 2, -221, 0]$[222, 1, -3, -1]"/>
- <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_A2MNQNjLEeKgkM6XJF9t4A" id="(0.96,0.820627802690583)"/>
- <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_A2MNQdjLEeKgkM6XJF9t4A" id="(0.014778325123152709,0.47580645161290325)"/>
+ <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_A2MNQNjLEeKgkM6XJF9t4A" id="(0.9304347826086956,0.8963730569948186)"/>
+ <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_A2MNQdjLEeKgkM6XJF9t4A" id="(0.014778325123152709,0.3870967741935484)"/>
</edges>
<edges xmi:type="notation:Connector" xmi:id="__u7_YNjMEeKgkM6XJF9t4A" type="4002" source="_52F7ENa7EeKPiuTfpuvqHA" target="_9IsT4NjiEeKQqZMBCFd2Uw" lineColor="0">
<children xmi:type="notation:DecorationNode" xmi:id="__vCGANjMEeKgkM6XJF9t4A" type="6007">
@@ -1593,7 +1593,7 @@
<styles xmi:type="notation:FontStyle" xmi:id="_18hy4dt5EeKwptaAAanMDg" fontName="Segoe UI"/>
<element xmi:type="uml:Generalization" href="layers.uml#_18JYYNt5EeKwptaAAanMDg"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_18hy4tt5EeKwptaAAanMDg" points="[-3, -5, 0, 82]$[-11, -80, -8, 7]"/>
- <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_18n5gNt5EeKwptaAAanMDg" id="(0.5114503816793893,0.033783783783783786)"/>
+ <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_18n5gNt5EeKwptaAAanMDg" id="(0.48210526315789476,0.004672897196261682)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_18n5gdt5EeKwptaAAanMDg" id="(0.41624365482233505,0.8444444444444444)"/>
</edges>
<edges xmi:type="notation:Connector" xmi:id="_R9IxEOHUEeKCZbxNW-U3VQ" type="4002" source="_z-jdcOHTEeKCZbxNW-U3VQ" target="_52F7ENa7EeKPiuTfpuvqHA" lineColor="0">
@@ -1614,7 +1614,7 @@
<element xmi:type="uml:Generalization" href="layers.uml#_am4OEOHUEeKCZbxNW-U3VQ"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_anKh8uHUEeKCZbxNW-U3VQ" points="[-14, -11, 258, 211]$[-263, -208, 9, 14]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_anQokuHUEeKCZbxNW-U3VQ" id="(0.32,0.11)"/>
- <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_anQok-HUEeKCZbxNW-U3VQ" id="(0.78,0.8782608695652174)"/>
+ <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_anQok-HUEeKCZbxNW-U3VQ" id="(0.4608695652173913,0.9740932642487047)"/>
</edges>
</notation:Diagram>
<notation:Diagram xmi:id="_C_qusNa8EeKPiuTfpuvqHA" type="PapyrusUMLClassDiagram" name="property values" measurementUnit="Pixel">
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 1c7c1bcb720..04dcde06218 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/model/layers.uml
@@ -908,8 +908,8 @@ This class carry a referenceto the Application.</body>
</ownedOperation>
<ownedOperation xmi:type="uml:Operation" xmi:id="_pKKxsBZ0EeOZwp016gnCFQ" name="isDerivedView" raisedException="_iYKFMNxGEeKwptaAAanMDg">
<ownedParameter xmi:type="uml:Parameter" xmi:id="_-UwgIBZ0EeOZwp016gnCFQ" name="res" type="_TqqsYNa8EeKPiuTfpuvqHA" direction="return">
- <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_LLUi4BZ1EeOZwp016gnCFQ"/>
- <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_LLnd0BZ1EeOZwp016gnCFQ" value="*"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_LLUi4BZ1EeOZwp016gnCFQ" value="1"/>
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_LLnd0BZ1EeOZwp016gnCFQ" value="1"/>
</ownedParameter>
<ownedParameter xmi:type="uml:Parameter" xmi:id="_0YIjYFVIEeOah7Z-UYdQAA" name="view">
<type xmi:type="uml:Class" href="notation/notation.uml#_AziHOrcnEeKeLJDBCBPhPw"/>
@@ -949,6 +949,8 @@ This class carry a referenceto the Application.</body>
</ownedParameter>
<ownedParameter xmi:type="uml:Parameter" xmi:id="_X28v8FVKEeOah7Z-UYdQAA" name="res" direction="return">
<type xmi:type="uml:Class" href="notation/notation.uml#_AziHOrcnEeKeLJDBCBPhPw"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_hTG1cFVXEeOeP67GJGKDkA"/>
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_hTG1cVVXEeOeP67GJGKDkA" value="*"/>
</ownedParameter>
</ownedOperation>
</packagedElement>
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcher.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcher.java
index f19b59841c5..8d33a4547c9 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcher.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcher.java
@@ -34,6 +34,9 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.ocl.ParserException;
import org.eclipse.ocl.ecore.OCL;
import org.eclipse.papyrus.layers.stackmodel.LayersException;
+import org.eclipse.papyrus.layers.stackmodel.util.NotyfyingList;
+
+import com.google.common.collect.Lists;
/**
* This class evaluate its associated expression against the associated models.
@@ -48,13 +51,13 @@ import org.eclipse.papyrus.layers.stackmodel.LayersException;
*/
public class ExpressionMatcher {
- protected String expression;
+ protected String expression="";
/**
* List of element matching the expression.
* This class maintains the list.
*/
- protected List<View> matchingElements;
+ protected NotyfyingList<View> matchingElements;
/**
* List of element used as starting point for search.
@@ -68,6 +71,38 @@ public class ExpressionMatcher {
protected OCL ocl;
+ public ExpressionMatcher() {
+ this.expression = "";
+ this.searchRoots = Collections.emptyList();
+ // init matchingElements
+ matchingElements = new NotyfyingList<View>(new ArrayList<View>());
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param searchRoots
+ * @throws LayersException
+ */
+ public ExpressionMatcher(List<EObject> searchRoots) {
+ this.expression = "";
+ this.searchRoots = searchRoots;
+ // init matchingElements
+ matchingElements = new NotyfyingList<View>(new ArrayList<View>());
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param searchRoot
+ * @throws LayersException
+ */
+ public ExpressionMatcher(EObject searchRoot) {
+ this(Collections.singletonList(searchRoot));
+ }
+
/**
* Constructor.
*
@@ -76,13 +111,22 @@ public class ExpressionMatcher {
* @throws LayersException If the Condition can't be computed from the expression.
*/
public ExpressionMatcher(String expression, List<EObject> searchRoots) throws LayersException {
- this.expression = expression;
this.searchRoots = searchRoots;
- matchingElements = new ArrayList<View>();
+ matchingElements = new NotyfyingList<View>(new ArrayList<View>());
// compute expr
- computeCondition();
- refreshMatchingElements();
+ setExpression(expression);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param expression
+ * @param searchRoots
+ * @throws LayersException If the Condition can't be computed from the expression.
+ */
+ public ExpressionMatcher(String expression, EObject searchRoot) throws LayersException {
+ this(expression, Collections.singletonList(searchRoot));
}
/**
@@ -99,6 +143,8 @@ public class ExpressionMatcher {
}
// Create the condition
try {
+ // If the 3rd args is null, this is a context free condition.
+
condition = new BooleanOCLCondition<EClassifier, EClass, EObject>(
ocl.getEnvironment(),
// "self.oclIsKindOf(Shape)",
@@ -106,16 +152,16 @@ public class ExpressionMatcher {
// "self.oclAsType(Shape).visible = true",
getExpression(),
NotationPackage.Literals.VIEW
+// null
);
} catch (ParserException e) {
// TODO Auto-generated catch block
condition = null;
- throw new LayersException("Can't parse expression", e);
+ throw new LayersException("Can't parse expression : " + e.getMessage(), e);
}
}
-
/**
* Recompute the matching elements.
* This lead to firing Events (added and removed)
@@ -152,36 +198,39 @@ public class ExpressionMatcher {
* @param results
*/
private void resetMatchingElements(Collection<?> newElements) {
- // Compute views to add
- // This are views in the newElements, but not in the actual list of matchingElement
- // viewsToAdd = results - getViews()
- List<View> viewsToAdd = new ArrayList<View>();
- for( Object o : newElements ) {
- View v = (View)o;
- if( !getMatchingElements().contains(v)) {
- viewsToAdd.add(v);
- }
- }
- // Compute views to remove
- // Their is two ways to compute it:
- // - viewsToremove = diagramViews - results
- // - or viewsToremove = getViews() - result
- // Use the cheaper one.
- // The computed viewsToRemove list contains also views that are not in the layer,
- // But this is cheaper than checking for the existence.
+ matchingElements.resetTo((Collection<View>)newElements);
-// List<View> viewsToRemove = new ArrayList<View>();
-// for( View v : (views.size()<getViews().size()?views:getViews()) ) {
-// if( !results.contains(v)) {
-// viewsToRemove.add(v);
+// // Compute views to add
+// // This are views in the newElements, but not in the actual list of matchingElement
+// // viewsToAdd = results - getViews()
+// List<View> viewsToAdd = new ArrayList<View>();
+// for( Object o : newElements ) {
+// View v = (View)o;
+// if( !getMatchingElements().contains(v)) {
+// viewsToAdd.add(v);
// }
// }
-
- // Do operations
- getMatchingElements().retainAll(newElements);
-// getViews().removeAll(viewsToRemove);
- getMatchingElements().addAll(viewsToAdd);
+//
+// // Compute views to remove
+// // Their is two ways to compute it:
+// // - viewsToremove = diagramViews - results
+// // - or viewsToremove = getViews() - result
+// // Use the cheaper one.
+// // The computed viewsToRemove list contains also views that are not in the layer,
+// // But this is cheaper than checking for the existence.
+//
+//// List<View> viewsToRemove = new ArrayList<View>();
+//// for( View v : (views.size()<getViews().size()?views:getViews()) ) {
+//// if( !results.contains(v)) {
+//// viewsToRemove.add(v);
+//// }
+//// }
+//
+// // Do operations
+// getMatchingElements().retainAll(newElements);
+//// getViews().removeAll(viewsToRemove);
+// getMatchingElements().addAll(viewsToAdd);
}
@@ -198,6 +247,15 @@ public class ExpressionMatcher {
* @throws LayersException If the Condition can't be computed from the expression.
*/
public void setExpression(String expression) throws LayersException {
+
+ if( expression == null || expression.length() == 0 ) {
+ // standardize noop expr
+ expression = "";
+ }
+ if( expression.equals(this.expression)) {
+ return;
+ }
+
this.expression = expression;
computeCondition();
@@ -208,7 +266,7 @@ public class ExpressionMatcher {
/**
* @return the matchingElements
*/
- public List<View> getMatchingElements() {
+ public NotyfyingList<View> getMatchingElements() {
return matchingElements;
}
@@ -220,5 +278,30 @@ public class ExpressionMatcher {
return searchRoots;
}
+ /**
+ *
+ * @param searchRoots
+ */
+ public void setSearchRoots(List<EObject> searchRoots) {
+ if( searchRoots == null) {
+ searchRoots = Collections.emptyList();
+ }
+ this.searchRoots = searchRoots;
+ // Do not refresh. Let user do it.
+ }
+
+ /**
+ *
+ * @param searchRoots
+ */
+ public void setSearchRoots(EObject searchRoot) {
+ if( searchRoot == null) {
+ searchRoots = Collections.emptyList();
+ return;
+ }
+
+ setSearchRoots( Collections.singletonList(searchRoot) );
+ }
+
}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/RegExpLayer.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/RegExpLayer.java
index 9d173c2a901..d259d1b068a 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/RegExpLayer.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/RegExpLayer.java
@@ -248,10 +248,10 @@ public interface RegExpLayer extends AbstractLayer {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
- * @model dataType="org.eclipse.papyrus.layers.stackmodel.layers.boolean" ordered="false" exceptions="org.eclipse.papyrus.layers.stackmodel.layers.LayersException" viewRequired="true" viewOrdered="false"
+ * @model dataType="org.eclipse.papyrus.layers.stackmodel.layers.boolean" required="true" ordered="false" exceptions="org.eclipse.papyrus.layers.stackmodel.layers.LayersException" viewRequired="true" viewOrdered="false"
* @generated
*/
- EList<Boolean> isDerivedView(View view) throws LayersException;
+ boolean isDerivedView(View view) throws LayersException;
/**
* <!-- begin-user-doc -->
@@ -280,8 +280,8 @@ public interface RegExpLayer extends AbstractLayer {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
- * @model required="true" ordered="false" exceptions="org.eclipse.papyrus.layers.stackmodel.layers.LayersException" viewsMany="true" viewsOrdered="false"
+ * @model ordered="false" exceptions="org.eclipse.papyrus.layers.stackmodel.layers.LayersException" viewsMany="true" viewsOrdered="false"
* @generated
*/
- View lookupDerivedViews(EList<View> views) throws LayersException;
+ EList<View> lookupDerivedViews(EList<View> views) throws LayersException;
} // RegExpLayer
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 64816c0a985..9be752e4abf 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
@@ -3443,7 +3443,7 @@ public class LayersPackageImpl extends EPackageImpl implements LayersPackage {
op = initEOperation(getRegExpLayer__Deactivate__AbstractLayerOperator(), null, "deactivate", 1, 1, IS_UNIQUE, !IS_ORDERED);
addEParameter(op, this.getAbstractLayerOperator(), "oldParentLayer", 1, 1, IS_UNIQUE, !IS_ORDERED);
- op = initEOperation(getRegExpLayer__IsDerivedView__View(), this.getboolean(), "isDerivedView", 0, -1, IS_UNIQUE, !IS_ORDERED);
+ op = initEOperation(getRegExpLayer__IsDerivedView__View(), this.getboolean(), "isDerivedView", 1, 1, IS_UNIQUE, !IS_ORDERED);
addEParameter(op, theNotationPackage.getView(), "view", 1, 1, IS_UNIQUE, !IS_ORDERED);
addEException(op, this.getLayersException());
@@ -3458,7 +3458,7 @@ public class LayersPackageImpl extends EPackageImpl implements LayersPackage {
op = initEOperation(getRegExpLayer__AttachDerivedViews(), null, "attachDerivedViews", 1, 1, IS_UNIQUE, !IS_ORDERED);
addEException(op, this.getLayersException());
- op = initEOperation(getRegExpLayer__LookupDerivedViews__EList(), theNotationPackage.getView(), "lookupDerivedViews", 1, 1, IS_UNIQUE, !IS_ORDERED);
+ op = initEOperation(getRegExpLayer__LookupDerivedViews__EList(), theNotationPackage.getView(), "lookupDerivedViews", 0, -1, IS_UNIQUE, !IS_ORDERED);
addEParameter(op, theNotationPackage.getView(), "views", 0, -1, IS_UNIQUE, !IS_ORDERED);
addEException(op, this.getLayersException());
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/RegExpLayerImpl.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/RegExpLayerImpl.java
index 6d378c4eba0..24ad2517609 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/RegExpLayerImpl.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/impl/RegExpLayerImpl.java
@@ -13,17 +13,33 @@
package org.eclipse.papyrus.layers.stackmodel.layers.impl;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
+import org.eclipse.emf.query.conditions.eobjects.EObjectCondition;
+import org.eclipse.emf.query.ocl.conditions.BooleanOCLCondition;
+import org.eclipse.emf.query.statements.FROM;
+import org.eclipse.emf.query.statements.IQueryResult;
+import org.eclipse.emf.query.statements.SELECT;
+import org.eclipse.emf.query.statements.WHERE;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.ocl.ParserException;
+import org.eclipse.ocl.ecore.OCL;
import org.eclipse.papyrus.layers.stackmodel.LayersException;
import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
+import org.eclipse.papyrus.layers.stackmodel.exprmatcher.ExpressionMatcher;
import org.eclipse.papyrus.layers.stackmodel.layers.AbstractLayerOperator;
import org.eclipse.papyrus.layers.stackmodel.layers.EventLevel;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage;
@@ -31,6 +47,9 @@ import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
import org.eclipse.papyrus.layers.stackmodel.layers.RegExpLayer;
import org.eclipse.papyrus.layers.stackmodel.notifier.DiagramViewEventNotifier;
import org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener;
+import org.eclipse.papyrus.layers.stackmodel.util.NotyfyingList;
+
+import com.google.common.eventbus.Subscribe;
/**
* <!-- begin-user-doc -->
@@ -190,17 +209,11 @@ public class RegExpLayerImpl extends AbstractLayerImpl implements RegExpLayer {
switch(msg.getEventType()) {
case Notification.SET:
//
- Object newValue = msg.getNewValue();
- if( newValue == null) {
- deactivate((AbstractLayerOperator)msg.getOldValue());
- }
- else {
- activate((AbstractLayerOperator)msg.getNewValue());
- }
+ parentLayerChanged((AbstractLayerOperator)msg.getNewValue(), (AbstractLayerOperator)msg.getOldValue());
break;
case Notification.UNSET:
- deactivate((AbstractLayerOperator)msg.getOldValue());
+ parentLayerChanged((AbstractLayerOperator)msg.getNewValue(), (AbstractLayerOperator)msg.getOldValue());
break;
default:
@@ -212,6 +225,11 @@ public class RegExpLayerImpl extends AbstractLayerImpl implements RegExpLayer {
};
protected DiagramViewEventNotifier diagramViewEventNotifier;
+
+ /**
+ * Expression matcher computing the expr, and firing events when the matching elements change.
+ */
+ protected ExpressionMatcher expressionMatcher;
/**
* <!-- begin-user-doc -->
@@ -220,9 +238,16 @@ public class RegExpLayerImpl extends AbstractLayerImpl implements RegExpLayer {
*/
protected RegExpLayerImpl() {
super();
+
+ // Initialize expressionmatcher
+ expressionMatcher = new ExpressionMatcher();
+ resetExpressionMatcherRoots();
+
+ // listen to expression matcher changes
+ expressionMatcher.getMatchingElements().getEventBus().register(this);
+
// Listen on this object attachment / detachment from its container.
eAdapters().add(containerListener);
-
}
/**
@@ -247,16 +272,33 @@ public class RegExpLayerImpl extends AbstractLayerImpl implements RegExpLayer {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
- * @generated
+ * @generated NOT
*/
public void setExpr(String newExpr) {
String oldExpr = expr;
expr = newExpr;
+ // Try to set the expression
+ try {
+ // First, reset expr roots. Do it because actually the roots are not properly set.
+ resetExpressionMatcherRoots();
+ // Change the expression, and recompute the matching elements.
+ expressionMatcher.setExpression(newExpr);
+ expressionMatcher.refreshMatchingElements();
+ } catch (LayersException e) {
+ // silently fails, but log the error.
+ System.err.println( "Error - " + this.getClass().getSimpleName() + " - " + e.getMessage());
+ }
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, LayersPackage.REG_EXP_LAYER__EXPR, oldExpr, expr));
}
/**
+ * OCL Condition computed from the expr.
+ */
+ protected EObjectCondition condition;
+ protected OCL ocl;
+
+ /**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
@@ -383,6 +425,57 @@ public class RegExpLayerImpl extends AbstractLayerImpl implements RegExpLayer {
}
/**
+ * The parent that contains this Layer has changed.
+ * Check if the associated Diagram has changed, and if true, change it in the ExpressionMatcher.
+ *
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param newLayerParent
+ * @generated NOT
+ */
+ public void parentLayerChanged(AbstractLayerOperator newLayerParent, AbstractLayerOperator oldLayerParent) {
+
+ // Try to change the diagram in the expressionMatcher.
+ // The expressionMatcher takes care to change it only if it this changed.
+ resetExpressionMatcherRoots();
+ }
+
+ /**
+ * Listener on {@link NotyfyingList} eventBus. This method is called each time a change occurs in the
+ * result of the expression.
+ * When the result change, the list of attached views is updated accordingly.
+ *
+ *
+ * @param event
+ */
+ @Subscribe
+ public void expressionResultChanged( NotyfyingList<View>.NotifyingListEvent event) {
+
+ System.out.println( this.getClass().getSimpleName() + ".expressionResultChanged()");
+ if( ! event.getAddedElements().isEmpty()) {
+ getViews().addAll(event.getAddedElements());
+ }
+ if( ! event.getRemovedElements().isEmpty()) {
+ getViews().removeAll(event.getRemovedElements());
+ }
+
+ }
+
+ /**
+ * Check if the associated Diagram has changed, and if true, change it in the ExpressionMatcher.
+ */
+ private void resetExpressionMatcherRoots() {
+
+ try {
+ expressionMatcher.setSearchRoots( getLayersStack().getDiagram() );
+ } catch (NotFoundException e) {
+ // layerStack not found ==> no roots
+ expressionMatcher.setSearchRoots( (List<EObject>)Collections.EMPTY_LIST);
+ }
+
+ }
+
+ /**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param newLayerParent
@@ -434,56 +527,215 @@ public class RegExpLayerImpl extends AbstractLayerImpl implements RegExpLayer {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
- * @generated
+ * @generated NOT
*/
- public EList<Boolean> isDerivedView(View view) throws LayersException {
- // TODO: implement this method
- // Ensure that you remove @generated or mark it @generated NOT
- throw new UnsupportedOperationException();
+ public boolean isDerivedView(View view) throws LayersException {
+
+ if(condition == null) {
+ return false;
+ }
+
+ // Create the OCL statement
+ SELECT statement = new SELECT(SELECT.UNBOUNDED, false,
+ new FROM(view), new WHERE(condition),
+ new NullProgressMonitor());
+
+ // Execute the OCL statement
+ IQueryResult results = statement.execute();
+
+ // the view is derived if the condition match the view.
+ return !results.isEmpty();
}
/**
* <!-- begin-user-doc -->
+ * Check if the view satisfy the expr condition.
+ * If the condition is satisfied, ensure that the view is attached.
+ * If the condition is not satisfied, ensure that the view is not attached.
+ *
+ *
* <!-- end-user-doc -->
- * @generated
+ * @generated NOT
*/
public void attachDerivedView(View view) throws LayersException {
// TODO: implement this method
- // Ensure that you remove @generated or mark it @generated NOT
- throw new UnsupportedOperationException();
+ if(condition == null) {
+ return;
+ }
+
+ // Create the OCL statement
+ SELECT statement = new SELECT(SELECT.UNBOUNDED, false,
+ new FROM(view), new WHERE(condition),
+ new NullProgressMonitor());
+
+ // Execute the OCL statement
+ IQueryResult results = statement.execute();
+
+ //
+ if( ! results.isEmpty()) {
+ // The condition is satisfied. Ensure the view is attached
+ List<View> attachedViews = getViews();
+ if (attachedViews.contains(view)) {
+ return;
+ }
+ attachedViews.add(view);
+ }
+ else {
+ // The condition is not satisfied. Ensure the view is not attached.
+ getViews().remove(view);
+ }
}
/**
* <!-- begin-user-doc -->
+ * Attach each view that satisfy the condition.
+ * Detach each view that do not satisfy the condition.
+ * TODO rename to updateDerivedViews() ?
* <!-- end-user-doc -->
- * @generated
+ * @generated NOT
*/
public void attachDerivedViews(EList<View> views) throws LayersException {
- // TODO: implement this method
- // Ensure that you remove @generated or mark it @generated NOT
- throw new UnsupportedOperationException();
+
+ if(condition == null) {
+ return;
+ }
+
+ // Create the OCL statement
+ SELECT statement = new SELECT(SELECT.UNBOUNDED, false,
+ new FROM(views), new WHERE(condition),
+ new NullProgressMonitor());
+
+ // Execute the OCL statement
+ IQueryResult results = statement.execute();
+
+ // viewsToCheck
+ // attachedViews -- list of views that are attached
+ // -- getViews()
+ // viewsToAttach -- list of views that should be attached
+ // -- query result
+ // toAdd - views that are in viewsToAttach, but not in attachedViews
+ // --
+ // toRemove - views that are in attachedViews, and viewsToCheck, but not in viewsToAttach
+
+ // Compute views to add
+ // This are views in the result, but not in the list of attached
+ // viewsToAdd = results - getViews()
+ List<View> viewsToAdd = new ArrayList<View>();
+ List<View> attachedViews = getViews();
+ for( Object o : results ) {
+ View v = (View)o;
+ if( !attachedViews.contains(v)) {
+ viewsToAdd.add(v);
+ }
+ }
+
+ // Compute views to remove
+ // Their is two ways to compute it:
+ // - viewsToremove = diagramViews - results
+ // - or viewsToremove = getViews() - result
+ // Use the cheaper one.
+ // The computed viewsToRemove list contains also views that are not in the layer,
+ // But this is cheaper than checking for the existence.
+
+ List<View> viewsToRemove = new ArrayList<View>();
+ for( View v : (views.size()<getViews().size()?views:getViews()) ) {
+ if( !results.contains(v)) {
+ viewsToRemove.add(v);
+ }
+ }
+
+ // Do operations
+ getViews().removeAll(viewsToRemove);
+ getViews().addAll(viewsToAdd);
}
/**
* <!-- begin-user-doc -->
+ * Update all views directly own by the diagram.
+ *
+ * If a view satisfy the expr condition, attach it to the Layer.
+ * Remove all others view from the layer.
+ * <br>
+ * To avoid multiple events, we compute the list of views to remove from the layer, and the list
+ * of views to add to layer. Then, we preform two operations; removeAll(toRemove) and addAll(toAdd);
+ *
* <!-- end-user-doc -->
- * @generated
+ * @generated NOT
*/
public void attachDerivedViews() throws LayersException {
- // TODO: implement this method
- // Ensure that you remove @generated or mark it @generated NOT
- throw new UnsupportedOperationException();
+
+ if(condition == null) {
+ return;
+ }
+
+ // Check views from the diagram.
+ @SuppressWarnings("unchecked")
+ EList<View> diagramViews = (EList<View>)getLayersStack().getDiagram().getChildren();
+
+ // Create the OCL statement
+ SELECT statement = new SELECT(SELECT.UNBOUNDED, false,
+ new FROM(diagramViews), new WHERE(condition),
+ new NullProgressMonitor());
+
+ // Execute the OCL statement
+ IQueryResult results = statement.execute();
+
+ // Compute views to add
+ // This are views in the result, but not in the list of attached
+ // viewsToAdd = results - getViews()
+ List<View> viewsToAdd = new ArrayList<View>();
+ List<View> attachedViews = getViews();
+ for( Object o : results ) {
+ View v = (View)o;
+ if( !attachedViews.contains(v)) {
+ viewsToAdd.add(v);
+ }
+ }
+
+ // Compute views to remove
+ // Their is two ways to compute it:
+ // - viewsToremove = diagramViews - results
+ // - or viewsToremove = getViews() - result
+ // Use the cheaper one.
+ // The computed viewsToRemove list contains also views that are not in the layer,
+ // But this is cheaper than checking for the existence.
+
+// List<View> viewsToRemove = new ArrayList<View>();
+// for( View v : (views.size()<getViews().size()?views:getViews()) ) {
+// if( !results.contains(v)) {
+// viewsToRemove.add(v);
+// }
+// }
+
+ // Do operations
+ getViews().retainAll(results);
+// getViews().removeAll(viewsToRemove);
+ getViews().addAll(viewsToAdd);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
- * @generated
+ * @generated NOT
*/
- public View lookupDerivedViews(EList<View> views) throws LayersException {
- // TODO: implement this method
- // Ensure that you remove @generated or mark it @generated NOT
- throw new UnsupportedOperationException();
+ public EList<View> lookupDerivedViews(EList<View> views) throws LayersException {
+// if(condition == null) {
+// return EList.EMPTY_LIST;
+// }
+//
+// // Check views from the diagram.
+// @SuppressWarnings("unchecked")
+// EList<View> diagramViews = (EList<View>)getLayersStack().getDiagram().getChildren();
+//
+// // Create the OCL statement
+// SELECT statement = new SELECT(SELECT.UNBOUNDED, false,
+// new FROM(diagramViews), new WHERE(condition),
+// new NullProgressMonitor());
+//
+// // Execute the OCL statement
+// IQueryResult results = statement.execute();
+// return new ;
+ return null;
}
/**
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingList.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingList.java
index 007160bfd95..228930b6f9a 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingList.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingList.java
@@ -19,8 +19,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import org.eclipse.gmf.runtime.notation.View;
-
import com.google.common.collect.ForwardingList;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcherTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcherTest.java
index d33830e3ef1..567cf6343e7 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcherTest.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ExpressionMatcherTest.java
@@ -14,10 +14,13 @@
package org.eclipse.papyrus.layers.stackmodel.exprmatcher;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
-import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
@@ -27,13 +30,17 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.layers.stackmodel.LayersException;
+import org.eclipse.papyrus.layers.stackmodel.util.FakeNotifyingListListener;
+import org.eclipse.papyrus.layers.stackmodel.util.NotyfyingList;
+import org.eclipse.uml2.uml.NamedElement;
import org.junit.After;
-import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
-import org.junit.experimental.categories.Categories.ExcludeCategory;
/**
* @author cedric dumoulin
@@ -114,6 +121,34 @@ public class ExpressionMatcherTest {
}
/**
+ * Test an expression
+ * @throws LayersException
+ */
+ @Test
+ public void testExpression() throws LayersException {
+
+// Shape s;
+// ((NamedElement)s.getElement()).getName().startsWith(prefix);
+
+ String expression = "self.element.oclAsType(uml::NamedElement).name.startsWith('C') = true";
+// self.oclAsType(Shape).element.oclAsType(uml::NamedElement).name.startsWith('C') = true
+// "self.element.oclAsType(uml::NamedElement).name.startsWith('C') = true";
+// "self.oclIsKindOf(Shape)",
+// "self.oclIsKindOf(Shape) and self.oclAsType(Shape).visible = true",
+// "self.oclAsType(Shape).visible = true",
+
+ String modelFileName = "/test/models/model1";
+ Diagram diagram = getDiagram(modelFileName);
+ List<EObject> searchRoots = diagram.getChildren();
+
+ ExpressionMatcher expressionMatcher = new ExpressionMatcher(expression, searchRoots);
+ assertNotNull("object created", expressionMatcher);
+
+ assertTrue("result not empty", !expressionMatcher.getMatchingElements().isEmpty());
+
+ }
+
+ /**
* Test method for {@link org.eclipse.papyrus.layers.stackmodel.exprmatcher.ExpressionMatcher#ExpressionMatcher(java.lang.String, java.util.List)}.
* @throws LayersException
*/
@@ -258,5 +293,155 @@ public class ExpressionMatcherTest {
assertNotNull("Diagram exist", diagram);
}
-
+ /**
+ * Test removing elements.
+ * @throws LayersException
+ */
+ @Test
+ public void testRemoveElements() throws LayersException {
+ String expression = "self.oclIsKindOf(Shape)";
+// "self.oclIsKindOf(Shape)",
+// "self.oclIsKindOf(Shape) and self.oclAsType(Shape).visible = true",
+// "self.oclAsType(Shape).visible = true",
+
+ String modelFileName = "/test/models/model1";
+ Diagram diagram = getDiagram(modelFileName);
+
+ int removedElementCount = 5;
+ int addedElementCount = 0;
+ int expectedEventCount = 1;
+
+ FakeNotifyingListListener<View> notifyingListListener = new FakeNotifyingListListener<View>();
+ ExpressionMatcher expressionMatcher = new ExpressionMatcher(expression, diagram);
+
+ expressionMatcher.getMatchingElements().getEventBus().register(notifyingListListener);
+
+ // Action
+ notifyingListListener.traces.clear();
+ removeElements(diagram, removedElementCount);
+ expressionMatcher.refreshMatchingElements();
+
+ // Assert
+ assertSame("event propagated", expectedEventCount, notifyingListListener.traces.size());
+
+ NotyfyingList<View>.NotifyingListEvent event = notifyingListListener.traces.get(0).notifier;
+
+ assertEquals("expected removed count", removedElementCount, event.getRemovedElements().size());
+ assertEquals("expected added count", addedElementCount, event.getAddedElements().size());
+ }
+
+ /**
+ * Test removing elements.
+ * @throws LayersException
+ */
+ @Test
+ public void testAddElements() throws LayersException {
+ String expression = "self.oclIsKindOf(Shape)";
+// "self.oclIsKindOf(Shape)",
+// "self.oclIsKindOf(Shape) and self.oclAsType(Shape).visible = true",
+// "self.oclAsType(Shape).visible = true",
+
+ String modelFileName = "/test/models/model1";
+ Diagram diagram = getDiagram(modelFileName);
+
+ int removedElementCount = 0;
+ int addedElementCount = 5;
+ int expectedEventCount = 1;
+ int viewsCount = diagram.getChildren().size();
+
+ FakeNotifyingListListener<View> notifyingListListener = new FakeNotifyingListListener<View>();
+ ExpressionMatcher expressionMatcher = new ExpressionMatcher(expression, diagram);
+
+ expressionMatcher.getMatchingElements().getEventBus().register(notifyingListListener);
+
+ // Action
+ notifyingListListener.traces.clear();
+ addShapeElements(diagram, addedElementCount);
+ removeElements(diagram, removedElementCount);
+ expressionMatcher.refreshMatchingElements();
+
+ // Assert
+ assertSame("elements added", viewsCount+addedElementCount, diagram.getChildren().size());
+
+ assertSame("event propagated", expectedEventCount, notifyingListListener.traces.size());
+
+ NotyfyingList<View>.NotifyingListEvent event = notifyingListListener.traces.get(0).notifier;
+
+ assertEquals("expected removed count", removedElementCount, event.getRemovedElements().size());
+ assertEquals("expected added count", addedElementCount, event.getAddedElements().size());
+ }
+
+ /**
+ * Test removing elements.
+ * @throws LayersException
+ */
+ @Test
+ public void testAddAndRemoveElements() throws LayersException {
+ String expression = "self.oclIsKindOf(Shape)";
+// "self.oclIsKindOf(Shape)",
+// "self.oclIsKindOf(Shape) and self.oclAsType(Shape).visible = true",
+// "self.oclAsType(Shape).visible = true",
+
+ String modelFileName = "/test/models/model1";
+ Diagram diagram = getDiagram(modelFileName);
+
+ int removedElementCount = 4;
+ int addedElementCount = 5;
+ int expectedEventCount = 1;
+ int viewsCount = diagram.getChildren().size();
+
+ FakeNotifyingListListener<View> notifyingListListener = new FakeNotifyingListListener<View>();
+ ExpressionMatcher expressionMatcher = new ExpressionMatcher(expression, diagram);
+
+ expressionMatcher.getMatchingElements().getEventBus().register(notifyingListListener);
+
+ // Action
+ notifyingListListener.traces.clear();
+ removeElements(diagram, removedElementCount);
+ addShapeElements(diagram, addedElementCount);
+ expressionMatcher.refreshMatchingElements();
+
+ // Assert
+ assertSame("elements added", viewsCount+addedElementCount-removedElementCount, diagram.getChildren().size());
+
+ assertSame("event propagated", expectedEventCount, notifyingListListener.traces.size());
+
+ NotyfyingList<View>.NotifyingListEvent event = notifyingListListener.traces.get(0).notifier;
+
+ assertEquals("expected removed count", removedElementCount, event.getRemovedElements().size());
+ assertEquals("expected added count", addedElementCount, event.getAddedElements().size());
+ }
+
+
+ /**
+ * Remove n Views from the provided diagram
+ * @param diagram
+ * @param removedElementCount
+ */
+ private void removeElements(Diagram diagram, int removedElementCount) {
+
+ List<View> views = diagram.getChildren();
+
+ int index = views.size()-1;
+ for( int i=0; i<removedElementCount&&index>=0; i++) {
+ diagram.removeChild(views.get(index));
+ index = views.size()-1;
+ }
+
+ }
+
+ /**
+ * Add n Views to the provided diagram
+ * @param diagram
+ * @param removedElementCount
+ */
+ private void addShapeElements(Diagram diagram, int elementCount) {
+
+ for( int i=0; i<elementCount; i++) {
+ diagram.createChild(NotationPackage.eINSTANCE.getShape());
+ }
+
+ }
+
+
}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingListTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingListTest.java
index 5d4b0b4893e..7179a150157 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingListTest.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotyfyingListTest.java
@@ -385,7 +385,7 @@ public class NotyfyingListTest {
* Test method for {@link org.eclipse.papyrus.layers.stackmodel.util.NotyfyingList#resetTo(java.util.Collection)}.
*/
@Test
- public void testResetToNoRemoved() {
+ public void testResetToWithAddition() {
List<String> list = Lists.newArrayList( "red", "orange", "yellow", "green", "blue", "purple");
List<String> listToReset = Lists.newArrayList( "red", "orange", "yellow", "green", "blue", "purple", "falseColor");

Back to the top