예제 #1
0
  public ProjectElementAdapter createProjectElementAdapter(
      IProject project, Class<? extends IGenericProjectElement> typeToCreate, String extensionId) {
    ProjectElementAdapter adapter = createProjectElementAdapter();

    IGenericProjectElement genericProjectElement =
        createGenericProjectElement(typeToCreate, extensionId);
    adapter.setBackingObject(genericProjectElement);

    ((Project) project).getElementsInternal().add(adapter);
    return adapter;
  }
예제 #2
0
  @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);
  }
예제 #3
0
  @Ignore
  @Test
  public void testSaveAndLoad() throws Exception {
    EList list = project.eResource().getResourceSet().getResources();

    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
      Resource element = (Resource) iter.next();
      try {
        element.save(null);
      } catch (Exception e) {
      }
      if (!element.getContents().contains(ProjectPlugin.getPlugin().getProjectRegistry()))
        element.unload();
    }

    ResourceSet set = new ResourceSetImpl();
    Project project =
        (Project)
            set.getResource(URI.createURI("file://" + file.getAbsolutePath()), true)
                .getAllContents()
                .next(); //$NON-NLS-1$
    assertFalse(project.eIsProxy());
    assertNotNull(project);
    int maps = 0;
    boolean foundFirstMap = false;
    boolean foundSecondMap = false;

    List resources = project.getElements();
    for (Iterator iter = resources.iterator(); iter.hasNext(); ) {
      Map map = (Map) iter.next();

      assertFalse(map.eIsProxy());
      assertEquals(1, map.getLayersInternal().size());
      assertNotNull(map.getLayersInternal().get(0).getGeoResources().get(0));
      assertNotNull(
          map.getLayersInternal()
              .get(0)
              .getResource(FeatureSource.class, new NullProgressMonitor()));

      if (map.getName().equals(firstMapName)) {
        foundFirstMap = true;
        assertEquals(firstMapLayerName, map.getLayersInternal().get(0).getName());
        FeatureSource<SimpleFeatureType, SimpleFeature> source =
            map.getLayersInternal().get(0).getResource(FeatureSource.class, null);
        assertEquals(4, source.getCount(Query.ALL));
        assertEquals(firstMapLayerName, map.getLayersInternal().get(0).getName());
      }
      if (map.getName().equals(secondMapName)) {
        foundSecondMap = true;
        assertEquals(secondMapLayerName, map.getLayersInternal().get(0).getName());
        FeatureSource<SimpleFeatureType, SimpleFeature> source =
            map.getLayersInternal().get(0).getResource(FeatureSource.class, null);
        assertEquals(6, source.getCount(Query.ALL));
        assertEquals(secondMapLayerName, map.getLayersInternal().get(0).getName());
      }
      maps++;
    }
    assertEquals(2, maps);
    assertTrue(foundFirstMap);
    assertTrue(foundSecondMap);
  }