Package org.locationtech.udig.project.internal

Examples of org.locationtech.udig.project.internal.ProjectRegistry


        setMessage(null);
        setErrorMessage(null);
    }

    private void createProjectEditor( Composite parent ) {
        ProjectRegistry registery = ProjectPlugin.getPlugin().getProjectRegistry();
        List<Project> list = registery.getProjects();
        String[][] projects = new String[ list.size()][];
        int index = 0;
        for( Project project : list ){
            projects[index]=new String[]{ project.getName(), project.getID().toString()};
            index++;
        }
        if( getDialogSettings() != null){
            if( registery.getCurrentProject() != null ){
                URI uri = registery.getCurrentProject().getID();
                if( uri != null ){
                    String selected = uri.toFileString();
                    this.getDialogSettings().put("projectSelect", selected );
                }                       
            }
View Full Code Here


        }
        setPageComplete(true);
        setMessage(Messages.ExportSelectionPage_ExportProject, INFORMATION );
    }
    public void selectProject( String uri ){
        ProjectRegistry registery = ProjectPlugin.getPlugin().getProjectRegistry();
        List<Project> list = registery.getProjects();
        for( Project project : list ){
           if( uri.equals( project.getID().toString() ) ){
               selectedProject = project;
               return;
           }
View Full Code Here

                return findProject(uri);
            }

            URI projectURI = URI.createURI(uri.toString());

            final ProjectRegistry registry = getProjectRegistry();
            Resource registryResource = registry.eResource();
            if (registryResource == null) {
                System.out.println("Registery was unable to load"); //$NON-NLS-1$
                throw new Error(Messages.ProjectRegistryImpl_load_error);
            }

            URI registryURI = registryResource.getURI();
            projectURI.deresolve(registryURI, true, true, true);

            ResourceSet registeryResourceSet = registryResource.getResourceSet();
            Resource projectResource = registeryResourceSet.createResource(projectURI);
            try {
                projectResource.load(null);
            } catch (IOException e1) {
                // resource doesn't exist. That is ok.
            }

            Project incomingProject = null;
            if (projectResource.getContents().isEmpty()) {
                // new file being created!
                if (projectURI.isFile()) {
                    // check to see if it exists; we don't like empty existing files
                    File file = new File(projectURI.toFileString());
                    if (file.exists()) {
                        if (!file.delete())
                            throw new NullPointerException("Unable to load " + uri
                                    + " file was empty");
                    }
                }
                // creating a new project from the new project wizard
                incomingProject = createProject(uri, projectResource);

            } else {
                // Go through list of resources
                EList<EObject> contents = projectResource.getContents();
                for (EObject eObject : contents) {
                    if (eObject instanceof Project) {
                        incomingProject = (Project) eObject;
                        break;
                    }
                }
                if (incomingProject == null) {
                    // this project was not saved with a project file?
                    // (does it represent an individial map? we are not sure)
                    throw new NullPointerException("Unable to load " + uri
                            + " - does not contain a project");
                }
                //                if (incomingProject == null) {
                //                    incomingProject = createProject(uri, resource);
                //                    List<ProjectElement> eContents = incomingProject.getElementsInternal();
                //                    for( EObject eObject : contents ) {
                //                        if (eObject instanceof MapImpl) {
                //                            MapImpl tmpMap = (MapImpl) eObject;
                //                            eContents.add(tmpMap);
                //                        }
                //                    }
                //                }
            }

            final Project newProject = incomingProject;
            PlatformGIS.syncInDisplayThread(new Runnable() {
                public void run() {
                    try {
                        setCurrentProject(newProject);
                        registry.getProjects().add(newProject);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
View Full Code Here

     *
     * @return the loaded project registry.
     */
    @SuppressWarnings("unchecked")
    private synchronized static ProjectRegistry load() {
        ProjectRegistry projectRegistry = null;
        try {

            IPath registrypath = Platform.getLocation().append(".projectRegistry"); //$NON-NLS-1$
            URI uri = URI.createURI("file://" + registrypath.toOSString()); //$NON-NLS-1$

            projectRegistry = backwardsCompatibility(projectRegistry, registrypath, uri);

            if (projectRegistry == null) {

                // Load the resource through the editing domain.
                resourceSet = new ResourceSetImpl();

                if (registrypath.toFile().exists()) {
                    Resource resource = resourceSet.getResource(uri, true);
                    resourceSet.eSetDeliver(false);
                    projectRegistry = (ProjectRegistry) resource.getContents().get(0);
                    if (projectRegistry == null) {
                        projectRegistry = ProjectFactory.eINSTANCE.createProjectRegistry();
                        resource.getContents().add(projectRegistry);
                    }
                } else {
                    Resource resource = resourceSet.createResource(uri);
                    if (resource == null)
                        throw new Exception("Unable to load or create ProjectRegistry resource"); //$NON-NLS-1$

                    projectRegistry = new ProjectRegistryImpl();
                    resource.getContents().add(projectRegistry);
                }
            }
        } catch (Exception exception) {
            ProjectPlugin.INSTANCE.log(exception);
        }
        if (projectRegistry == null)
            ProjectPlugin.log("Error getting project from resource"); //$NON-NLS-1$
        else {
            final ProjectRegistry registry = projectRegistry;
            projectRegistry.eAdapters().add(new AdapterImpl() {
                /**
                 * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
                 */
                public void notifyChanged(Notification msg) {
                    if (msg.getFeatureID(ProjectRegistry.class) == ProjectPackage.PROJECT_REGISTRY__PROJECTS) {
                        registry.eResource().setModified(true);
                    }
                }
            });
        }
        resourceSet.eSetDeliver(false);
View Full Code Here

            if (result == null)
                result = defaultCase(theEObject);
            return result;
        }
        case ProjectPackage.PROJECT_REGISTRY: {
            ProjectRegistry projectRegistry = (ProjectRegistry) theEObject;
            T result = caseProjectRegistry(projectRegistry);
            if (result == null)
                result = defaultCase(theEObject);
            return result;
        }
View Full Code Here

    project=map.getProjectInternal();
  }
 
  @After
  public void tearDown() throws Exception {
    ProjectRegistry registry = ProjectPlugin.getPlugin().getProjectRegistry();
    Resource registryResource=registry.eResource();
    List<Project> project=new ArrayList<Project>();
    project.addAll(registry.getProjects());
   
    for (Project project2 : project) {
      registry.getProjects().remove(project2);
    }
    if( registryResource == null )
      return;
    Iterator iter=registryResource.getResourceSet().getResources().iterator();
    while ( iter.hasNext() ){
      Resource resource=(Resource) iter.next();
      if( resource==registry.eResource() )
        continue;
      resource.unload();
      File file = new File(resource.getURI().toFileString());
      if( file.exists() )
        file.delete();
View Full Code Here

    while ( iter.hasNext() ){
      ((Resource) iter.next()).save(null);
    }
        //test cancel delete
    deleteAction.runDoDelete(project,false, Window.CANCEL);
    ProjectRegistry registry = ProjectPlugin.getPlugin().getProjectRegistry();
    assertEquals(1, registry.getProjects().size());
    assertTrue( registry.getProjects().contains(project) );
    assertNotNull(project.eResource());
    assertEquals(project, project.getElementsInternal().get(0).getProject());

        Resource resource = project.eResource();
        IProjectElement elem = project.getElements().get(0);
       
        // Test remove project but leave files
    deleteAction.runDoDelete(project,false, Window.OK);
    assertEquals(0, registry.getProjects().size());
    assertTrue( new File(projecturi.toFileString()).exists() );
        assertFalse(resource.isLoaded());
       
    Project project=registry.getProject(projecturi);
    assertEquals(1, project.getElementsInternal().size());
        assertNotSame(elem, project.getElements().get(0));
    assertEquals(project, project.getElementsInternal().get(0).getProject());
       
        // Test delete from file System
        deleteAction.runDoDelete(project,true, Window.OK);
        assertEquals(0, registry.getProjects().size());
        assertFalse( new File(projecturi.toFileString()).exists() );
  }
View Full Code Here

  private IGeoResource resource2;

  @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);
View Full Code Here

TOP

Related Classes of org.locationtech.udig.project.internal.ProjectRegistry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.