use of org.eclipse.core.resources.IContainer in project eclipse.platform.text by eclipse.
the class SelectResourcesDialog method selectAndReveal.
private void selectAndReveal(IResource resource) {
IContainer container = null;
if ((IResource.FILE & resource.getType()) > 0)
container = resource.getParent();
else
container = (IContainer) resource;
fResourceGroup.selectAndReveal(container);
}
use of org.eclipse.core.resources.IContainer in project eclipse.platform.text by eclipse.
the class ResourceHelper method createFolder.
public static IFolder createFolder(String portableFolderPath) throws CoreException {
ContainerCreator creator = new ContainerCreator(ResourcesPlugin.getWorkspace(), new Path(portableFolderPath));
IContainer container = creator.createContainer(NULL_MONITOR);
if (container instanceof IFolder)
return (IFolder) container;
return null;
}
use of org.eclipse.core.resources.IContainer in project eclipse.platform.text by eclipse.
the class ContainerCreator method createContainer.
/**
* Creates this container.
*
* @param progressMonitor the progress monitor or <code>null</code> if none
* @return the container specified by this container creator's full path
* @throws CoreException if this container creator's full path denotes a file or creating
* either the project or folders for the given container fails
*/
public IContainer createContainer(IProgressMonitor progressMonitor) throws CoreException {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, FileBuffersMessages.ContainerCreator_task_creatingContainer, fContainerFullPath.segmentCount());
if (fContainer != null)
return;
// Does the container exist already?
IWorkspaceRoot root = fWorkspace.getRoot();
IResource found = root.findMember(fContainerFullPath);
if (found instanceof IContainer) {
fContainer = (IContainer) found;
return;
} else if (found != null) {
// fContainerFullPath specifies a file as directory
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.ContainerCreator_destinationMustBeAContainer, fContainerFullPath), null));
}
// Create the containers for the given path
fContainer = root;
for (int i = 0; i < fContainerFullPath.segmentCount(); i++) {
String currentSegment = fContainerFullPath.segment(i);
IResource resource = fContainer.findMember(currentSegment);
if (resource != null) {
if (resource instanceof IContainer) {
fContainer = (IContainer) resource;
subMonitor.split(1);
} else {
// fContainerFullPath specifies a file as directory
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.ContainerCreator_destinationMustBeAContainer, resource.getFullPath()), null));
}
} else {
if (i == 0) {
IProject projectHandle = createProjectHandle(root, currentSegment);
fContainer = createProject(projectHandle, subMonitor.split(1));
} else {
IFolder folderHandle = createFolderHandle(fContainer, currentSegment);
fContainer = createFolder(folderHandle, subMonitor.split(1));
}
}
}
}
};
// Get scheduling rule
IWorkspaceRoot root = fWorkspace.getRoot();
IPath existingParentPath = fContainerFullPath;
while (!root.exists(existingParentPath)) existingParentPath = existingParentPath.removeLastSegments(1);
IResource schedulingRule = root.findMember(existingParentPath);
fWorkspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, progressMonitor);
return fContainer;
}
use of org.eclipse.core.resources.IContainer in project xtext-xtend by eclipse.
the class ConvertJavaCode method xtendFileToCreate.
private IFile xtendFileToCreate(ICompilationUnit iCompilationUnit) {
IContainer parent = iCompilationUnit.getResource().getParent();
String xtendFileName = Files.getNameWithoutExtension(iCompilationUnit.getElementName()) + "." + fileExtensionProvider.getPrimaryFileExtension();
IFile file = parent.getFile(new Path(xtendFileName));
return file;
}
use of org.eclipse.core.resources.IContainer in project xtext-xtend by eclipse.
the class SourceRelativeFileSystemAccess method ensureOutputConfigurationDirectoryExists.
@Override
protected boolean ensureOutputConfigurationDirectoryExists(OutputConfiguration outputConfig) {
try {
if (super.ensureOutputConfigurationDirectoryExists(outputConfig)) {
IContainer container = getContainer(outputConfig);
addToSourceFolders(container);
return true;
}
return false;
} catch (CoreException e) {
throw new RuntimeIOException(e);
}
}
Aggregations