Anytime a UI plug-in modifies resources, it should wrap the resource modification code by subclassing org.eclipse.ui.actions.WorkspaceModifyOperation. The primary consequence of using this operation is that events that typically occur as a result of workspace changes (e.g., the firing of resource deltas, performance of autobuilds, etc.) are deferred until the outermost operation has successfully completed. In the Favorites view, if you want to implement a delete operation that removed the resources themselves rather than just the Favorites items that referenced the resources, then it might be implemented as shown below.
package com.qualityeclipse.favorites.actions;
import ...
public class DeleteResourcesOperation
extends WorkspaceModifyOperation
{
private final IResource[] resources;
public DeleteResourcesOperation(IResource[] resources) {
this.resources = resources;
}
protected void execute(IProgressMonitor monitor)
throws
CoreException,
InvocationTargetException,
InterruptedException
{
monitor.beginTask("Deleting resources...", resources.length);
for (int i = 0; i < resources.length; i++) {
if (monitor.isCanceled())
break;
resources[i].delete(
true, new SubProgressMonitor(monitor, 1));
}
monitor.done();
}
}
protected void execute(IProgressMonitor monitor)
throws CoreException
{
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException
{
monitor.beginTask(
"Deleting resources...", resources.length);
for (int i = 0; i < resources.length; i++) {
resources[i].delete(
true, new SubProgressMonitor(monitor, 1));
}
monitor.done();
}
}, monitor);
}