Search in sources :

Example 66 with IResource

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

the class Resource method isConflicting.

@Override
public boolean isConflicting(ISchedulingRule rule) {
    if (this == rule)
        return true;
    //must not schedule at same time as notification
    if (rule.getClass().equals(WorkManager.NotifyRule.class))
        return true;
    if (rule instanceof MultiRule) {
        MultiRule multi = (MultiRule) rule;
        ISchedulingRule[] children = multi.getChildren();
        for (int i = 0; i < children.length; i++) if (isConflicting(children[i]))
            return true;
        return false;
    }
    if (!(rule instanceof IResource))
        return false;
    IResource resource = (IResource) rule;
    if (!workspace.equals(resource.getWorkspace()))
        return false;
    IPath otherPath = resource.getFullPath();
    return path.isPrefixOf(otherPath) || otherPath.isPrefixOf(path);
}
Also used : IPath(org.eclipse.core.runtime.IPath) MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 67 with IResource

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

the class Resource method contains.

@Override
public boolean contains(ISchedulingRule rule) {
    if (this == rule)
        return true;
    //must allow notifications to nest in all resource rules
    if (rule.getClass().equals(WorkManager.NotifyRule.class))
        return true;
    if (rule instanceof MultiRule) {
        MultiRule multi = (MultiRule) rule;
        ISchedulingRule[] children = multi.getChildren();
        for (int i = 0; i < children.length; i++) if (!contains(children[i]))
            return false;
        return true;
    }
    if (!(rule instanceof IResource))
        return false;
    IResource resource = (IResource) rule;
    if (!workspace.equals(resource.getWorkspace()))
        return false;
    return path.isPrefixOf(resource.getFullPath());
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 68 with IResource

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

the class Rules method validateEditRule.

/**
	 * Combines rules for each parameter to validateEdit from the corresponding
	 * rule factories.
	 */
public ISchedulingRule validateEditRule(IResource[] resources) {
    if (resources.length == 0)
        return null;
    //optimize rule for single file
    if (resources.length == 1) {
        if (resources[0].getType() == IResource.ROOT)
            return root;
        return factoryFor(resources[0]).validateEditRule(resources);
    }
    //gather rules for each resource from appropriate factory
    HashSet<ISchedulingRule> rules = new HashSet<ISchedulingRule>();
    IResource[] oneResource = new IResource[1];
    for (int i = 0; i < resources.length; i++) {
        if (resources[i].getType() == IResource.ROOT)
            return root;
        oneResource[0] = resources[i];
        ISchedulingRule rule = factoryFor(resources[i]).validateEditRule(oneResource);
        if (rule != null)
            rules.add(rule);
    }
    if (rules.isEmpty())
        return null;
    if (rules.size() == 1)
        return rules.iterator().next();
    ISchedulingRule[] ruleArray = rules.toArray(new ISchedulingRule[rules.size()]);
    return new MultiRule(ruleArray);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 69 with IResource

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

the class Workspace method delete.

@Override
public IStatus delete(IResource[] resources, int updateFlags, IProgressMonitor monitor) throws CoreException {
    monitor = Policy.monitorFor(monitor);
    try {
        int opWork = Math.max(resources.length, 1);
        int totalWork = Policy.totalWork * opWork / Policy.opWork;
        String message = Messages.resources_deleting_0;
        monitor.beginTask(message, totalWork);
        message = Messages.resources_deleteProblem;
        MultiStatus result = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.INTERNAL_ERROR, message, null);
        if (resources.length == 0)
            return result;
        // to avoid concurrent changes to this array
        resources = resources.clone();
        try {
            prepareOperation(getRoot(), monitor);
            beginOperation(true);
            for (int i = 0; i < resources.length; i++) {
                Policy.checkCanceled(monitor);
                Resource resource = (Resource) resources[i];
                if (resource == null) {
                    monitor.worked(1);
                    continue;
                }
                try {
                    resource.delete(updateFlags, Policy.subMonitorFor(monitor, 1));
                } catch (CoreException e) {
                    // Don't really care about the exception unless the resource is still around.
                    ResourceInfo info = resource.getResourceInfo(false, false);
                    if (resource.exists(resource.getFlags(info), false)) {
                        message = NLS.bind(Messages.resources_couldnotDelete, resource.getFullPath());
                        result.merge(new org.eclipse.core.internal.resources.ResourceStatus(IResourceStatus.FAILED_DELETE_LOCAL, resource.getFullPath(), message));
                        result.merge(e.getStatus());
                    }
                }
            }
            if (result.matches(IStatus.ERROR))
                throw new ResourceException(result);
            return result;
        } catch (OperationCanceledException e) {
            getWorkManager().operationCanceled();
            throw e;
        } finally {
            endOperation(getRoot(), true, Policy.subMonitorFor(monitor, totalWork - opWork));
        }
    } finally {
        monitor.done();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResource(org.eclipse.core.resources.IResource) MultiStatus(org.eclipse.core.runtime.MultiStatus) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ResourceException(org.eclipse.core.internal.resources.ResourceException)

Example 70 with IResource

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

the class ResourceChangeDescriptionFactory method getDelta.

private ProposedResourceDelta getDelta(IResource resource) {
    ProposedResourceDelta delta = (ProposedResourceDelta) root.findMember(resource.getFullPath());
    if (delta != null) {
        return delta;
    }
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IResource iResource = resource.getParent();
    if (iResource == null) {
        iResource = ((Workspace) workspace).newResource(resource.getFullPath().removeLastSegments(1), IResource.FOLDER);
    }
    ProposedResourceDelta parent = getDelta(iResource);
    delta = new ProposedResourceDelta(resource);
    parent.add(delta);
    return delta;
}
Also used : IWorkspace(org.eclipse.core.resources.IWorkspace) IResource(org.eclipse.core.resources.IResource)

Aggregations

IResource (org.eclipse.core.resources.IResource)559 CoreException (org.eclipse.core.runtime.CoreException)141 IFile (org.eclipse.core.resources.IFile)140 IPath (org.eclipse.core.runtime.IPath)119 IProject (org.eclipse.core.resources.IProject)104 IContainer (org.eclipse.core.resources.IContainer)88 ArrayList (java.util.ArrayList)84 IFolder (org.eclipse.core.resources.IFolder)64 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)52 IStatus (org.eclipse.core.runtime.IStatus)47 IOException (java.io.IOException)46 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)44 Path (org.eclipse.core.runtime.Path)42 File (java.io.File)39 Status (org.eclipse.core.runtime.Status)38 IJavaProject (org.eclipse.jdt.core.IJavaProject)31 IJavaElement (org.eclipse.jdt.core.IJavaElement)30 ISelection (org.eclipse.jface.viewers.ISelection)26 List (java.util.List)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22