Search in sources :

Example 6 with MultiRule

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

the class ResourcesShare method handleResourceChangeMessage.

private void handleResourceChangeMessage(byte[] data) throws Exception {
    IModelChange remoteChange = ResourcesSynchronizationStrategy.getInstance().deserializeRemoteChange(data);
    final IModelChange[] remoteChanges = ResourcesSynchronizationStrategy.getInstance().transformRemoteChange(remoteChange);
    // create a scheduling rule to lock the projects
    ISchedulingRule[] rules = new ISchedulingRule[sharedProjects.size()];
    int index = 0;
    for (Iterator it = sharedProjects.iterator(); it.hasNext(); ) {
        String projectName = (String) it.next();
        rules[index] = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        index++;
    }
    try {
        // lock to prevent resource changes from being propagated
        lock(remoteChanges);
        applyRemoteChanges(remoteChanges, new MultiRule(rules));
    } finally {
        // unlock now that we've applied the remote changes to our
        // own workspace
        unlock(remoteChanges);
    }
    if (remoteChange instanceof BatchModelChange) {
        BatchModelChange batchChange = (BatchModelChange) remoteChange;
        batchChange.setOutgoing(false);
        batchChange.setTime(System.currentTimeMillis());
        SyncResourcesCore.add(batchChange);
    }
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) Iterator(java.util.Iterator) IModelChange(org.eclipse.ecf.sync.IModelChange) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 7 with MultiRule

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

the class MultiRuleTest method testContains.

public void testContains() {
    ISchedulingRule child1 = new PathRule("/a");
    ISchedulingRule child2 = new PathRule("/b/c");
    ISchedulingRule childOfChild1 = new PathRule("/a/b");
    ISchedulingRule nonChild = new PathRule("/z/d");
    MultiRule multi1 = new MultiRule(new ISchedulingRule[] { child1, child2 });
    MultiRule multi2 = new MultiRule(new ISchedulingRule[] { childOfChild1 });
    assertTrue("1.0", multi1.contains(child1));
    assertTrue("1.1", multi1.contains(child2));
    assertTrue("1.2", !multi1.contains(nonChild));
    assertTrue("1.3", multi1.contains(childOfChild1));
    assertTrue("1.4", multi1.contains(multi2));
    assertTrue("1.5", !multi2.contains(multi1));
    assertTrue("1.6", multi1.contains(multi1));
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 8 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule in project polymap4-core by Polymap4.

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 rules = new HashSet();
    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 (ISchedulingRule) rules.iterator().next();
    ISchedulingRule[] ruleArray = (ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]);
    return new MultiRule(ruleArray);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 9 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule in project pmd-eclipse-plugin by pmd.

the class ReviewCodeCmd method getSchedulingRule.

/**
 * @return the scheduling rule needed to apply markers
 */
private ISchedulingRule getSchedulingRule() {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IResourceRuleFactory ruleFactory = workspace.getRuleFactory();
    ISchedulingRule rule;
    if (resources.isEmpty()) {
        rule = ruleFactory.markerRule(resourceDelta.getResource().getProject());
    } else {
        ISchedulingRule[] rules = new ISchedulingRule[resources.size()];
        for (int i = 0; i < rules.length; i++) {
            rules[i] = ruleFactory.markerRule((IResource) resources.get(i));
        }
        rule = new MultiRule(resources.toArray(rules));
    }
    return rule;
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) IWorkspace(org.eclipse.core.resources.IWorkspace) IResourceRuleFactory(org.eclipse.core.resources.IResourceRuleFactory) IResource(org.eclipse.core.resources.IResource) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 10 with MultiRule

use of org.eclipse.core.runtime.jobs.MultiRule in project polymap4-core by Polymap4.

the class ResourceRuleFactory method validateEditRule.

/**
 * Default implementation of <code>IResourceRuleFactory#validateEditRule</code>.
 * This default implementation returns a rule that combines the parents of
 * all read-only resources, or <code>null</code> if there are no read-only
 * resources.
 * <p>
 * Subclasses may override this method. The rule provided by an overriding
 * method must at least contain the rule from this default implementation.
 *
 * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule)
 * @see org.eclipse.core.resources.IResourceRuleFactory#validateEditRule(IResource[])
 */
public ISchedulingRule validateEditRule(IResource[] resources) {
    if (resources.length == 0)
        return null;
    // optimize rule for single file
    if (resources.length == 1)
        return isReadOnly(resources[0]) ? parent(resources[0]) : null;
    // need a lock on the parents of all read-only files
    HashSet rules = new HashSet();
    for (int i = 0; i < resources.length; i++) if (isReadOnly(resources[i]))
        rules.add(parent(resources[i]));
    if (rules.isEmpty())
        return null;
    if (rules.size() == 1)
        return (ISchedulingRule) rules.iterator().next();
    ISchedulingRule[] ruleArray = (ISchedulingRule[]) rules.toArray(new ISchedulingRule[rules.size()]);
    return new MultiRule(ruleArray);
}
Also used : MultiRule(org.eclipse.core.runtime.jobs.MultiRule) HashSet(java.util.HashSet) 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