Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2013-12-16 22:27:56 +0000
committerCedric Dumoulin2014-01-27 13:57:05 +0000
commitcfcc88475333a2a6d19969ede230e03079c3c17e (patch)
tree513cd074d0c8051a93fa9a18b64dd0df9a2a1364 /extraplugins/layers/org.eclipse.papyrus.layers.stackmodel
parentf5ad47b005bdfe19ec3b801c1175093f8afc8ac8 (diff)
downloadorg.eclipse.papyrus-cfcc88475333a2a6d19969ede230e03079c3c17e.tar.gz
org.eclipse.papyrus-cfcc88475333a2a6d19969ede230e03079c3c17e.tar.xz
org.eclipse.papyrus-cfcc88475333a2a6d19969ede230e03079c3c17e.zip
Bug 330199 - Add ValueChangedNotifier for ExpressionMatcher.
This version has a bug: the notifier is not propagated to domain element, because they are simple references (not containment).
Diffstat (limited to 'extraplugins/layers/org.eclipse.papyrus.layers.stackmodel')
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/IValueChangedEventListener.java35
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifier.java237
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactory.java68
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IUmlNamedElementChangedEventListener.java34
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifier.java176
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactory.java68
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/TraceValueChangedEventListener.java40
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactoryTest.java95
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierTest.java222
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceDiagramViewChangedEventListener.java2
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceUmlNamedElementChangedEventListener.java40
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactoryTest.java95
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierTest.java201
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactory.java21
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactoryTest.java17
15 files changed, 1350 insertions, 1 deletions
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/IValueChangedEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/IValueChangedEventListener.java
new file mode 100644
index 00000000000..e86f28addbe
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/IValueChangedEventListener.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.exprmatcher;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+
+
+/**
+ * Class implementing this interface can listen to event from EObject.
+ * This class is used by {@link ExpressionMatcher} to be informed when it need to be refreshed.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public interface IValueChangedEventListener {
+
+ /**
+ * Called by events when a property is changed in a {@link EObject}
+ *
+ * @param msg
+ */
+ public void valueChanged(Notification msg) ;
+
+
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifier.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifier.java
new file mode 100644
index 00000000000..6ba78501945
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifier.java
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * 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.exprmatcher;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
+import org.eclipse.papyrus.layers.stackmodel.notifier.LayersTreeEventNotifier;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.UMLPackage;
+
+
+/**
+ * An EMF {@link Adapter} listening on uml::NamedElement properties changes.
+ *
+ * This class listen to a {@link NamedElement} and send following events to listeners:
+ * <ul>
+ * <li>valueChanged</li>
+ * </ul>
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ValueChangedEventNotifier extends EContentAdapter {
+
+ boolean isDisposed = false;
+
+ /**
+ * List of listener to notify.
+ */
+ protected List<IValueChangedEventListener> listeners = new ArrayList<IValueChangedEventListener>();
+
+ /**
+ * Something happen on the tree of object
+ * @see org.eclipse.emf.ecore.util.EContentAdapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param msg
+ */
+ public void notifyChanged(Notification notification) {
+
+ // Self atttach
+ super.notifyChanged(notification);
+
+ if( isDiagramRootView(notification)) {
+ fireValueChangedEvent(notification);
+ }
+ else if ( isUmlDomainElementChanged(notification)) {
+ fireValueChangedEvent(notification);
+ }
+
+
+// // We are only interested in NamedElement (from newValue if set, or oldValue if removed)
+// Object newValue = notification.getNewValue();
+// if( ! (newValue instanceof NamedElement || notification.getOldValue() instanceof NamedElement ) ) {
+// return;
+// }
+// // Check diagram modification
+// // There is 4 sources: View::persistedChildren and View::transientChildren
+// // Diagram::persistedChildren and Diagram::transientChildren
+// Object feature = notification.getFeature();
+// if( feature == UMLPackage.eINSTANCE.getNamedElement()
+// || feature == NotationPackage.eINSTANCE.getView_TransientChildren()
+// || feature == NotationPackage.eINSTANCE.getDiagram_PersistedEdges()
+// || feature == NotationPackage.eINSTANCE.getDiagram_TransientEdges() ) {
+// // LayerOperator::layers || LayersStack::layers
+// // check the event type.
+// switch(notification.getEventType()) {
+// case Notification.SET:
+//
+// break;
+// case Notification.ADD:
+// // A view is added
+// fireValueChangedEvent(notification);
+// break;
+// case Notification.REMOVE:
+// // A layer is removed
+// fireDiagramViewRemovedEvent(notification);
+// break;
+// }
+// }
+
+ };
+
+ /**
+ * Return true if the notification indicates a change in a uml element.
+ * @param notification
+ * @return
+ */
+ private boolean isUmlDomainElementChanged(Notification notification) {
+ // Notifier should be the diagram
+ if( ! (notification.getNotifier() instanceof NamedElement) ) {
+ return false;
+ }
+
+ Object feature = notification.getFeature();
+
+ if( feature == UMLPackage.eINSTANCE.getNamedElement_Name() ) {
+ // check the event type.
+ switch(notification.getEventType()) {
+ case Notification.SET:
+ case Notification.ADD:
+ case Notification.REMOVE:
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return true if the notification indicates that a Diagram root view is modifified.
+ * @param notification
+ * @return
+ */
+ private boolean isDiagramRootView(Notification notification) {
+
+ // Notifier should be the diagram
+ if( ! (notification.getNotifier() instanceof Diagram) ) {
+ return false;
+ }
+
+ Object feature = notification.getFeature();
+
+ if( feature == NotationPackage.eINSTANCE.getView_PersistedChildren()
+ || feature == NotationPackage.eINSTANCE.getView_TransientChildren()
+ || feature == NotationPackage.eINSTANCE.getDiagram_PersistedEdges()
+ || feature == NotationPackage.eINSTANCE.getDiagram_TransientEdges() ) {
+ // LayerOperator::layers || LayersStack::layers
+ // check the event type.
+ switch(notification.getEventType()) {
+ case Notification.SET:
+ case Notification.ADD:
+ case Notification.REMOVE:
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 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 == ValueChangedEventNotifier.class;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param layersModel
+ */
+ public ValueChangedEventNotifier() {
+ }
+
+ /**
+ * Dispose the synchronizer
+ */
+ public void dispose() {
+
+ if(isDisposed()) {
+ return;
+ }
+
+ isDisposed = true;
+ listeners.clear();
+ }
+
+ /**
+ * Return true if the object is disposed.
+ * @return
+ */
+ public boolean isDisposed() {
+ return isDisposed == true;
+ }
+
+ /**
+ * 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 addEventListener(IValueChangedEventListener 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 removeEventListener(IValueChangedEventListener listener) {
+
+ listeners.remove(listener);
+ }
+
+ /**
+ * Called by events when a {@link LayersStack} is added to the {@link LayersStackApplication}
+ * @param msg
+ */
+ protected void fireValueChangedEvent(Notification msg) {
+ for(IValueChangedEventListener listener : listeners) {
+ listener.valueChanged(msg);
+ }
+ }
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactory.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactory.java
new file mode 100644
index 00000000000..e0f85d0b97f
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactory.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.exprmatcher;
+
+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 ValueChangedEventNotifier}.
+ * The factory ensures that there is only one Notifier for a given {@link LayersStack}.
+ * @author cedric dumoulin
+ *
+ */
+public class ValueChangedEventNotifierFactory extends AdapterFactoryImpl {
+
+ /**
+ * Global factory.
+ */
+ static public ValueChangedEventNotifierFactory instance = new ValueChangedEventNotifierFactory();
+
+ /**
+ * Convenience method.
+ * @param target
+ * @return
+ */
+ public ValueChangedEventNotifier adapt(Notifier target) {
+ return (ValueChangedEventNotifier)adapt(target, ValueChangedEventNotifier.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 ValueChangedEventNotifier();
+ }
+
+ /**
+ * This Factory is for {@link ValueChangedEventNotifier}.
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#isFactoryForType(java.lang.Object)
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean isFactoryForType(Object type) {
+ return type == ValueChangedEventNotifier.class;
+ }
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IUmlNamedElementChangedEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IUmlNamedElementChangedEventListener.java
new file mode 100644
index 00000000000..b2b2a24d842
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IUmlNamedElementChangedEventListener.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.uml2.uml.NamedElement;
+
+
+/**
+ * Class implementing this interface can listen to event from a {@link NamedElement}.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public interface IUmlNamedElementChangedEventListener {
+
+ /**
+ * Called by events when a property is changed in a {@link NamedElement}
+ *
+ * @param msg
+ */
+ public void valueChanged(Notification msg) ;
+
+
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifier.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifier.java
new file mode 100644
index 00000000000..d1602eab3fb
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifier.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * 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.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.util.EContentAdapter;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
+import org.eclipse.uml2.uml.NamedElement;
+
+
+/**
+ * An EMF {@link Adapter} listening on uml::NamedElement properties changes.
+ *
+ * This class listen to a {@link NamedElement} and send following events to listeners:
+ * <ul>
+ * <li>valueChanged</li>
+ * </ul>
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class UmlNamedElementChangedEventNotifier extends EContentAdapter {
+
+ boolean isDisposed = false;
+
+ /**
+ * List of listener to notify.
+ */
+ protected List<IUmlNamedElementChangedEventListener> listeners = new ArrayList<IUmlNamedElementChangedEventListener>();
+
+ /**
+ * Something happen on the tree of object
+ * @see org.eclipse.emf.ecore.util.EContentAdapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param msg
+ */
+ public void notifyChanged(Notification notification) {
+
+ // Self atttach
+ super.notifyChanged(notification);
+
+ // Retain only NamedElement
+ if( ! (notification.getNotifier() instanceof NamedElement) ) {
+ return;
+ }
+
+ // No more filter: all events are forwarded
+ fireValueChangedEvent(notification);
+
+// // We are only interested in NamedElement (from newValue if set, or oldValue if removed)
+// Object newValue = notification.getNewValue();
+// if( ! (newValue instanceof NamedElement || notification.getOldValue() instanceof NamedElement ) ) {
+// return;
+// }
+// // Check diagram modification
+// // There is 4 sources: View::persistedChildren and View::transientChildren
+// // Diagram::persistedChildren and Diagram::transientChildren
+// Object feature = notification.getFeature();
+// if( feature == UMLPackage.eINSTANCE.getNamedElement()
+// || feature == NotationPackage.eINSTANCE.getView_TransientChildren()
+// || feature == NotationPackage.eINSTANCE.getDiagram_PersistedEdges()
+// || feature == NotationPackage.eINSTANCE.getDiagram_TransientEdges() ) {
+// // LayerOperator::layers || LayersStack::layers
+// // check the event type.
+// switch(notification.getEventType()) {
+// case Notification.SET:
+//
+// break;
+// case Notification.ADD:
+// // A view is added
+// fireValueChangedEvent(notification);
+// break;
+// case Notification.REMOVE:
+// // A layer is removed
+// fireDiagramViewRemovedEvent(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 == UmlNamedElementChangedEventNotifier.class;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param layersModel
+ */
+ public UmlNamedElementChangedEventNotifier() {
+ }
+
+ /**
+ * Dispose the synchronizer
+ */
+ public void dispose() {
+
+ if(isDisposed()) {
+ return;
+ }
+
+ isDisposed = true;
+ listeners.clear();
+ }
+
+ /**
+ * Return true if the object is disposed.
+ * @return
+ */
+ public boolean isDisposed() {
+ return isDisposed == true;
+ }
+
+ /**
+ * 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 addEventListener(IUmlNamedElementChangedEventListener 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 removeEventListener(IUmlNamedElementChangedEventListener listener) {
+
+ listeners.remove(listener);
+ }
+
+ /**
+ * Called by events when a {@link LayersStack} is added to the {@link LayersStackApplication}
+ * @param msg
+ */
+ protected void fireValueChangedEvent(Notification msg) {
+ for(IUmlNamedElementChangedEventListener listener : listeners) {
+ listener.valueChanged(msg);
+ }
+ }
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactory.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactory.java
new file mode 100644
index 00000000000..3b0dc5f37e9
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactory.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 UmlNamedElementChangedEventNotifier}.
+ * The factory ensures that there is only one Notifier for a given {@link LayersStack}.
+ * @author cedric dumoulin
+ *
+ */
+public class UmlNamedElementChangedEventNotifierFactory extends AdapterFactoryImpl {
+
+ /**
+ * Global factory.
+ */
+ static public UmlNamedElementChangedEventNotifierFactory instance = new UmlNamedElementChangedEventNotifierFactory();
+
+ /**
+ * Convenience method.
+ * @param target
+ * @return
+ */
+ public UmlNamedElementChangedEventNotifier adapt(Notifier target) {
+ return (UmlNamedElementChangedEventNotifier)adapt(target, UmlNamedElementChangedEventNotifier.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 UmlNamedElementChangedEventNotifier();
+ }
+
+ /**
+ * This Factory is for {@link UmlNamedElementChangedEventNotifier}.
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#isFactoryForType(java.lang.Object)
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean isFactoryForType(Object type) {
+ return type == UmlNamedElementChangedEventNotifier.class;
+ }
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/TraceValueChangedEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/TraceValueChangedEventListener.java
new file mode 100644
index 00000000000..22992024d83
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/TraceValueChangedEventListener.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.exprmatcher;
+
+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 TraceValueChangedEventListener implements IValueChangedEventListener {
+
+ 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 valueChanged(Notification notification) {
+ traces.addTrace("valueChanged", notification);
+
+ }
+
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactoryTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactoryTest.java
new file mode 100644
index 00000000000..0655006d468
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierFactoryTest.java
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * 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.exprmatcher;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory;
+import org.eclipse.uml2.uml.Class;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class ValueChangedEventNotifierFactoryTest {
+
+ /**
+ * @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 testValueChangedEventNotifierFactory() {
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ // Action
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(c1, ValueChangedEventNotifier.class);
+
+ // Assert
+ assertNotNull("object created", eventNotifier);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#AdapterFactoryImpl()}.
+ */
+ @Test
+ public void testReturnSameInstanceImpl() {
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+ Class c2 = modelsFactory.newClass(diagram1, "C2");
+
+ // Action
+ ValueChangedEventNotifier eventNotifier11 = (ValueChangedEventNotifier)notifierFactory.adapt(c1, ValueChangedEventNotifier.class);
+ ValueChangedEventNotifier eventNotifier12 = (ValueChangedEventNotifier)notifierFactory.adapt(c1, ValueChangedEventNotifier.class);
+
+ ValueChangedEventNotifier eventNotifier21 = (ValueChangedEventNotifier)notifierFactory.adapt(c2, ValueChangedEventNotifier.class);
+ ValueChangedEventNotifier eventNotifier22 = (ValueChangedEventNotifier)notifierFactory.adapt(c2, ValueChangedEventNotifier.class);
+
+ // Assert
+ assertNotNull("object created", eventNotifier11);
+ assertNotNull("object created", eventNotifier21);
+
+ assertNotEquals("instance are different between diagram", 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/exprmatcher/ValueChangedEventNotifierTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierTest.java
new file mode 100644
index 00000000000..0ca2083725d
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/exprmatcher/ValueChangedEventNotifierTest.java
@@ -0,0 +1,222 @@
+/*****************************************************************************
+ * 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.exprmatcher;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory;
+import org.eclipse.papyrus.layers.stackmodel.util.TriggeredEventTraces;
+import org.eclipse.papyrus.layers.stackmodel.util.TriggeredEventTraces.TriggeredEvent;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Property;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class ValueChangedEventNotifierTest {
+
+ /**
+ * @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.stackmodel.notifier.ValueChangedEventNotifier#ValueChangedEventNotifier()}.
+ */
+ @Test
+ public void testValueChangedEventNotifier() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(c1, ValueChangedEventNotifier.class);
+
+ // Assert
+ assertNotNull("notifier created", eventNotifier);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.ValueChangedEventNotifier#addEventListener(org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener)}.
+ */
+ @Test
+ public void testAddEventListener() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(diagram1, ValueChangedEventNotifier.class);
+
+ TraceValueChangedEventListener listener = new TraceValueChangedEventListener();
+ eventNotifier.addEventListener(listener);
+
+ // Assert
+ assertTrue("listener added", eventNotifier.listeners.contains(listener));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.ValueChangedEventNotifier#removeEventListener(org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener)}.
+ */
+ @Test
+ public void testRemoveEventListener() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(diagram1, ValueChangedEventNotifier.class);
+
+ TraceValueChangedEventListener listener = new TraceValueChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ eventNotifier.removeEventListener(listener);
+
+ // Assert
+ assertFalse("listener removed", eventNotifier.listeners.contains(listener));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.ValueChangedEventNotifier#fireDiagramViewAddedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testNameChangedEvent() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(diagram1, ValueChangedEventNotifier.class);
+
+ TraceValueChangedEventListener listener = new TraceValueChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ int expectedEventCount = 1;
+
+ // Action
+ traces.clear();
+ // Modify ele
+ c1.setName("newName");
+
+ // Assert
+ // Assert
+ assertTrue("event recorded", traces.contains("valueChanged"));
+ assertEquals("right number of events", expectedEventCount, traces.traces.size() );
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.ValueChangedEventNotifier#fireDiagramViewRemovedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testPropertyAdded() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(diagram1, ValueChangedEventNotifier.class);
+
+ TraceValueChangedEventListener listener = new TraceValueChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ int expectedEventCount = 1;
+
+ // Action
+ traces.clear();
+ // Modify ele
+ Property p1 = modelsFactory.newProperty(c1, "p1");
+
+ // Assert
+ // Assert
+ assertTrue("event recorded", traces.contains("valueChanged"));
+ assertEquals("one event recorded", expectedEventCount, traces.traces.size() );
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.ValueChangedEventNotifier#fireDiagramViewRemovedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testPropertyNameChanged() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+ Property p1 = modelsFactory.newProperty(c1, "p1");
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(diagram1, ValueChangedEventNotifier.class);
+
+ TraceValueChangedEventListener listener = new TraceValueChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ int expectedEventCount = 1;
+
+ // Action
+ traces.clear();
+ // Modify ele
+ p1.setName("NewName");
+
+ // Assert
+ assertTrue("event recorded", traces.contains("valueChanged"));
+ assertEquals("one event recorded", expectedEventCount, traces.traces.size() );
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.ValueChangedEventNotifier#fireDiagramViewRemovedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testClassAdded() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ ValueChangedEventNotifierFactory notifierFactory = new ValueChangedEventNotifierFactory();
+ ValueChangedEventNotifier eventNotifier = (ValueChangedEventNotifier)notifierFactory.adapt(diagram1, ValueChangedEventNotifier.class);
+
+ TraceValueChangedEventListener listener = new TraceValueChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ int expectedEventCount = 1; // Name is set before attachment ==> no corresponding event.
+
+ // Action
+ traces.clear();
+ Class c2 = modelsFactory.newClass(diagram1, "C2");
+
+ // Assert
+ assertTrue("event recorded", traces.contains("valueChanged"));
+ assertEquals("one event recorded", expectedEventCount, traces.traces.size() );
+
+ }
+
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceDiagramViewChangedEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceDiagramViewChangedEventListener.java
index b88716cb4d3..0170b3c563b 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceDiagramViewChangedEventListener.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceDiagramViewChangedEventListener.java
@@ -52,7 +52,7 @@ public class TraceDiagramViewChangedEventListener implements IDiagramViewEventLi
* @param notification
*/
public void diagramViewMoved(Notification notification) {
- traces.addTrace("diagramViewRemoved", notification);
+ traces.addTrace("diagramViewMoved", notification);
}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceUmlNamedElementChangedEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceUmlNamedElementChangedEventListener.java
new file mode 100644
index 00000000000..c5033527d80
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceUmlNamedElementChangedEventListener.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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 TraceUmlNamedElementChangedEventListener implements IUmlNamedElementChangedEventListener {
+
+ 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 valueChanged(Notification notification) {
+ traces.addTrace("valueChanged", notification);
+
+ }
+
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactoryTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactoryTest.java
new file mode 100644
index 00000000000..9f8b9f3e769
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierFactoryTest.java
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ * 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.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory;
+import org.eclipse.uml2.uml.Class;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class UmlNamedElementChangedEventNotifierFactoryTest {
+
+ /**
+ * @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 testUmlNamedElementChangedEventNotifierFactory() {
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ // Action
+ UmlNamedElementChangedEventNotifier eventNotifier = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ // Assert
+ assertNotNull("object created", eventNotifier);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#AdapterFactoryImpl()}.
+ */
+ @Test
+ public void testReturnSameInstanceImpl() {
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+ Class c2 = modelsFactory.newClass(diagram1, "C2");
+
+ // Action
+ UmlNamedElementChangedEventNotifier eventNotifier11 = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+ UmlNamedElementChangedEventNotifier eventNotifier12 = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ UmlNamedElementChangedEventNotifier eventNotifier21 = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c2, UmlNamedElementChangedEventNotifier.class);
+ UmlNamedElementChangedEventNotifier eventNotifier22 = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c2, UmlNamedElementChangedEventNotifier.class);
+
+ // Assert
+ assertNotNull("object created", eventNotifier11);
+ assertNotNull("object created", eventNotifier21);
+
+ assertNotEquals("instance are different between diagram", 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/UmlNamedElementChangedEventNotifierTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierTest.java
new file mode 100644
index 00000000000..f22d8d76947
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/UmlNamedElementChangedEventNotifierTest.java
@@ -0,0 +1,201 @@
+/*****************************************************************************
+ * 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.emf.common.notify.Notification;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory;
+import org.eclipse.papyrus.layers.stackmodel.util.TriggeredEventTraces;
+import org.eclipse.papyrus.layers.stackmodel.util.TriggeredEventTraces.TriggeredEvent;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Property;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class UmlNamedElementChangedEventNotifierTest {
+
+ /**
+ * @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.stackmodel.notifier.UmlNamedElementChangedEventNotifier#UmlNamedElementChangedEventNotifier()}.
+ */
+ @Test
+ public void testUmlNamedElementChangedEventNotifier() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ UmlNamedElementChangedEventNotifier eventNotifier = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ // Assert
+ assertNotNull("notifier created", eventNotifier);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.UmlNamedElementChangedEventNotifier#addEventListener(org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener)}.
+ */
+ @Test
+ public void testAddEventListener() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ UmlNamedElementChangedEventNotifier eventNotifier = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ TraceUmlNamedElementChangedEventListener listener = new TraceUmlNamedElementChangedEventListener();
+ eventNotifier.addEventListener(listener);
+
+ // Assert
+ assertTrue("listener added", eventNotifier.listeners.contains(listener));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.UmlNamedElementChangedEventNotifier#removeEventListener(org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener)}.
+ */
+ @Test
+ public void testRemoveEventListener() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ UmlNamedElementChangedEventNotifier eventNotifier = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ TraceUmlNamedElementChangedEventListener listener = new TraceUmlNamedElementChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ eventNotifier.removeEventListener(listener);
+
+ // Assert
+ assertFalse("listener removed", eventNotifier.listeners.contains(listener));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.UmlNamedElementChangedEventNotifier#fireDiagramViewAddedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testNameChangedEvent() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ UmlNamedElementChangedEventNotifier eventNotifier = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ TraceUmlNamedElementChangedEventListener listener = new TraceUmlNamedElementChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+
+ // Action
+ traces.clear();
+ // Modify ele
+ c1.setName("newName");
+
+ // Assert
+ // Assert
+ assertTrue("event recorded", traces.contains("valueChanged"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+
+ TriggeredEventTraces<Notification>.TriggeredEvent event = traces.traces.get(0);
+
+ assertEquals("right element in event", c1, event.notifier.getNotifier() );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.UmlNamedElementChangedEventNotifier#fireDiagramViewRemovedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testPropertyAdded() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ UmlNamedElementChangedEventNotifier eventNotifier = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ TraceUmlNamedElementChangedEventListener listener = new TraceUmlNamedElementChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ int expectedEventCount = 2;
+
+ // Action
+ traces.clear();
+ // Modify ele
+ Property p1 = modelsFactory.newProperty(c1, "p1");
+
+ // Assert
+ // Assert
+ assertTrue("event recorded", traces.contains("valueChanged"));
+ assertEquals("one event recorded", expectedEventCount, traces.traces.size() );
+
+// TriggeredEventTraces<Notification>.TriggeredEvent event = traces.traces.get(0);
+// assertEquals("right element in event", c1, event.notifier.getNotifier() );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.UmlNamedElementChangedEventNotifier#fireDiagramViewRemovedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testPropertyNameChanged() {
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+ Property p1 = modelsFactory.newProperty(c1, "p1");
+
+ UmlNamedElementChangedEventNotifierFactory notifierFactory = new UmlNamedElementChangedEventNotifierFactory();
+ UmlNamedElementChangedEventNotifier eventNotifier = (UmlNamedElementChangedEventNotifier)notifierFactory.adapt(c1, UmlNamedElementChangedEventNotifier.class);
+
+ TraceUmlNamedElementChangedEventListener listener = new TraceUmlNamedElementChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+ int expectedEventCount = 1;
+
+ // Action
+ traces.clear();
+ // Modify ele
+ p1.setName("NewName");
+
+ // Assert
+ // Assert
+ assertTrue("event recorded", traces.contains("valueChanged"));
+ assertEquals("one event recorded", expectedEventCount, traces.traces.size() );
+
+// TriggeredEventTraces<Notification>.TriggeredEvent event = traces.traces.get(0);
+// assertEquals("right element in event", c1, event.notifier.getNotifier() );
+ }
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactory.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactory.java
index 7d38d80541e..3941d01dc5c 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactory.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactory.java
@@ -21,6 +21,7 @@ import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.UMLFactory;
/**
@@ -76,6 +77,26 @@ public class NotationAndUmlModelsFactory {
}
/**
+ *
+ * @param name
+ * @return
+ */
+ public Property newProperty( String name) {
+ Property c = UMLFactory.eINSTANCE.createProperty();
+ c.setName(name);
+ return c;
+ }
+
+ /**
+ *
+ * @param name
+ * @return
+ */
+ public Property newProperty( Class c, String name) {
+ return c.createOwnedAttribute(name, null);
+ }
+
+ /**
* Lookup the View owning the specified {@link NamedElement}.
* return null if not found.
*
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactoryTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactoryTest.java
index 579b0b1764f..98b29284e19 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactoryTest.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactoryTest.java
@@ -22,6 +22,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Property;
/**
*
@@ -117,4 +118,20 @@ public class NotationAndUmlModelsFactoryTest {
}
+ /**
+ * Test
+ */
+ @Test
+ public void testNewProperty() {
+ NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
+
+ Diagram diagram1 =factory.newDiagram();
+ Class c1 = factory.newClass(diagram1, "C1");
+ Property p1 = factory.newProperty(c1, "p1");
+
+ assertNotNull("property created", p1);
+
+ }
+
+
}

Back to the top