use of org.eclipse.ui.ide.undo.DeleteResourcesOperation in project translationstudio8 by heartsome.
the class DeleteResourceAndCloseEditorAction method scheduleDeleteJob.
/**
* Schedule a job to delete the resources to delete.
* @param resourcesToDelete
*/
private void scheduleDeleteJob(final IResource[] resourcesToDelete) {
// use a non-workspace job with a runnable inside so we can avoid
// periodic updates
Job deleteJob = new Job(IDEWorkbenchMessages.DeleteResourceAction_jobName) {
public IStatus run(final IProgressMonitor monitor) {
try {
final DeleteResourcesOperation op = new DeleteResourcesOperation(resourcesToDelete, IDEWorkbenchMessages.DeleteResourceAction_operationLabel, deleteContent);
op.setModelProviderIds(getModelProviderIds());
// added to the undo history.
if (deleteContent && containsOnlyProjects(resourcesToDelete)) {
// We must compute the execution status first so that any user prompting
// or validation checking occurs. Do it in a syncExec because
// we are calling this from a Job.
WorkbenchJob statusJob = new //$NON-NLS-1$
WorkbenchJob(//$NON-NLS-1$
"Status checking") {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus runInUIThread(IProgressMonitor monitor) {
return op.computeExecutionStatus(monitor);
}
};
statusJob.setSystem(true);
statusJob.schedule();
try {
// block until the status is ready
statusJob.join();
} catch (InterruptedException e) {
// Do nothing as status will be a cancel
}
if (statusJob.getResult().isOK()) {
return op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
}
return statusJob.getResult();
}
return PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(shellProvider.getShell()));
} catch (ExecutionException e) {
if (e.getCause() instanceof CoreException) {
return ((CoreException) e.getCause()).getStatus();
}
return new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, e.getMessage(), e);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
*/
public boolean belongsTo(Object family) {
if (IDEWorkbenchMessages.DeleteResourceAction_jobName.equals(family)) {
return true;
}
return super.belongsTo(family);
}
};
deleteJob.setUser(true);
deleteJob.schedule();
}
use of org.eclipse.ui.ide.undo.DeleteResourcesOperation in project tdi-studio-se by Talend.
the class ExportProjectsAsAction method clearExternalLibraries.
/**
* DOC zwang Comment method "clearExternalLibraries".
*/
private void clearExternalLibraries() {
List<IResource> resourcesToDelete = new ArrayList<IResource>();
IResource[] resourceArray = null;
try {
IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
// fix for bug 15454
Project[] projects = repositoryFactory.readProject(true);
for (Project project : projects) {
IProject fsProject = ResourceUtils.getProject(project);
IFolder libJavaFolder = fsProject.getFolder(ExportProjectsAsAction.LIB);
if (!libJavaFolder.exists()) {
continue;
}
// final DeleteResourcesOperation operation = new DeleteResourcesOperation(new IResource[] {
// libJavaFolder },
// IDEWorkbenchMessages.DeleteResourceAction_operationLabel, true);
final DeleteResourcesOperation operation = new DeleteResourcesOperation(new IResource[] { libJavaFolder }, Messages.getString("IDEWorkbenchMessages.DeleteResourceAction_operationLabel"), //$NON-NLS-1$
true);
PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(operation, null, WorkspaceUndoUtil.getUIInfoAdapter(window.getShell()));
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
Aggregations