Search in sources :

Example 6 with IResource

use of org.eclipse.core.resources.IResource 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 7 with IResource

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

the class FileNamePatternSearchScope method addToList.

private static void addToList(ArrayList res, IResource curr, boolean includeDerived) {
    //		if (!includeDerived && curr.isDerived(IResource.CHECK_ANCESTORS)) {
    //			return;
    //		}
    IPath currPath = curr.getFullPath();
    for (int k = res.size() - 1; k >= 0; k--) {
        IResource other = (IResource) res.get(k);
        IPath otherPath = other.getFullPath();
        if (otherPath.isPrefixOf(currPath)) {
            return;
        }
        if (currPath.isPrefixOf(otherPath)) {
            res.remove(k);
        }
    }
    res.add(curr);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource)

Example 8 with IResource

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

the class AbstractResourceDescription method createResource.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ui.ide.undo.ResourceDescription#createResource(org.eclipse
	 * .core.runtime.IProgressMonitor)
	 */
public IResource createResource(IProgressMonitor monitor) throws CoreException {
    IResource resource = createResourceHandle();
    createExistentResourceFromHandle(resource, monitor);
    restoreResourceAttributes(resource);
    return resource;
}
Also used : IResource(org.eclipse.core.resources.IResource)

Example 9 with IResource

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

the class AbstractResourceDescription method verifyExistence.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.ide.undo.ResourceDescription#verifyExistence(boolean)
	 */
public boolean verifyExistence(boolean checkMembers) {
    IContainer p = parent;
    if (p == null) {
        p = getWorkspace().getRoot();
    }
    IResource handle = p.findMember(getName());
    return handle != null;
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 10 with IResource

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

the class RenameResourceProcessor method createDescriptor.

protected RenameResourceDescriptor createDescriptor() {
    IResource resource = getResource();
    RenameResourceDescriptor descriptor = new RenameResourceDescriptor();
    descriptor.setProject(resource instanceof IProject ? null : resource.getProject().getName());
    descriptor.setDescription(Messages.format(RefactoringCoreMessages.RenameResourceProcessor_description, BasicElementLabels.getResourceName(resource)));
    descriptor.setComment(Messages.format(RefactoringCoreMessages.RenameResourceProcessor_comment, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getResourceName(getNewResourceName()) }));
    descriptor.setFlags(RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE | RefactoringDescriptor.BREAKING_CHANGE);
    descriptor.setResourcePath(resource.getFullPath());
    descriptor.setNewName(getNewResourceName());
    descriptor.setUpdateReferences(isUpdateReferences());
    return descriptor;
}
Also used : RenameResourceDescriptor(org.eclipse.ltk.core.refactoring.resource.RenameResourceDescriptor) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Aggregations

IResource (org.eclipse.core.resources.IResource)1487 IFile (org.eclipse.core.resources.IFile)390 CoreException (org.eclipse.core.runtime.CoreException)390 IPath (org.eclipse.core.runtime.IPath)315 IProject (org.eclipse.core.resources.IProject)286 ArrayList (java.util.ArrayList)237 IFolder (org.eclipse.core.resources.IFolder)187 IContainer (org.eclipse.core.resources.IContainer)175 Path (org.eclipse.core.runtime.Path)141 File (java.io.File)124 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)109 IOException (java.io.IOException)103 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)95 IStatus (org.eclipse.core.runtime.IStatus)89 List (java.util.List)83 IJavaProject (org.eclipse.jdt.core.IJavaProject)75 HashSet (java.util.HashSet)71 Status (org.eclipse.core.runtime.Status)66 HashMap (java.util.HashMap)60 IAdaptable (org.eclipse.core.runtime.IAdaptable)59