diff options
author | Cedric Dumoulin | 2013-12-13 15:16:38 +0000 |
---|---|---|
committer | Cedric Dumoulin | 2014-01-27 13:56:30 +0000 |
commit | 31712ea31aa0de07784270e3b1daf4a0117714a8 (patch) | |
tree | 3142300b855344682a892c6579cf31eacafe5b10 /extraplugins/layers | |
parent | 56782ff678497b9923e6253fbe8fcf76d2fd4c23 (diff) | |
download | org.eclipse.papyrus-31712ea31aa0de07784270e3b1daf4a0117714a8.tar.gz org.eclipse.papyrus-31712ea31aa0de07784270e3b1daf4a0117714a8.tar.xz org.eclipse.papyrus-31712ea31aa0de07784270e3b1daf4a0117714a8.zip |
Allows multi add/remove events from layer model.
Multi add/remove come from addAll() and removeAll() List methods. They
are thrown by the RegExp.
This commit take into account these events.
Diffstat (limited to 'extraplugins/layers')
7 files changed, 358 insertions, 12 deletions
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/ILayersModelEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/ILayersModelEventListener.java index 49fb3772c0a..3abf07c96d5 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/ILayersModelEventListener.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/ILayersModelEventListener.java @@ -51,6 +51,9 @@ public interface ILayersModelEventListener { */ public void viewAddedToLayer( Notification notification ); public void viewRemovedFromLayer( Notification notification ); + public void multiViewsRemovedFromLayer(Notification notification); + public void multiViewsAddedToLayer(Notification notification); + /** * Method called when a view is moved from one layer to another. * The event contains: the layer, the view. diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java index c7750a0e3be..025f3e2a7de 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java @@ -508,7 +508,7 @@ public class LayerStackSynchronizer implements IDiagramViewEventListener, ILayer */ @Override public void viewAddedToLayer(Notification notification) { - System.out.println("viewAddedToLayer" + notification.getNewValue()); + System.out.println(this.getClass().getSimpleName() + " viewAddedToLayer( " + notification.getNewValue() + " )"); // We need to find the view, the layer in which it is added, // and the properties attached to this layer. @@ -548,6 +548,28 @@ public class LayerStackSynchronizer implements IDiagramViewEventListener, ILayer } + @Override + public void multiViewsAddedToLayer(Notification notification) { + System.out.println(this.getClass().getSimpleName() + ".multiViewsAddedToLayer( " + notification.getNewValue() + " )"); + + // We need to find the view, the layer in which it is added, + // and the properties attached to this layer. + // Then, we compute this property and set it to the view. + try { + AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); + List<View> views = LayersModelEventUtils.ViewEvents.getViewsAdded(notification); + + checkApplication(); + List<Property> properties = layer.getAttachedProperties(); + recompute(views, properties); + + } catch (LayersException e) { + e.printStackTrace(); + } + + } + + /** * @@ -557,25 +579,65 @@ public class LayerStackSynchronizer implements IDiagramViewEventListener, ILayer */ @Override public void viewRemovedFromLayer(Notification notification) { - System.out.println(this.getClass().getSimpleName() + " viewRemovedFromLayer(Not Implemented) " + notification.getOldValue()); + System.out.println(this.getClass().getSimpleName() + " viewRemovedFromLayer( " + notification.getOldValue() + " )"); // We need to find the view, the layer in which it is added, // and the properties attached to this layer. // Then, we compute this property and set it to the view. try { AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); -// View view = LayersModelEventUtils.ViewEvents.getViewRemoved(notification); + View view = LayersModelEventUtils.ViewEvents.getViewRemoved(notification); + checkApplication(); + List<Property> properties = layer.getAttachedProperties(); -// List<Property> properties = layer.getAttachedProperties(); + List<ComputePropertyValueCommand> commands = layersStack.getPropertiesComputePropertyValueCommand(view, properties); + if(commands == null) { + // No property to set + return; + } - // Here we need to reset default values to the view - // TODO: reset default values for specified properties. + PropertySetter setter; + // Walk each cmd and set the property + for( int i=0; i<commands.size(); i++) { + try { + Property property = properties.get(i); + setter = application.getPropertySetterRegistry().getPropertySetter(property); + setter.setValue(view, commands.get(i).getCmdValue() ); + } catch (NotFoundException e) { + // No setter found + System.err.println(e.getMessage()); + } catch (NullPointerException e) { + // A command is null + } + } } catch (LayersException e) { // TODO Auto-generated catch block e.printStackTrace(); } } + @Override + public void multiViewsRemovedFromLayer(Notification notification) { + System.out.println(this.getClass().getSimpleName() + " multiViewsRemovedFromLayer( " + notification.getOldValue() + " )"); + + // We need to find the view, the layer in which it is added, + // and the properties attached to this layer. + // Then, we compute this property and set it to the view. + try { + AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); + List<View> views = LayersModelEventUtils.ViewEvents.getViewsRemoved(notification); + + checkApplication(); + List<Property> properties = layer.getAttachedProperties(); + recompute(views, properties); + + } catch (LayersException e) { + e.printStackTrace(); + } + + } + + /** @@ -632,4 +694,6 @@ public class LayerStackSynchronizer implements IDiagramViewEventListener, ILayer + + } diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java index a82cd7bd288..0b28b9659e6 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java @@ -94,6 +94,14 @@ public class LayersModelEventNotifier { fireViewAddedToLayer(notification); break; + case Notification.ADD_MANY: + // A layer is added + // the concerned view +// View view = (View)notification.getNewValue(); +// AbstractLayer layer = (AbstractLayer)notification.getNotifier() + + fireMultiViewsAddedToLayer(notification); + break; case Notification.REMOVE: // A layer is removed // the concerned view @@ -102,6 +110,14 @@ public class LayersModelEventNotifier { fireViewRemovedFromLayer(notification); break; + case Notification.REMOVE_MANY: + // A layer is removed + // the concerned view +// View view = (View)notification.getOldValue(); +// AbstractLayer layer = (AbstractLayer)notification.getNotifier() + + fireMultiViewsRemovedFromLayer(notification); + break; } } @@ -374,6 +390,19 @@ public class LayersModelEventNotifier { } /** + * Method called when a view is added to one layer. + * The event contains: the layer, the view. + * + * @param notification + */ + public void fireMultiViewsAddedToLayer( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.multiViewsAddedToLayer(notification); + } + } + + /** * Method called when a view is removed from one layer. * The event contains: the layer, the view. * @@ -387,6 +416,19 @@ public class LayersModelEventNotifier { } /** + * Method called when a view is removed from one layer. + * The event contains: the layer, the view. + * + * @param notification + */ + public void fireMultiViewsRemovedFromLayer( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.multiViewsRemovedFromLayer(notification); + } + } + + /** * Method called when a view is moved from one layer to another layer. * The event contains: the layer, the view. * diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventUtils.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventUtils.java index 0831d2cddb3..e58b3bfe2ac 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventUtils.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventUtils.java @@ -10,6 +10,8 @@ ******************************************************************************/ package org.eclipse.papyrus.layers.runtime; +import java.util.List; + import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.notation.View; @@ -109,6 +111,20 @@ public class LayersModelEventUtils { static public View getViewRemoved(Notification notification) throws NotFoundException { return (View)notification.getOldValue(); } + + /** + * Get the views[*] that have been removed from the layer. + * + * @param notification + * @return + */ + public static List<View> getViewsRemoved(Notification notification) { + return (List<View>)notification.getOldValue(); + } + + public static List<View> getViewsAdded(Notification notification) { + return (List<View>)notification.getNewValue(); + } } diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerSubclass.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerSubclass.java index ebb7e44d035..3f68b7e1aff 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerSubclass.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerSubclass.java @@ -170,5 +170,15 @@ public class LayerStackSynchronizerSubclass extends LayerStackSynchronizer { super.diagramViewRemoved(msg); } + @Override + public void multiViewsAddedToLayer(Notification notification) { + traces.addTrace( "multiViewsAddedToLayer", notification); + super.multiViewsAddedToLayer(notification); + } + @Override + public void multiViewsRemovedFromLayer(Notification notification) { + traces.addTrace( "multiViewsRemovedFromLayer", notification); + super.multiViewsRemovedFromLayer(notification); + } } diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerWithApplicationTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerWithApplicationTest.java index 5268cd1f8dc..cd1e9519fcb 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerWithApplicationTest.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizerWithApplicationTest.java @@ -10,6 +10,7 @@ ******************************************************************************/ package org.eclipse.papyrus.layers.runtime; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -18,11 +19,13 @@ import static org.junit.Assert.fail; import java.util.Arrays; import java.util.List; +import org.eclipse.emf.common.notify.Notification; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.gmf.runtime.notation.NotationFactory; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.layers.runtime.utils.TriggeredEventTraces; +import org.eclipse.papyrus.layers.runtime.utils.TriggeredEventTraces.TriggeredEvent; import org.eclipse.papyrus.layers.stackmodel.LayersException; import org.eclipse.papyrus.layers.stackmodel.layers.BooleanInstance; import org.eclipse.papyrus.layers.stackmodel.layers.Layer; @@ -384,20 +387,206 @@ public class LayerStackSynchronizerWithApplicationTest { /** * Test method for {@link org.eclipse.papyrus.layers.runtime.LayerStackSynchronizer#viewAddedToLayer(org.eclipse.emf.common.notify.Notification)}. + * @throws LayersException */ @Test - @Ignore - public void testViewAddedToLayer() { - fail("Not yet implemented"); + public void testViewAddedToLayer() throws LayersException { + // Create requested objects + LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication(); + PropertyRegistry propertyRegistry = application.getPropertyRegistry(); + Diagram diagram = NotationFactory.eINSTANCE.createDiagram(); + + // Create stack + LayersStack stack = application.getLayersStackFor(diagram); + + // Create a TopLayer + TopLayerOperator layer = LayersFactory.eINSTANCE.createTopLayerOperator(); + layer.setApplication(application); + stack.setLayers(layer); + + // Create synchronizer + LayerStackSynchronizerSubclass synchronizer = new LayerStackSynchronizerSubclass(stack); + TriggeredEventTraces traces = synchronizer.traces; + + // Create Views + View view1 = NotationFactory.eINSTANCE.createShape(); + View view2 = NotationFactory.eINSTANCE.createShape(); + + // Create Properties + int index = 0; + Property property1 = propertyRegistry.getProperties().get(index++); + + // Create layer1: views ={} propInstances={} + Layer layer1 = createLayer( layer, Arrays.asList(view1), Arrays.asList(property1)); + + // action + traces.clear(); + // remove a view + layer1.getViews().add(view2); + + // assert + assertTrue("event sent", traces.size()>0); + TriggeredEvent event = traces.get(0); + assertSame("event sent", "viewAddedToLayer", event.name); + } + + /** + * Test method for {@link org.eclipse.papyrus.layers.runtime.LayerStackSynchronizer#viewAddedToLayer(org.eclipse.emf.common.notify.Notification)}. + * @throws LayersException + */ + @Test + public void testNViewAddedToLayer() throws LayersException { + // Create requested objects + LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication(); + PropertyRegistry propertyRegistry = application.getPropertyRegistry(); + Diagram diagram = NotationFactory.eINSTANCE.createDiagram(); + + // Create stack + LayersStack stack = application.getLayersStackFor(diagram); + + // Create a TopLayer + TopLayerOperator layer = LayersFactory.eINSTANCE.createTopLayerOperator(); + layer.setApplication(application); + stack.setLayers(layer); + + // Create synchronizer + LayerStackSynchronizerSubclass synchronizer = new LayerStackSynchronizerSubclass(stack); + TriggeredEventTraces traces = synchronizer.traces; + + // Create Views + View view1 = NotationFactory.eINSTANCE.createShape(); + View view2 = NotationFactory.eINSTANCE.createShape(); + View view3 = NotationFactory.eINSTANCE.createShape(); + + List<View> viewsToAttach = Arrays.asList(view1); + List<View> viewsToAdd = Arrays.asList(view2, view3); + + // Create Properties + int index = 0; + Property property1 = propertyRegistry.getProperties().get(index++); + + // Create layer1: views ={} propInstances={} + Layer layer1 = createLayer( layer, viewsToAttach, Arrays.asList(property1)); + + // action + traces.clear(); + // remove a view + layer1.getViews().addAll(viewsToAdd ); + + // assert + assertTrue("event sent", traces.size()>0); + TriggeredEvent event = traces.get(0); + assertSame("event sent", "multiViewsAddedToLayer", event.name); + + // Check the collection + Notification notification = event.notifier; + assertNotNull("notification is set", notification); + + List<View> addedViews = LayersModelEventUtils.ViewEvents.getViewsAdded(notification); + assertEquals( "both removed list have the same size", viewsToAdd.size(), addedViews.size()); + assertTrue( "notification contains removed views", addedViews.containsAll(viewsToAdd)); } /** * Test method for {@link org.eclipse.papyrus.layers.runtime.LayerStackSynchronizer#viewRemovedFromLayer(org.eclipse.emf.common.notify.Notification)}. + * @throws LayersException */ @Test - @Ignore - public void testViewRemovedFromLayer() { - fail("Not yet implemented"); + public void testViewRemovedFromLayer() throws LayersException { + // Create requested objects + LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication(); + PropertyRegistry propertyRegistry = application.getPropertyRegistry(); + Diagram diagram = NotationFactory.eINSTANCE.createDiagram(); + + // Create stack + LayersStack stack = application.getLayersStackFor(diagram); + + // Create a TopLayer + TopLayerOperator layer = LayersFactory.eINSTANCE.createTopLayerOperator(); + layer.setApplication(application); + stack.setLayers(layer); + + // Create synchronizer + LayerStackSynchronizerSubclass synchronizer = new LayerStackSynchronizerSubclass(stack); + TriggeredEventTraces traces = synchronizer.traces; + + // Create Views + View view1 = NotationFactory.eINSTANCE.createShape(); + View view2 = NotationFactory.eINSTANCE.createShape(); + + // Create Properties + int index = 0; + Property property1 = propertyRegistry.getProperties().get(index++); + + // Create layer1: views ={} propInstances={} + Layer layer1 = createLayer( layer, Arrays.asList(view1, view2), Arrays.asList(property1)); + + // action + traces.clear(); + // remove a view + layer1.getViews().remove(view2); + + // assert + assertTrue("event sent", traces.size()>0); + TriggeredEvent event = traces.get(0); + assertSame("event sent", "viewRemovedFromLayer", event.name); + } + + /** + * Test method for {@link org.eclipse.papyrus.layers.runtime.LayerStackSynchronizer#viewRemovedFromLayer(org.eclipse.emf.common.notify.Notification)}. + * @throws LayersException + */ + @Test + public void testNViewRemovedFromLayer() throws LayersException { + // Create requested objects + LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication(); + PropertyRegistry propertyRegistry = application.getPropertyRegistry(); + Diagram diagram = NotationFactory.eINSTANCE.createDiagram(); + + // Create stack + LayersStack stack = application.getLayersStackFor(diagram); + + // Create a TopLayer + TopLayerOperator layer = LayersFactory.eINSTANCE.createTopLayerOperator(); + layer.setApplication(application); + stack.setLayers(layer); + + // Create synchronizer + LayerStackSynchronizerSubclass synchronizer = new LayerStackSynchronizerSubclass(stack); + TriggeredEventTraces traces = synchronizer.traces; + + // Create Views + View view1 = NotationFactory.eINSTANCE.createShape(); + View view2 = NotationFactory.eINSTANCE.createShape(); + View view3 = NotationFactory.eINSTANCE.createShape(); + + List<View> viewsToAttach = Arrays.asList(view1, view2, view3); + List<View> viewsToRemove = Arrays.asList(view2, view3); + + + // Create Properties + int index = 0; + Property property1 = propertyRegistry.getProperties().get(index++); + + // Create layer1: views ={} propInstances={} + Layer layer1 = createLayer( layer, viewsToAttach, Arrays.asList(property1)); + + // action + traces.clear(); + // remove a view + layer1.getViews().removeAll(viewsToRemove); + + // assert + assertTrue("event sent", traces.size()>0); + TriggeredEvent event = traces.get(0); + assertSame("event sent", "multiViewsRemovedFromLayer", event.name); + // Check the collection + Notification notification = event.notifier; + assertNotNull("notification is set", notification); + + List<View> removedViews = LayersModelEventUtils.ViewEvents.getViewsRemoved(notification); + assertEquals( "both removed list have the same size", removedViews.size(), viewsToRemove.size()); + assertTrue( "notification contains removed views", removedViews.containsAll(viewsToRemove)); } /** diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/TraceLayersModelEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/TraceLayersModelEventListener.java index 00a3c9b6e4b..f5d6a2b61c2 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/TraceLayersModelEventListener.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/tests/org/eclipse/papyrus/layers/runtime/TraceLayersModelEventListener.java @@ -128,4 +128,26 @@ public class TraceLayersModelEventListener implements ILayersModelEventListener traces.addTrace("viewMovedBetweenLayer", notification); } + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#multiViewsRemovedFromLayer(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void multiViewsRemovedFromLayer(Notification notification) { + traces.addTrace("multiViewsRemovedFromLayer", notification); + } + + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#multiViewsAddedToLayer(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void multiViewsAddedToLayer(Notification notification) { + traces.addTrace("multiViewsAddedToLayer", notification); + } + } |