Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2013-12-15 23:30:32 +0000
committerCedric Dumoulin2014-01-27 13:57:00 +0000
commitf5ad47b005bdfe19ec3b801c1175093f8afc8ac8 (patch)
tree5e5c573511ce2f41063796de3ca4a83f888d6bc2 /extraplugins/layers
parentd3d76e9101dddbc2a35bbcfb876f80b537c58b75 (diff)
downloadorg.eclipse.papyrus-f5ad47b005bdfe19ec3b801c1175093f8afc8ac8.tar.gz
org.eclipse.papyrus-f5ad47b005bdfe19ec3b801c1175093f8afc8ac8.tar.xz
org.eclipse.papyrus-f5ad47b005bdfe19ec3b801c1175093f8afc8ac8.zip
Bug 330199 - Add DiagramView event notifier.
Diffstat (limited to 'extraplugins/layers')
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.runtime/META-INF/MANIFEST.MF3
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifier.java199
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactory.java68
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewEventNotifier.java2
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IDiagramViewEventListener.java1
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactoryTest.java93
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierTest.java146
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceDiagramViewChangedEventListener.java59
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactory.java114
-rw-r--r--extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactoryTest.java120
10 files changed, 802 insertions, 3 deletions
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/META-INF/MANIFEST.MF b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/META-INF/MANIFEST.MF
index 7f33d0167a5..279aeeab522 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/META-INF/MANIFEST.MF
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.junit,
org.eclipse.papyrus.infra.core,
org.eclipse.core.resources;bundle-version="3.8.100",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.0"
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.0",
+ org.eclipse.uml2.uml;bundle-version="4.1.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.papyrus.layers.runtime,
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifier.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifier.java
new file mode 100644
index 00000000000..2cce3ba7105
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifier.java
@@ -0,0 +1,199 @@
+/*******************************************************************************
+ * 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.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
+import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
+
+
+/**
+ * An EMF {@link Adapter} listening on notation::diagram::view added and removed.
+ *
+ * This class listen to a {@link Diagram} and send following events to listeners:
+ * <ul>
+ * <li>view removed</li>
+ * <li>view added</li>
+ * </ul>
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class DiagramViewChangedEventNotifier extends EContentAdapter {
+
+ boolean isDisposed = false;
+
+ /**
+ * List of listener to notify.
+ */
+ protected List<IDiagramViewEventListener> listeners = new ArrayList<IDiagramViewEventListener>();
+
+ /**
+ * 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);
+
+ // We are only interested in views (from newValue if set, or oldValue if removed)
+ Object newValue = notification.getNewValue();
+ if( ! (newValue instanceof View || notification.getOldValue() instanceof View ) ) {
+ return;
+ }
+ // Check diagram modification
+ // There is 4 sources: View::persistedChildren and View::transientChildren
+ // Diagram::persistedChildren and Diagram::transientChildren
+ 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:
+
+ break;
+ case Notification.ADD:
+ // A view is added
+ fireDiagramViewAddedEvent(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 == DiagramViewChangedEventNotifier.class;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param layersModel
+ */
+ public DiagramViewChangedEventNotifier() {
+ }
+
+ /**
+ * 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(IDiagramViewEventListener 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(IDiagramViewEventListener listener) {
+
+ listeners.remove(listener);
+ }
+
+ /**
+ * Called by events when a {@link LayersStack} is added to the {@link LayersStackApplication}
+ * @param msg
+ */
+ protected void fireDiagramViewAddedEvent(Notification msg) {
+ for(IDiagramViewEventListener listener : listeners) {
+ listener.diagramViewAdded(msg);
+ }
+ }
+
+ /**
+ * Called by events when a {@link LayersStack} is added to the {@link LayersStackApplication}
+ * @param msg
+ */
+ protected void fireDiagramViewRemovedEvent(Notification msg) {
+ for(IDiagramViewEventListener listener : listeners) {
+ listener.diagramViewRemoved(msg);
+ }
+ }
+
+ /**
+ * Get the removed diagram in case of diagramRemoved event
+ * @param msg
+ * @return
+ */
+ public static View viewAddedEvent_getAddedView(Notification msg) {
+ return (View)msg.getNewValue();
+ }
+
+ /**
+ * Get the removed diagram in case of diagramRemoved event
+ * @param msg
+ * @return
+ */
+ public static View viewAddedEvent_getRemovedView(Notification msg) {
+ return (View)msg.getOldValue();
+ }
+
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactory.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactory.java
new file mode 100644
index 00000000000..580ce62dcec
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactory.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 DiagramViewChangedEventNotifier}.
+ * The factory ensures that there is only one Notifier for a given {@link LayersStack}.
+ * @author cedric dumoulin
+ *
+ */
+public class DiagramViewChangedEventNotifierFactory extends AdapterFactoryImpl {
+
+ /**
+ * Global factory.
+ */
+ static public DiagramViewChangedEventNotifierFactory instance = new DiagramViewChangedEventNotifierFactory();
+
+ /**
+ * Convenience method.
+ * @param target
+ * @return
+ */
+ public DiagramViewChangedEventNotifier adapt(Notifier target) {
+ return (DiagramViewChangedEventNotifier)adapt(target, DiagramViewChangedEventNotifier.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 DiagramViewChangedEventNotifier();
+ }
+
+ /**
+ * This Factory is for {@link DiagramViewChangedEventNotifier}.
+ *
+ * @see org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#isFactoryForType(java.lang.Object)
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public boolean isFactoryForType(Object type) {
+ return type == DiagramViewChangedEventNotifier.class;
+ }
+}
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewEventNotifier.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewEventNotifier.java
index 175d49253e2..dfda9457d3e 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewEventNotifier.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewEventNotifier.java
@@ -31,7 +31,7 @@ import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
* </ul>
*
* @author cedric dumoulin
- *
+ * @deprecated use {@link DiagramViewChangedEventNotifier} instead.
*/
public class DiagramViewEventNotifier {
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IDiagramViewEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IDiagramViewEventListener.java
index 3406225a008..2e0c8a68a94 100644
--- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IDiagramViewEventListener.java
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/notifier/IDiagramViewEventListener.java
@@ -13,7 +13,6 @@ package org.eclipse.papyrus.layers.stackmodel.notifier;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactoryTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactoryTest.java
new file mode 100644
index 00000000000..ff122ba166d
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierFactoryTest.java
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * 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 static org.junit.Assert.fail;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author dumoulin
+ *
+ */
+public class DiagramViewChangedEventNotifierFactoryTest {
+
+ /**
+ * @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 testDiagramViewChangedEventNotifierFactory() {
+
+ DiagramViewChangedEventNotifierFactory notifierFactory = new DiagramViewChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+
+ // Action
+ DiagramViewChangedEventNotifier eventNotifier = (DiagramViewChangedEventNotifier)notifierFactory.adapt(diagram1, DiagramViewChangedEventNotifier.class);
+
+ // Assert
+ assertNotNull("object created", eventNotifier);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.emf.common.notify.impl.AdapterFactoryImpl#AdapterFactoryImpl()}.
+ */
+ @Test
+ public void testReturnSameInstanceImpl() {
+
+ DiagramViewChangedEventNotifierFactory notifierFactory = new DiagramViewChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Diagram diagram2 = modelsFactory.newDiagram();
+
+ // Action
+ DiagramViewChangedEventNotifier eventNotifier11 = (DiagramViewChangedEventNotifier)notifierFactory.adapt(diagram1, DiagramViewChangedEventNotifier.class);
+ DiagramViewChangedEventNotifier eventNotifier12 = (DiagramViewChangedEventNotifier)notifierFactory.adapt(diagram1, DiagramViewChangedEventNotifier.class);
+
+ DiagramViewChangedEventNotifier eventNotifier21 = (DiagramViewChangedEventNotifier)notifierFactory.adapt(diagram2, DiagramViewChangedEventNotifier.class);
+ DiagramViewChangedEventNotifier eventNotifier22 = (DiagramViewChangedEventNotifier)notifierFactory.adapt(diagram2, DiagramViewChangedEventNotifier.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/DiagramViewChangedEventNotifierTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierTest.java
new file mode 100644
index 00000000000..597960f81a4
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/DiagramViewChangedEventNotifierTest.java
@@ -0,0 +1,146 @@
+/*****************************************************************************
+ * 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.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class DiagramViewChangedEventNotifierTest {
+
+ /**
+ * @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.DiagramViewChangedEventNotifier#DiagramViewChangedEventNotifier()}.
+ */
+ @Test
+ public void testDiagramViewChangedEventNotifier() {
+ NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
+
+ Diagram diagram1 = factory.newDiagram();
+
+ DiagramViewChangedEventNotifier notifier = new DiagramViewChangedEventNotifier();
+
+ Class c1 = factory.newClass(diagram1, "C1");
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.DiagramViewChangedEventNotifier#addEventListener(org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener)}.
+ */
+ @Test
+ public void testAddEventListener() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.DiagramViewChangedEventNotifier#removeEventListener(org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener)}.
+ */
+ @Test
+ public void testRemoveEventListener() {
+ fail("Not yet implemented");
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.DiagramViewChangedEventNotifier#fireDiagramViewAddedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireDiagramViewAddedEvent() {
+ DiagramViewChangedEventNotifierFactory notifierFactory = new DiagramViewChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+// Shape shape1 = (Shape)modelsFactory.lookupViewFor(diagram1, c1);
+
+ DiagramViewChangedEventNotifier eventNotifier = (DiagramViewChangedEventNotifier)notifierFactory.adapt(diagram1, DiagramViewChangedEventNotifier.class);
+
+ TraceDiagramViewChangedEventListener listener = new TraceDiagramViewChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+
+ // Action
+ traces.clear();
+ // Modify diagram
+ Class c2 = modelsFactory.newClass(diagram1, "C2");
+ Shape shape2 = (Shape)modelsFactory.lookupViewFor(diagram1, c2);
+
+ // Assert
+ assertTrue("event recorded", traces.contains("diagramViewAdded"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+
+ TriggeredEventTraces<Notification>.TriggeredEvent event = traces.traces.get(0);
+
+ assertEquals("right element in event", shape2, event.notifier.getNewValue() );
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.notifier.DiagramViewChangedEventNotifier#fireDiagramViewRemovedEvent(org.eclipse.emf.common.notify.Notification)}.
+ */
+ @Test
+ public void testFireDiagramViewRemovedEvent() {
+ DiagramViewChangedEventNotifierFactory notifierFactory = new DiagramViewChangedEventNotifierFactory();
+ NotationAndUmlModelsFactory modelsFactory = new NotationAndUmlModelsFactory();
+ Diagram diagram1 = modelsFactory.newDiagram();
+ Class c1 = modelsFactory.newClass(diagram1, "C1");
+ Shape shape1 = (Shape)modelsFactory.lookupViewFor(diagram1, c1);
+ Class c2 = modelsFactory.newClass(diagram1, "C2");
+ Shape shape2 = (Shape)modelsFactory.lookupViewFor(diagram1, c2);
+
+ DiagramViewChangedEventNotifier eventNotifier = (DiagramViewChangedEventNotifier)notifierFactory.adapt(diagram1, DiagramViewChangedEventNotifier.class);
+
+ TraceDiagramViewChangedEventListener listener = new TraceDiagramViewChangedEventListener();
+ eventNotifier.addEventListener(listener);
+ TriggeredEventTraces<Notification> traces = listener.traces;
+
+ // Action
+ traces.clear();
+ // Modify diagram
+ View removedShape = modelsFactory.remove(diagram1, c2);
+
+ // Assert
+ assertTrue("event recorded", traces.contains("diagramViewRemoved"));
+ assertEquals("one event recorded", 1, traces.traces.size() );
+
+ TriggeredEventTraces<Notification>.TriggeredEvent event = traces.traces.get(0);
+
+ assertEquals("right element in event", shape2, event.notifier.getOldValue() );
+ }
+
+}
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
new file mode 100644
index 00000000000..b88716cb4d3
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/notifier/TraceDiagramViewChangedEventListener.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * 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 TraceDiagramViewChangedEventListener implements IDiagramViewEventListener {
+
+ 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 diagramViewAdded(Notification notification) {
+ traces.addTrace("diagramViewAdded", notification);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerAdded(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ public void diagramViewRemoved(Notification notification) {
+ traces.addTrace("diagramViewRemoved", notification);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerRemoved(org.eclipse.emf.common.notify.Notification)
+ * This does not exist actually.
+ * @param notification
+ */
+ public void diagramViewMoved(Notification notification) {
+ traces.addTrace("diagramViewRemoved", notification);
+ }
+
+
+}
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
new file mode 100644
index 00000000000..7d38d80541e
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactory.java
@@ -0,0 +1,114 @@
+/*****************************************************************************
+ * 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.util;
+
+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.uml2.uml.Class;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.UMLFactory;
+
+/**
+ * A factory allowing to create Diagram and UML elements for testing purpose.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class NotationAndUmlModelsFactory {
+
+
+ /**
+ * Create a Diagram
+ * @return
+ */
+ public Diagram newDiagram() {
+
+ Diagram diagram = NotationFactory.eINSTANCE.createDiagram();
+ return diagram;
+ }
+
+ /**
+ * Create a {@link Class} in the {@link Diagram}. Also create intermediate elements like
+ * {@link Shape}.
+ *
+ * @param name
+ * @return
+ */
+ public Class newClass( String name) {
+
+ Class c = UMLFactory.eINSTANCE.createClass();
+ c.setName(name);
+ return c;
+ }
+
+ /**
+ * Create a {@link Class} in the {@link Diagram}. Also create intermediate elements like
+ * {@link Shape}.
+ *
+ * @param diagram
+ * @param name
+ * @return
+ */
+ public Class newClass( Diagram diagram, String name) {
+
+ Class c = UMLFactory.eINSTANCE.createClass();
+ c.setName(name);
+
+ Shape shape = (Shape)diagram.createChild(NotationPackage.eINSTANCE.getShape());
+ shape.setElement(c);
+
+ return c;
+ }
+
+ /**
+ * Lookup the View owning the specified {@link NamedElement}.
+ * return null if not found.
+ *
+ * @param diagram1
+ * @param element
+ * @return
+ */
+ public View lookupViewFor(Diagram diagram1, NamedElement element) {
+
+
+ for( Object o : diagram1.getChildren()) {
+ View view = (View)o;
+ if( view.getElement() == element) {
+ return view;
+ }
+ }
+ // not found
+ return null;
+ }
+
+ /**
+ * Remove the specified element and its associated View.
+ * @param element element to remove.
+ * @return The associated view.
+ */
+ public View remove(Diagram diagram, NamedElement element) {
+ View view = lookupViewFor(diagram, element);
+ if( view == null) {
+ return null;
+ }
+
+ diagram.removeChild(view);
+ return view;
+ }
+
+}
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
new file mode 100644
index 00000000000..579b0b1764f
--- /dev/null
+++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/util/NotationAndUmlModelsFactoryTest.java
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ * 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.util;
+
+import static org.junit.Assert.*;
+
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.eclipse.uml2.uml.Class;
+
+/**
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class NotationAndUmlModelsFactoryTest {
+
+ /**
+ * @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.util.NotationAndUmlModelsFactory#newDiagram()}.
+ */
+ @Test
+ public void testNotationAndUmlModelsTestUtils() {
+ NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
+
+ assertNotNull("object created", factory);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory#newDiagram()}.
+ */
+ @Test
+ public void testNewDiagram() {
+ NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
+
+ Diagram diagram1 =factory.newDiagram();
+
+ assertNotNull("diagram1 created", diagram1);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory#newClass(org.eclipse.gmf.runtime.notation.Diagram, java.lang.String)}.
+ */
+ @Test
+ public void testNewClass() {
+ NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
+
+ // Action
+ Diagram diagram1 =factory.newDiagram();
+ Class c1 = factory.newClass(diagram1, "C1");
+ Class c2 = factory.newClass(diagram1, "C2");
+
+ // Lookup Shape
+ View shape1 = factory.lookupViewFor(diagram1, c1);
+ View shape2 = factory.lookupViewFor(diagram1, c2);
+
+ // Assert
+ assertNotNull("class created", c1);
+ assertNotNull("shape created", shape2);
+ assertNotNull("shape created", shape1);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory#remove(org.eclipse.gmf.runtime.notation.Diagram, java.lang.String)}.
+ */
+ @Test
+ public void testRemove() {
+ NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
+
+ Diagram diagram1 =factory.newDiagram();
+ Class c1 = factory.newClass(diagram1, "C1");
+ Class c2 = factory.newClass(diagram1, "C2");
+
+ // Lookup Shape
+ View shape1 = factory.lookupViewFor(diagram1, c1);
+ View shape2 = factory.lookupViewFor(diagram1, c2);
+
+ // Action
+ View removedShape = factory.remove(diagram1, c1);
+ View lookupResult = factory.lookupViewFor(diagram1, c1);
+
+ // Assert
+ assertNotNull("object removed found", removedShape);
+ assertSame("Right object removed", shape1, removedShape);
+
+ assertNull("lookupResult null after remove", lookupResult);
+
+ }
+
+}

Back to the top