Search in sources :

Example 1 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class Util method getPackageFragment.

public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
    if (jarSeparator != -1) {
        String jarMemento = new String(fileName, 0, jarSeparator);
        PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento);
        if (pkgEnd == jarSeparator)
            return root.getPackageFragment(CharOperation.NO_STRINGS);
        char[] pkgName = CharOperation.subarray(fileName, jarSeparator + 1, pkgEnd);
        char[][] compoundName = CharOperation.splitOn('/', pkgName);
        return root.getPackageFragment(CharOperation.toStrings(compoundName));
    } else {
        Path path = new Path(new String(fileName, 0, pkgEnd));
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
        IJavaElement element = JavaCore.create(folder);
        if (element == null)
            return null;
        switch(element.getElementType()) {
            case IJavaElement.PACKAGE_FRAGMENT:
                return (IPackageFragment) element;
            case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                return ((PackageFragmentRoot) element).getPackageFragment(CharOperation.NO_STRINGS);
            case IJavaElement.JAVA_PROJECT:
                PackageFragmentRoot root = (PackageFragmentRoot) ((IJavaProject) element).getPackageFragmentRoot(folder);
                if (root == null)
                    return null;
                return root.getPackageFragment(CharOperation.NO_STRINGS);
        }
        return null;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer)

Example 2 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class ImportOperation method collectExistingReadonlyFiles.

/**
     * Prompts if existing resources should be overwritten. Recursively collects
     * existing read-only files to overwrite and resources that should not be
     * overwritten.
     *
     * @param sourceStart destination path to check for existing files
     * @param sources file system objects that may exist in the destination
     * @param noOverwrite files that were selected to be skipped (don't overwrite).
     * 	object type IPath
     * @param overwriteReadonly the collected existing read-only files to overwrite.
     * 	object type IPath
     * @param policy on of the POLICY constants defined in the
     * class.
     */
void collectExistingReadonlyFiles(IPath sourceStart, List sources, ArrayList noOverwrite, ArrayList overwriteReadonly, int policy) {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    Iterator sourceIter = sources.iterator();
    IPath sourceRootPath = null;
    if (this.source != null) {
        sourceRootPath = new Path(provider.getFullPath(this.source));
    }
    while (sourceIter.hasNext()) {
        Object nextSource = sourceIter.next();
        IPath sourcePath = new Path(provider.getFullPath(nextSource));
        IPath newDestinationPath;
        IResource newDestination;
        if (sourceRootPath == null) {
            newDestinationPath = sourceStart.append(provider.getLabel(nextSource));
        } else {
            int prefixLength = sourcePath.matchingFirstSegments(sourceRootPath);
            IPath relativeSourcePath = sourcePath.removeFirstSegments(prefixLength);
            newDestinationPath = this.destinationPath.append(relativeSourcePath);
        }
        newDestination = workspaceRoot.findMember(newDestinationPath);
        if (newDestination == null) {
            continue;
        }
        IFolder folder = getFolder(newDestination);
        if (folder != null) {
            if (policy != POLICY_FORCE_OVERWRITE) {
                if (this.overwriteState == OVERWRITE_NONE || !queryOverwrite(newDestinationPath)) {
                    noOverwrite.add(folder);
                    continue;
                }
            }
            if (provider.isFolder(nextSource)) {
                collectExistingReadonlyFiles(newDestinationPath, provider.getChildren(nextSource), noOverwrite, overwriteReadonly, POLICY_FORCE_OVERWRITE);
            }
        } else {
            IFile file = getFile(newDestination);
            if (file != null) {
                if (!queryOverwriteFile(file, policy)) {
                    noOverwrite.add(file.getFullPath());
                } else if (file.isReadOnly()) {
                    overwriteReadonly.add(file);
                }
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) Iterator(java.util.Iterator) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class ImportOperation method createFromRoot.

/**
     * Creates the folders that appear in the specified resource path
     * assuming that the destinationContainer begins at the root. Do not create projects.
     *
     * @param path the relative path of the resource
     * @return the container resource coresponding to the given path
     * @exception CoreException if this method failed
     */
private IContainer createFromRoot(IPath path) throws CoreException {
    int segmentCount = path.segmentCount();
    //Assume the project exists 
    IContainer currentFolder = ((IWorkspaceRoot) destinationContainer).getProject(path.segment(0));
    for (int i = 1; i < segmentCount; i++) {
        currentFolder = currentFolder.getFolder(new Path(path.segment(i)));
        if (!currentFolder.exists()) {
            ((IFolder) currentFolder).create(false, true, null);
        }
    }
    return currentFolder;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class FileUndoState method createResourceHandle.

public IResource createResourceHandle() {
    IWorkspaceRoot workspaceRoot = parent.getWorkspace().getRoot();
    IPath fullPath = parent.getFullPath().append(name);
    return workspaceRoot.getFile(fullPath);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath)

Example 5 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project che by eclipse.

the class FolderUndoState method createResourceHandle.

public IResource createResourceHandle() {
    IWorkspaceRoot workspaceRoot = getWorkspace().getRoot();
    IPath folderPath = parent.getFullPath().append(name);
    return workspaceRoot.getFolder(folderPath);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)465 IProject (org.eclipse.core.resources.IProject)179 IPath (org.eclipse.core.runtime.IPath)171 IFile (org.eclipse.core.resources.IFile)158 Path (org.eclipse.core.runtime.Path)110 CoreException (org.eclipse.core.runtime.CoreException)104 IResource (org.eclipse.core.resources.IResource)101 IWorkspace (org.eclipse.core.resources.IWorkspace)88 File (java.io.File)77 IContainer (org.eclipse.core.resources.IContainer)59 IFolder (org.eclipse.core.resources.IFolder)40 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)36 Test (org.junit.Test)33 IJavaProject (org.eclipse.jdt.core.IJavaProject)29 URI (java.net.URI)27 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)25 IProjectDescription (org.eclipse.core.resources.IProjectDescription)24 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)19