use of org.eclipse.core.resources.IProjectDescription in project translationstudio8 by heartsome.
the class ImportProjectWizardPage method createExistingProject.
/**
* Create the project described in record. If it is successful return true.
*
* @param record
* @return boolean <code>true</code> 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) {
// error case
record.description = workspace.newProjectDescription(projectName);
IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
// If it is under the root use the default location
if (Platform.getLocation().isPrefixOf(locationPath)) {
record.description.setLocation(null);
} else {
record.description.setLocation(locationPath);
}
} else {
record.description.setName(projectName);
}
if (record.projectArchiveFile != null) {
// import from archive
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;
}
// import from file system
File importSource = null;
if (copyFiles) {
// import project from location copying files - use default project
// location for this workspace
URI locationURI = record.description.getLocationURI();
// some error condition occured.
if (locationURI != null) {
// validate the location of the project being copied
IStatus result = ResourcesPlugin.getWorkspace().validateProjectLocationURI(project, locationURI);
if (!result.isOK())
throw new InvocationTargetException(new CoreException(result));
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));
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
// import operation to import project files if copy checkbox is selected
if (copyFiles && importSource != null) {
List filesToImport = FileSystemStructureProvider.INSTANCE.getChildren(importSource);
ImportOperation operation = new ImportOperation(project.getFullPath(), importSource, FileSystemStructureProvider.INSTANCE, this, filesToImport);
operation.setContext(getShell());
// need to overwrite
operation.setOverwriteResources(true);
// .project, .classpath
// files
operation.setCreateContainerStructure(false);
operation.run(monitor);
}
return true;
}
use of org.eclipse.core.resources.IProjectDescription in project ow by vtst.
the class Utils method setProjectNature.
/**
* Set or remove a nature to a project.
* @param project The project.
* @param nature The ID of the nature.
* @param status true to set the nature, false to remove it.
* @throws CoreException
*/
public static void setProjectNature(IProject project, String nature, boolean status) throws CoreException {
IProjectDescription description = project.getDescription();
String[] newNatures = setFlagInArrayOfFlags(description.getNatureIds(), nature, status);
if (newNatures != null) {
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
}
use of org.eclipse.core.resources.IProjectDescription in project XobotOS by xamarin.
the class SharpenNature method deconfigure.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.resources.IProjectNature#deconfigure()
*/
public void deconfigure() throws CoreException {
IProjectDescription description = getProject().getDescription();
ICommand[] commands = description.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(SharpenBuilder.BUILDER_ID)) {
ICommand[] newCommands = new ICommand[commands.length - 1];
System.arraycopy(commands, 0, newCommands, 0, i);
System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
description.setBuildSpec(newCommands);
return;
}
}
}
use of org.eclipse.core.resources.IProjectDescription in project XobotOS by xamarin.
the class SharpenNature method configure.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.resources.IProjectNature#configure()
*/
public void configure() throws CoreException {
IProjectDescription desc = _project.getDescription();
ICommand[] commands = desc.getBuildSpec();
if (containsBuilderCommand(commands))
return;
desc.setBuildSpec(append(commands, newBuilderCommand(desc)));
_project.setDescription(desc, null);
}
use of org.eclipse.core.resources.IProjectDescription in project mechanoid by robotoworks.
the class MechanoidXtextAddingEditorCallback method toggleNature.
public void toggleNature(IProject project) {
try {
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
for (int i = 0; i < natures.length; ++i) {
if (XtextProjectHelper.NATURE_ID.equals(natures[i])) {
// Remove the nature
String[] newNatures = new String[natures.length - 1];
System.arraycopy(natures, 0, newNatures, 0, i);
System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
description.setNatureIds(newNatures);
project.setDescription(description, null);
return;
}
}
// Add the nature
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = XtextProjectHelper.NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, null);
} catch (CoreException e) {
log.error(e);
}
}
Aggregations