Search in sources :

Example 1 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule 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 2 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule 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 3 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule 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 4 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule 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 5 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule in project eclipse.platform.text by eclipse.

the class GenericFileBufferOperationRunner method computeCommitRule.

protected ISchedulingRule computeCommitRule(IFileBuffer[] fileBuffers) {
    ArrayList<ISchedulingRule> list = new ArrayList<>();
    for (IFileBuffer fileBuffer : fileBuffers) {
        ISchedulingRule rule = fileBuffer.computeCommitRule();
        if (rule != null)
            list.add(rule);
    }
    ISchedulingRule[] rules = new ISchedulingRule[list.size()];
    list.toArray(rules);
    return new MultiRule(rules);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) ArrayList(java.util.ArrayList) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)14 MultiRule (org.eclipse.core.runtime.jobs.MultiRule)14 IResource (org.eclipse.core.resources.IResource)6 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 IResourceRuleFactory (org.eclipse.core.resources.IResourceRuleFactory)2 IPath (org.eclipse.core.runtime.IPath)2 Iterator (java.util.Iterator)1 IFileBuffer (org.eclipse.core.filebuffers.IFileBuffer)1 IContainer (org.eclipse.core.resources.IContainer)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IModelChange (org.eclipse.ecf.sync.IModelChange)1