plugins/org.wso2.developerstudio.eclipse.distribution.project/src/org/wso2/developerstudio/eclipse/distribution/project/ui/wizard/ProjectsImportPage.java
/**
	 * Create the project described in record. If it is successful return true.
	 * 
	 * @param record
	 * @return boolean <code>true</code> if successful
	 * @throws InterruptedException
	 */
Create the project described in record. If it is successful return true.

@param record
@return boolean true if successful
@throws InterruptedException
Create the project described in record . If it is successful return true . @param record @return boolean true if successful @throws InterruptedException
private boolean createExistingProject(final ProjectRecord record, IProgressMonitor monitor)
			throws InvocationTargetException, InterruptedException {
		String projectName = record.getProjectName();
		final IWorkspace workspace = ResourcesPlugin.getWorkspace();
		final IProject project = workspace.getRoot().getProject(projectName);
		createdProjects.add(project);
		if (record.description == null) {
			record.description = workspace.newProjectDescription(projectName);
			IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
			if (Platform.getLocation().isPrefixOf(locationPath)) {
				record.description.setLocation(null);
			} else {
				record.description.setLocation(locationPath);
			}
		} else {
			record.description.setName(projectName);
		}
		if (record.projectArchiveFile != null) {
			List fileSystemObjects = structureProvider.getChildren(record.parent);
			structureProvider.setStrip(record.level);
			ImportOperation operation = new ImportOperation(project.getFullPath(), structureProvider.getRoot(),
					structureProvider, this, fileSystemObjects);
			operation.setContext(getShell());
			operation.run(monitor);
			return true;
		}
		File importSource = null;
		if (copyFiles) {
			URI locationURI = record.description.getLocationURI();
			if (locationURI != null) {
				importSource = new File(locationURI);
				IProjectDescription desc = workspace.newProjectDescription(projectName);
				desc.setBuildSpec(record.description.getBuildSpec());
				desc.setComment(record.description.getComment());
				desc.setDynamicReferences(record.description.getDynamicReferences());
				desc.setNatureIds(record.description.getNatureIds());
				desc.setReferencedProjects(record.description.getReferencedProjects());
				record.description = desc;
			}
		}
		try {
			monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_CreateProjectsTask, 100);
			project.create(record.description, new SubProgressMonitor(monitor, 30));
			project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 70));
			project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
		} catch (CoreException e) {
			throw new InvocationTargetException(e);
		} finally {
			monitor.done();
		}
		try {
			if (copyFiles && importSource != null && !project.hasNature(MAVEN_MULTI_MODULE_NATURE)) {
				List filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(importSource);
				ImportOperation operation = new ImportOperation(project.getFullPath(), importSource,
						FileSystemStructureProvider.INSTANCE, this, filesToImport);
				operation.setContext(getShell());
				operation.setOverwriteResources(true);
				operation.setCreateContainerStructure(false);
				operation.run(monitor);
			} else if (copyFiles && importSource != null && project.hasNature(MAVEN_MULTI_MODULE_NATURE)) {
				List filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(importSource);
				for (Object resource : filesToImport) {
					File resourceFile = (File) resource;
					if (resourceFile.isDirectory()) {
						IProjectDescription newProjectDescription = project.getWorkspace()
								.newProjectDescription(resourceFile.getName());
						String subProject = project.getLocation().toOSString() + File.separator
								+ resourceFile.getName();
						URI subProjectURI = new URI(subProject);
						newProjectDescription.setLocationURI(subProjectURI);
						File[] subProjectList = resourceFile.listFiles();
						for (File file : subProjectList) {
							if (file.getName().equals(".project")) {
								String[] natureIds = { readProjectNatureFromProjectFile(file) };
								newProjectDescription.setNatureIds(natureIds);
								break;
							}
						}
						IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
						IProject subIProject = root.getProject(resourceFile.getName());
						subIProject.create(newProjectDescription, new NullProgressMonitor());
						subIProject.open(new NullProgressMonitor());
						List subImportFiles = FileSystemStructureProvider.INSTANCE.getChildren(resourceFile);
						ImportOperation operation = new ImportOperation(subIProject.getFullPath(), resourceFile,
								FileSystemStructureProvider.INSTANCE, this, subImportFiles);
						operation.setContext(getShell());
						operation.setOverwriteResources(true);
						operation.setCreateContainerStructure(false);
						operation.run(monitor);
					} else {
						Files.copy(resourceFile.toPath(),
								(new File(project.getLocation().toOSString() + File.separator + resourceFile.getName()))
										.toPath(),
								StandardCopyOption.REPLACE_EXISTING);
					}
				}
			}
		} catch (URISyntaxException e) {
			log.error("URISyntaxException exception while importing", e);
		} catch (CoreException e) {
			log.error("CoreException exception while importing", e);
		} catch (IOException e) {
			log.error("IOException exception while importing", e);
		}
		return true;
	}
