LayerImpl layer = MapTests.createLayer(null, new RendererCreatorTestObjForMulitRenderer(), null);
Map map=layer.getMapInternal();
ContextModelListener listener = new ContextModelListener();
layer.getContextModel().eAdapters().add(listener);
RendererCreatorImpl creator = MapTests.createRendererCreator(layer.getMapInternal());
// Listener added after first layer was added so make notification by hand
NotificationImpl notificationImpl = new ENotificationImpl((InternalEObject) layer.getContextModel(), Notification.ADD,
ProjectPackage.CONTEXT_MODEL__LAYERS, null, layer);
creator.changed(notificationImpl);
RenderContext context = creator.getConfiguration().iterator().next();
assertEquals(1, creator.getLayers().size());
Renderer renderer = creator.getRenderer(context);
assertSame( context, renderer.getContext() );
assertTrue("Expected MultiLayerRenderer but was "+renderer, renderer instanceof MultiLayerRenderer); //$NON-NLS-1$
assertEquals(1, creator.getConfiguration().size());
layer=MapTests.createLayer(new URL( "http://multi_dummy"), new RendererCreatorTestObjForMulitRenderer(), layer.getMapInternal()); //$NON-NLS-1$
creator.changed(listener.lastNotification);
assertEquals(2, creator.getLayers().size());
assertEquals(1, creator.getConfiguration().size());
context=creator.getConfiguration().iterator().next();
renderer = creator.getRenderer(context);
assertSame( context, renderer.getContext() );
CompositeRenderContext compositeRenderContext = ((CompositeRenderContext)creator.getConfiguration().iterator().next());
assertEquals(2, compositeRenderContext.getContexts().size());
assertTrue("Expected MultiRenderer but was "+renderer, renderer instanceof MultiLayerRenderer); //$NON-NLS-1$
layer=MapTests.createLayer(new URL( "http://othername"), new RendererCreatorTestObjForMulitRenderer(), layer.getMapInternal()); //$NON-NLS-1$
creator.changed(listener.lastNotification);
assertEquals(3, creator.getLayers().size());
assertEquals(2, creator.getConfiguration().size());
for( RenderContext context2 : creator.getConfiguration() ) {
renderer = creator.getRenderer(context2);
assertTrue("Expected SingleRenderer but was "+renderer, renderer instanceof MultiLayerRenderer); //$NON-NLS-1$
}
map.lowerLayer(layer);
int indexOfOtherName=map.getMapLayers().indexOf(layer);
creator.changed(listener.lastNotification);
assertEquals(3, creator.getLayers().size());
assertEquals(3, creator.getConfiguration().size());
for( RenderContext context2 : creator.getConfiguration() ) {
renderer = creator.getRenderer(context2);
assertTrue("Expected SingleRenderer but was "+renderer, renderer instanceof MultiLayerRenderer); //$NON-NLS-1$
}
layer=MapTests.createLayer(new URL( "http://dummy"), new RendererCreatorTestObjForMulitRenderer(), null); //$NON-NLS-1$
map.getLayersInternal().set(indexOfOtherName, layer);
creator.changed(listener.lastNotification);
assertEquals(3, creator.getLayers().size());
assertEquals(1, creator.getConfiguration().size());
renderer = creator.getRenderer(creator.getConfiguration().iterator().next());
compositeRenderContext = ((CompositeRenderContext)creator.getConfiguration().iterator().next());
assertEquals(3, compositeRenderContext.getContexts().size());
map.getLayersInternal().remove(0);
creator.changed(listener.lastNotification);
assertEquals(2, creator.getLayers().size());
assertEquals(1, creator.getConfiguration().size());
renderer = creator.getRenderer(creator.getConfiguration().iterator().next());
compositeRenderContext = ((CompositeRenderContext)creator.getConfiguration().iterator().next());
assertEquals(2, compositeRenderContext.getContexts().size());
}