use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.
the class File method setContents.
@Override
public void setContents(InputStream content, int updateFlags, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
String message = NLS.bind(Messages.resources_settingContents, getFullPath());
monitor.beginTask(message, Policy.totalWork);
// if (workspace.shouldValidate)
// workspace.validateSave(this);
final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
try {
workspace.prepareOperation(rule, monitor);
ResourceInfo info = getResourceInfo(false, false);
// checkAccessible(getFlags(info));
workspace.beginOperation(true);
// IFileInfo fileInfo = getStore().fetchInfo();
internalSetContents(content, updateFlags, false, Policy.subMonitorFor(monitor, Policy.opWork));
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
FileUtil.safeClose(content);
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project che by eclipse.
the class Resource method delete.
@Override
public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
// String message = NLS.bind(Messages.resources_deleting, getFullPath());
// monitor.beginTask("", Policy.totalWork * 1000); //$NON-NLS-1$
// monitor.subTask(message);
final ISchedulingRule rule = workspace.getRuleFactory().deleteRule(this);
try {
workspace.prepareOperation(rule, monitor);
// if there is no resource then there is nothing to delete so just return
if (!exists())
return;
workspace.beginOperation(true);
// broadcastPreDeleteEvent();
// when a project is being deleted, flush the build order in case there is a problem
// if (this.getType() == IResource.PROJECT)
// workspace.flushBuildOrder();
// final IFileStore originalStore = getStore();
// boolean wasLinked = isLinked();
// message = Messages.resources_deleteProblem;
// MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_DELETE_LOCAL, message, null);
WorkManager workManager = workspace.getWorkManager();
// ResourceTree tree = new ResourceTree(workspace.getFileSystemManager(), workManager.getLock(), status, updateFlags);
int depth = 0;
try {
depth = workManager.beginUnprotected();
workspace.delete(this);
// unprotectedDelete(tree, updateFlags, monitor);
} finally {
workManager.endUnprotected(depth);
}
if (getType() == ROOT) {
// // need to clear out the root info
// workspace.getMarkerManager().removeMarkers(this, IResource.DEPTH_ZERO);
// getPropertyManager().deleteProperties(this, IResource.DEPTH_ZERO);
// getResourceInfo(false, false).clearSessionProperties();
}
// Invalidate the tree for further use by clients.
// tree.makeInvalid();
// if (!tree.getStatus().isOK())
// throw new ResourceException(tree.getStatus());
//update any aliases of this resource
//note that deletion of a linked resource cannot affect other resources
// if (!wasLinked)
// workspace.getAliasManager().updateAliases(this, originalStore, IResource.DEPTH_INFINITE, monitor);
// if (getType() == PROJECT) {
// make sure the rule factory is cleared on project deletion
// ((Rules) workspace.getRuleFactory()).setRuleFactory((IProject) this, null);
// make sure project deletion is remembered
// workspace.getSaveManager().requestSnapshot();
// }
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork * 1000));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule 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);
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule 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());
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule 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);
}
Aggregations