Example #1
1
  @Before
  public void baseline() throws Exception {
    map = MapTests.createDefaultMap("FTName", 4, true, new Dimension(500, 500)); // $NON-NLS-1$

    Folder folder = ProjectFactory.eINSTANCE.createFolder();
    folder.setName("Folder");
    folder.setShown(true);
    map.getLegend().add(folder);

    Layer layer = map.getLayersInternal().get(0);
    LayerLegendItem layerItem = ProjectFactory.eINSTANCE.createLayerLegendItem();
    layerItem.setName("Layer 0");
    layerItem.setLayer(layer);
    folder.getItems().add(layerItem);

    layer = ProjectFactory.eINSTANCE.createLayer();
    map.getLayersInternal().add(layer);
    layerItem = ProjectFactory.eINSTANCE.createLayerLegendItem();
    layerItem.setName("Layer 1");
    layerItem.setLayer(layer);
    folder.getItems().add(layerItem);

    layer = ProjectFactory.eINSTANCE.createLayer();
    map.getLayersInternal().add(layer);
    layerItem = ProjectFactory.eINSTANCE.createLayerLegendItem();
    layerItem.setName("Layer 2");
    layerItem.setLayer(layer);
    map.getLegend().add(layerItem);

    layer = ProjectFactory.eINSTANCE.createLayer();
    map.getLayersInternal().add(layer);
    layerItem = ProjectFactory.eINSTANCE.createLayerLegendItem();
    layerItem.setName("Layer 3");
    layerItem.setLayer(layer);
    map.getLegend().add(layerItem);
  }
  @SuppressWarnings("unchecked")
  @Before
  public void setUp() throws Exception {
    ProjectRegistry registry = ProjectPlugin.getPlugin().getProjectRegistry();
    List<Project> projects = registry.getProjects();
    registry.getProjects().removeAll(projects);

    EList list = registry.eResource().getResourceSet().getResources();
    Set<Resource> toRemove = new HashSet<Resource>();
    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
      Resource element = (Resource) iter.next();
      if (element != registry.eResource()) {
        element.unload();
        toRemove.add(element);
      }
    }

    project = registry.getDefaultProject();
    file = new File(project.eResource().getURI().toFileString());
    if (file.exists()) {
      if (file.isFile()) {
        file.delete();
        File parent = file.getParentFile();
        File[] files = parent.listFiles();
        for (File file : files) {
          file.delete();
        }
        parent.delete();
      }
      file.delete();
    }

    registry.eResource().getResourceSet().getResources().removeAll(toRemove);

    project =
        registry.getProject(
            FileLocator.toFileURL(Platform.getInstanceLocation().getURL()).getFile());

    resource1 =
        MapTests.createGeoResource(UDIGTestUtil.createDefaultTestFeatures(type1Name, 4), false);
    Map map = MapTests.createNonDynamicMapAndRenderer(resource1, new Dimension(512, 512));
    map.setName(firstMapName);
    map.getLayersInternal().get(0).setName(firstMapLayerName);

    resource2 =
        MapTests.createGeoResource(UDIGTestUtil.createDefaultTestFeatures(type2Name, 6), false);
    map = MapTests.createNonDynamicMapAndRenderer(resource2, new Dimension(512, 512));
    map.setName(secondMapName);
    map.getLayersInternal().get(0).setName(secondMapLayerName);
  }
  @Ignore
  @Test
  public void testNormalRenderer() throws Exception {
    Map map = ProjectFactory.eINSTANCE.createMap();
    URL url1 =
        FileLocator.toFileURL(
            CatalogTestsUIPlugin.getDefault()
                .getBundle()
                .getEntry("data/streams.shp")); // $NON-NLS-1$
    String fragment1 = url1.getFile();
    fragment1 = fragment1.substring(0, fragment1.lastIndexOf('.'));
    fragment1 =
        "#" + fragment1.substring(fragment1.lastIndexOf("/") + 1); // $NON-NLS-1$ //$NON-NLS-2$
    URL url2 =
        FileLocator.toFileURL(
            CatalogTestsUIPlugin.getDefault()
                .getBundle()
                .getEntry("data/lakes.shp")); // $NON-NLS-1$
    String fragment2 = url2.getFile();
    fragment2 = fragment2.substring(0, fragment2.lastIndexOf('.'));
    fragment2 =
        "#" + fragment2.substring(fragment2.lastIndexOf("/") + 1); // $NON-NLS-1$ //$NON-NLS-2$
    Layer layer =
        MapTests.createLayer(
            map,
            ShpServiceImpl.class,
            url1.toExternalForm(),
            url1.toExternalForm() + fragment1,
            "layer1"); //$NON-NLS-1$
    Layer layer2 =
        MapTests.createLayer(
            map,
            ShpServiceImpl.class,
            url2.toExternalForm(),
            url2.toExternalForm() + fragment2,
            "layer2"); //$NON-NLS-1$

    runVisibilityTest(map, layer, layer2, true);
  }
  @Ignore
  @Test
  public void testMultiLayerRenderer() throws Exception {
    Map map = ProjectFactory.eINSTANCE.createMap();

    Layer layer =
        MapTests.createLayer(
            map,
            MapGraphicService.class,
            "file:/localhost/mapgraphic", //$NON-NLS-1$
            "file:/localhost/mapgraphic#Scalebar", //$NON-NLS-1$
            "layer1"); //$NON-NLS-1$
    Layer layer2 =
        MapTests.createLayer(
            map,
            MapGraphicService.class,
            "file:/localhost/mapgraphic", //$NON-NLS-1$
            "file:/localhost/mapgraphic#Scalebar", //$NON-NLS-1$
            "layer2"); //$NON-NLS-1$

    runVisibilityTest(map, layer, layer2, false);
  }
  @Test
  public void testAddRemoveClear() throws Exception {
    Map map = MapTests.createDefaultMap("typename", 2, true, null); // $NON-NLS-1$
    map.getLayersInternal()
        .add(
            map.getLayerFactory()
                .createLayer(MapTests.createGeoResource("type2", 3, false))); // $NON-NLS-1$

    CompositeRendererImpl renderer =
        (CompositeRendererImpl) map.getRenderManagerInternal().getRenderExecutor().getRenderer();
    renderer.getContext().clear();
    RendererCreator creator = map.getRenderManagerInternal().getRendererCreator();

    SortedSet<Layer> layers = creator.getLayers();
    layers.clear();
    layers.addAll(map.getLayersInternal());
    layers.add(new SelectionLayer(map.getLayersInternal().get(0)));
    layers.add(new SelectionLayer(map.getLayersInternal().get(1)));

    creator.reset();

    CompositeRenderContextImpl comp = new CompositeRenderContextImpl();
    comp.addContexts(creator.getConfiguration());

    Iterator iter = comp.getContexts().iterator();

    RenderContext executor = (RenderContext) iter.next();
    assertEquals(map.getLayersInternal().get(0), executor.getLayer());
    executor = (RenderContext) iter.next();
    assertEquals(map.getLayersInternal().get(1), executor.getLayer());
    executor = (RenderContext) iter.next();
    SelectionLayer sl = (SelectionLayer) executor.getLayer();
    assertEquals(map.getLayersInternal().get(0), sl.getWrappedLayer());
    executor = (RenderContext) iter.next();
    sl = (SelectionLayer) executor.getLayer();
    assertEquals(map.getLayersInternal().get(1), sl.getWrappedLayer());
  }