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();
}
}
});