use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Project method move.
/* (non-Javadoc)
* @see IResource#move(IProjectDescription, int, IProgressMonitor)
*/
public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(description);
monitor = Policy.monitorFor(monitor);
try {
String message = NLS.bind(Messages.resources_moving, getFullPath());
monitor.beginTask(message, Policy.totalWork);
IProject destination = workspace.getRoot().getProject(description.getName());
final ISchedulingRule rule = workspace.getRuleFactory().moveRule(this, destination);
try {
workspace.prepareOperation(rule, monitor);
// and assert for programming errors. See checkMoveRequirements for more information.
if (!getName().equals(description.getName())) {
IPath destPath = Path.ROOT.append(description.getName());
assertMoveRequirements(destPath, IResource.PROJECT, updateFlags);
}
checkDescription(destination, description, true);
workspace.beginOperation(true);
message = Messages.resources_moveProblem;
MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, null);
WorkManager workManager = workspace.getWorkManager();
ResourceTree tree = new ResourceTree(getLocalManager(), workManager.getLock(), status, updateFlags);
IMoveDeleteHook hook = workspace.getMoveDeleteHook();
workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_MOVE, this, destination, updateFlags));
int depth = 0;
try {
depth = workManager.beginUnprotected();
if (!hook.moveProject(tree, this, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
tree.standardMoveProject(this, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2));
} finally {
workManager.endUnprotected(depth);
}
// Invalidate the tree for further use by clients.
tree.makeInvalid();
if (!tree.getStatus().isOK())
throw new ResourceException(tree.getStatus());
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Project method internalCopy.
protected void internalCopy(IProjectDescription destDesc, int updateFlags, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
String message = NLS.bind(Messages.resources_copying, getFullPath());
monitor.beginTask(message, Policy.totalWork);
String destName = destDesc.getName();
IPath destPath = new Path(destName).makeAbsolute();
Project destination = (Project) workspace.getRoot().getProject(destName);
final ISchedulingRule rule = workspace.getRuleFactory().copyRule(this, destination);
try {
workspace.prepareOperation(rule, monitor);
// The following assert method throws CoreExceptions as stated in the IProject.copy API
// and assert for programming errors. See checkCopyRequirements for more information.
assertCopyRequirements(destPath, IResource.PROJECT, updateFlags);
checkDescription(destination, destDesc, false);
workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_COPY, this, destination, updateFlags));
workspace.beginOperation(true);
getLocalManager().refresh(this, DEPTH_INFINITE, true, Policy.subMonitorFor(monitor, Policy.opWork * 20 / 100));
// close the property store so incorrect info is not copied to the destination
getPropertyManager().closePropertyStore(this);
getLocalManager().getHistoryStore().closeHistoryStore(this);
// copy the meta area for the project
copyMetaArea(this, destination, Policy.subMonitorFor(monitor, Policy.opWork * 5 / 100));
// copy just the project and not its children yet (tree node, properties)
internalCopyProjectOnly(destination, Policy.subMonitorFor(monitor, Policy.opWork * 5 / 100));
// set the description
destination.internalSetDescription(destDesc, false);
// create the directory for the new project
destination.getStore().mkdir(EFS.NONE, Policy.subMonitorFor(monitor, Policy.opWork * 5 / 100));
// call super.copy for each child (excluding project description file)
// make it a best effort copy
message = Messages.resources_copyProblem;
MultiStatus problems = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.INTERNAL_ERROR, message, null);
IResource[] children = members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS | IContainer.INCLUDE_HIDDEN);
final int childCount = children.length;
final int childWork = childCount > 1 ? Policy.opWork * 50 / 100 / (childCount - 1) : 0;
for (int i = 0; i < childCount; i++) {
IResource child = children[i];
if (!isProjectDescriptionFile(child)) {
try {
child.copy(destPath.append(child.getName()), updateFlags, Policy.subMonitorFor(monitor, childWork));
} catch (CoreException e) {
problems.merge(e.getStatus());
}
}
}
// write out the new project description to the meta area
try {
destination.writeDescription(IResource.FORCE);
} catch (CoreException e) {
try {
destination.delete((updateFlags & IResource.FORCE) != 0, null);
} catch (CoreException e2) {
// ignore and rethrow the exception that got us here
}
throw e;
}
monitor.worked(Policy.opWork * 5 / 100);
// refresh local
monitor.subTask(Messages.resources_updating);
getLocalManager().refresh(destination, DEPTH_INFINITE, true, Policy.subMonitorFor(monitor, Policy.opWork * 10 / 100));
if (!problems.isOK())
throw new ResourceException(problems);
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Project method open.
/* (non-Javadoc)
* @see IProject#open(IProgressMonitor)
*/
public void open(int updateFlags, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
String msg = NLS.bind(Messages.resources_opening_1, getName());
monitor.beginTask(msg, Policy.totalWork);
monitor.subTask(msg);
final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
try {
workspace.prepareOperation(rule, monitor);
ProjectInfo info = (ProjectInfo) getResourceInfo(false, false);
int flags = getFlags(info);
checkExists(flags, true);
if (isOpen(flags))
return;
workspace.beginOperation(true);
// flush the build order early in case there is a problem
workspace.flushBuildOrder();
info = (ProjectInfo) getResourceInfo(false, true);
info.set(M_OPEN);
// clear the unknown children immediately to avoid background refresh
boolean unknownChildren = info.isSet(M_CHILDREN_UNKNOWN);
if (unknownChildren)
info.clear(M_CHILDREN_UNKNOWN);
// the M_USED flag is used to indicate the difference between opening a project
// for the first time and opening it from a previous close (restoring it from disk)
boolean used = info.isSet(M_USED);
boolean minorIssuesDuringRestore = false;
if (used) {
minorIssuesDuringRestore = workspace.getSaveManager().restore(this, Policy.subMonitorFor(monitor, Policy.opWork * 20 / 100));
} else {
info.set(M_USED);
// reconcile any links in the project description
IStatus result = reconcileLinks(info.getDescription());
if (!result.isOK())
throw new CoreException(result);
workspace.updateModificationStamp(info);
monitor.worked(Policy.opWork * 20 / 100);
}
startup();
// or restore of the project is not fully succesfull
if ((!used && unknownChildren) || !minorIssuesDuringRestore) {
// refresh either in background or foreground
if ((updateFlags & IResource.BACKGROUND_REFRESH) != 0) {
workspace.refreshManager.refresh(this);
monitor.worked(Policy.opWork * 80 / 100);
} else {
refreshLocal(IResource.DEPTH_INFINITE, Policy.subMonitorFor(monitor, Policy.opWork * 80 / 100));
}
}
// creation of this project may affect overlapping resources
workspace.getAliasManager().updateAliases(this, getStore(), IResource.DEPTH_INFINITE, monitor);
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class Project method touch.
/* (non-Javadoc)
* @see IResource#touch(IProgressMonitor)
*/
public void touch(IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
String message = NLS.bind(Messages.resources_touch, getFullPath());
monitor.beginTask(message, Policy.totalWork);
final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this);
try {
workspace.prepareOperation(rule, monitor);
workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_CHANGE, this));
workspace.beginOperation(true);
super.touch(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();
}
}
use of org.eclipse.core.runtime.jobs.ISchedulingRule in project polymap4-core by Polymap4.
the class File method setCharset.
/* (non-Javadoc)
* @see IFile#setCharset(String, IProgressMonitor)
*/
public void setCharset(String newCharset, IProgressMonitor monitor) throws CoreException {
monitor = Policy.monitorFor(monitor);
try {
String message = NLS.bind(Messages.resources_settingCharset, getFullPath());
monitor.beginTask(message, Policy.totalWork);
// need to get the project as a scheduling rule because we might be creating a new folder/file to
// hold the project settings
final ISchedulingRule rule = workspace.getRuleFactory().charsetRule(this);
try {
workspace.prepareOperation(rule, monitor);
ResourceInfo info = getResourceInfo(false, false);
checkAccessible(getFlags(info));
workspace.beginOperation(true);
workspace.getCharsetManager().setCharsetFor(getFullPath(), newCharset);
info = getResourceInfo(false, true);
info.incrementCharsetGenerationCount();
monitor.worked(Policy.opWork);
} catch (OperationCanceledException e) {
workspace.getWorkManager().operationCanceled();
throw e;
} finally {
workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
}
} finally {
monitor.done();
}
}
Aggregations