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);
}
}
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));
}
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);
}
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;
}
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);
}
Aggregations