private boolean createExistingProject ( final ProjectRecord record , IProgressMonitor monitor ) throws InvocationTargetException , InterruptedException { String projectName = record . getProjectName ( ) ; final IWorkspace workspace = ResourcesPlugin . getWorkspace ( ) ; final IProject project = workspace . getRoot ( ) . getProject ( projectName ) ; createdProjects . add ( project ) ; if ( record . description == null ) { record . description = workspace . newProjectDescription ( projectName ) ; IPath locationPath = new Path ( record . projectSystemFile . getAbsolutePath ( ) ) ; if ( Platform . getLocation ( ) . isPrefixOf ( locationPath ) ) { record . description . setLocation ( null ) ; } else { record . description . setLocation ( locationPath ) ; } } else { record . description . setName ( projectName ) ; } if ( record . projectArchiveFile != null ) { List fileSystemObjects = structureProvider . getChildren ( record . parent ) ; structureProvider . setStrip ( record . level ) ; ImportOperation operation = new ImportOperation ( project . getFullPath ( ) , structureProvider . getRoot ( ) , structureProvider , this , fileSystemObjects ) ; operation . setContext ( getShell ( ) ) ; operation . run ( monitor ) ; return true ; } File importSource = null ; if ( copyFiles ) { URI locationURI = record . description . getLocationURI ( ) ; if ( locationURI != null ) { importSource = new File ( locationURI ) ; IProjectDescription desc = workspace . newProjectDescription ( projectName ) ; desc . setBuildSpec ( record . description . getBuildSpec ( ) ) ; desc . setComment ( record . description . getComment ( ) ) ; desc . setDynamicReferences ( record . description . getDynamicReferences ( ) ) ; desc . setNatureIds ( record . description . getNatureIds ( ) ) ; desc . setReferencedProjects ( record . description . getReferencedProjects ( ) ) ; record . description = desc ; } } try { monitor . beginTask ( DataTransferMessages . WizardProjectsImportPage_CreateProjectsTask , 100 ) ; project . create ( record . description , new SubProgressMonitor ( monitor , 30 ) ) ; project . open ( IResource . BACKGROUND_REFRESH , new SubProgressMonitor ( monitor , 70 ) ) ; project . refreshLocal ( IResource . DEPTH_INFINITE , monitor ) ; } catch ( CoreException e ) { throw new InvocationTargetException ( e ) ; } finally { monitor . done ( ) ; } try { if ( copyFiles && importSource != null && ! project . hasNature ( MAVEN_MULTI_MODULE_NATURE ) ) { List filesToImport = FileSystemStructureProvider . INSTANCE . getChildren ( importSource ) ; ImportOperation operation = new ImportOperation ( project . getFullPath ( ) , importSource , FileSystemStructureProvider . INSTANCE , this , filesToImport ) ; operation . setContext ( getShell ( ) ) ; operation . setOverwriteResources ( true ) ; operation . setCreateContainerStructure ( false ) ; operation . run ( monitor ) ; } else if ( copyFiles && importSource != null && project . hasNature ( MAVEN_MULTI_MODULE_NATURE ) ) { List filesToImport = FileSystemStructureProvider . INSTANCE . getChildren ( importSource ) ; for ( Object resource : filesToImport ) { File resourceFile = ( File ) resource ; if ( resourceFile . isDirectory ( ) ) { IProjectDescription newProjectDescription = project . getWorkspace ( ) . newProjectDescription ( resourceFile . getName ( ) ) ; String subProject = project . getLocation ( ) . toOSString ( ) + File . separator + resourceFile . getName ( ) ; URI subProjectURI = new URI ( subProject ) ; newProjectDescription . setLocationURI ( subProjectURI ) ; File [ ] subProjectList = resourceFile . listFiles ( ) ; for ( File file : subProjectList ) { if ( file . getName ( ) . equals ( ".project" ) ) { String [ ] natureIds = { readProjectNatureFromProjectFile ( file ) } ; newProjectDescription . setNatureIds ( natureIds ) ; break ; } } IWorkspaceRoot root = ResourcesPlugin . getWorkspace ( ) . getRoot ( ) ; IProject subIProject = root . getProject ( resourceFile . getName ( ) ) ; subIProject . create ( newProjectDescription , new NullProgressMonitor ( ) ) ; subIProject . open ( new NullProgressMonitor ( ) ) ; List subImportFiles = FileSystemStructureProvider . INSTANCE . getChildren ( resourceFile ) ; ImportOperation operation = new ImportOperation ( subIProject . getFullPath ( ) , resourceFile , FileSystemStructureProvider . INSTANCE , this , subImportFiles ) ; operation . setContext ( getShell ( ) ) ; operation . setOverwriteResources ( true ) ; operation . setCreateContainerStructure ( false ) ; operation . run ( monitor ) ; } else { Files . copy ( resourceFile . toPath ( ) , ( new File ( project . getLocation ( ) . toOSString ( ) + File . separator + resourceFile . getName ( ) ) ) . toPath ( ) , StandardCopyOption . REPLACE_EXISTING ) ; } } } } catch ( URISyntaxException e ) { log . error ( "URISyntaxException exception while importing" , e ) ; } catch ( CoreException e ) { log . error ( "CoreException exception while importing" , e ) ; } catch ( IOException e ) { log . error ( "IOException exception while importing" , e ) ; } return true ; }
Create the project described in record.
Create the project described in record .
// error case // If it is under the root use the default location // import from archive // import from file system // import project from location copying files - use default project // location for this workspace // if location is null, project already exists in this location or // some error condition occured. // import operation to import project files if copy checkbox is selected