Search in sources :

Example 56 with IContainer

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);
}
Also used : IContainer(org.eclipse.core.resources.IContainer)

Example 57 with IContainer

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IContainer(org.eclipse.core.resources.IContainer) ContainerCreator(org.eclipse.core.filebuffers.manipulation.ContainerCreator) IFolder(org.eclipse.core.resources.IFolder)

Example 58 with IContainer

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 59 with IContainer

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;
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IContainer(org.eclipse.core.resources.IContainer)

Example 60 with IContainer

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);
    }
}
Also used : RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9