use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class RPMProjectCreator method create.
/**
* Creates a project with the given name in the given location.
*
* @param projectName
* The name of the project.
* @param projectPath
* The parent location of the project.
* @param monitor
* Progress monitor to report back status.
* @return The newly created project.
* @throws CoreException If the location is wrong.
*/
public IProject create(String projectName, IPath projectPath, IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
String parsedIPathString = null;
if (!Platform.getLocation().equals(projectPath)) {
// $NON-NLS-1$ //$NON-NLS-2$
parsedIPathString = projectPath.toString().replaceFirst(":/", "://");
try {
description.setLocationURI(new URI(parsedIPathString));
} catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID, e.getMessage(), e));
}
}
description.setNatureIds(new String[] { IRPMConstants.RPM_NATURE_ID });
project.create(description, monitor);
monitor.worked(10);
project.open(monitor);
new RPMProject(project, layout);
return project;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class ChangeLogAction method createChangeLog.
protected IFile createChangeLog(IPath changelog) {
IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
IWorkbench ws = PlatformUI.getWorkbench();
final IFile changelog_File = myWorkspaceRoot.getFile(changelog);
final InputStream initialContents = new ByteArrayInputStream(new byte[0]);
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
try {
// $NON-NLS-1$
monitor.beginTask(Messages.getString("ChangeLog.AddingChangeLog"), 2000);
changelog_File.create(initialContents, false, monitor);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
} finally {
monitor.done();
}
}
};
try {
new ProgressMonitorDialog(ws.getActiveWorkbenchWindow().getShell()).run(true, true, operation);
} catch (InterruptedException e) {
// $NON-NLS-1$
reportErr(Messages.getString("ChangeLog.ErrInterrupted"), e);
return null;
} catch (InvocationTargetException e) {
// $NON-NLS-1$
reportErr(Messages.getString("ChangeLog.ErrInvocation"), e);
return null;
}
// FIXME: we should put this refreshLocal call into a thread (filed as bug #256180)
try {
IContainer changelogContainer = myWorkspaceRoot.getContainerForLocation(changelog);
if (changelogContainer != null)
changelogContainer.refreshLocal(2, null);
} catch (CoreException e) {
// $NON-NLS-1$
reportErr(Messages.getString("ChangeLog.ErrRefresh"), e);
return null;
}
return changelog_File;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class ChangeLogAction method getChangelogForRemovePath.
/**
* Find the ChangeLog for a file that is being removed. It can't be found and
* it is possible that the directory it is in has also been removed.
*
* @param path Path of removed file
* @return ChangeLog editor part that must be used to report removed file
*/
protected IEditorPart getChangelogForRemovePath(IPath path) {
IResource parent_resource = null;
IPath loc_path = path;
// Look from current loc up to find first folder that is still existing
IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
while (loc_path.segmentCount() > 0) {
parent_resource = myWorkspaceRoot.findMember(loc_path);
if (parent_resource != null)
break;
loc_path = loc_path.removeLastSegments(1);
}
if (parent_resource != null) {
IResource parent_dec = parent_resource;
while (parent_dec != null) {
String parent_node = parent_dec.getFullPath().toOSString();
parent_node = parent_node + System.getProperty("file.separator") + // $NON-NLS-1$
pref_ChangeLogName;
IResource change_log_res = myWorkspaceRoot.findMember(parent_node);
if (change_log_res != null) {
IProject proj_loc = parent_resource.getProject();
IPath modified_changelog_path = change_log_res.getFullPath().removeFirstSegments(1);
IFile change_log_file = proj_loc.getFile(modified_changelog_path);
return openEditor(change_log_file);
}
parent_dec = parent_dec.getParent();
if (parent_dec == null) {
break;
}
}
}
return null;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class ChangeLogAction method askChangeLogLocation.
protected IEditorPart askChangeLogLocation(String editorLoc) {
IWorkbench ws = PlatformUI.getWorkbench();
IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
IResource given_resource = myWorkspaceRoot.findMember(editorLoc);
if (given_resource == null)
return null;
ChangeLogContainerSelectionDialog dialog = new ChangeLogContainerSelectionDialog(ws.getActiveWorkbenchWindow().getShell(), given_resource.getParent(), false, Messages.getString(// $NON-NLS-1$
"AddAction.str_ChangeLog_Location"));
dialog.showClosedProjects(false);
dialog.open();
Object[] result = dialog.getResult();
if (result == null)
return null;
final IPath result_path = new Path(result[0] + System.getProperty("file.separator") + // $NON-NLS-1$ //$NON-NLS-2$
pref_ChangeLogName);
IFile newChangeLog = createChangeLog(result_path);
return openEditor(newChangeLog);
}
use of org.eclipse.core.resources.IWorkspaceRoot in project linuxtools by eclipse.
the class ChangeLogAction method getChangelogFile.
protected IFile getChangelogFile(String currentEditorloc) {
// Scenario 1: The Changelog is in in the current project file
IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
IResource given_resource = myWorkspaceRoot.findMember(currentEditorloc);
if (given_resource != null) {
IResource parent_dec = given_resource;
while (parent_dec != null) {
String parent_node = parent_dec.getFullPath().removeLastSegments(1).toOSString();
parent_node = parent_node + System.getProperty("file.separator") + // $NON-NLS-1$
pref_ChangeLogName;
IResource change_log_res = myWorkspaceRoot.findMember(parent_node);
if (change_log_res != null) {
IProject proj_loc = given_resource.getProject();
IPath modified_changelog_path = change_log_res.getFullPath().removeFirstSegments(1);
IFile change_log_file = proj_loc.getFile(modified_changelog_path);
return change_log_file;
}
parent_dec = parent_dec.getParent();
if (parent_dec == null) {
break;
}
}
}
return null;
}
Aggregations