Source:
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; } Shell shell = window.getShell(); MessageBox confirmOperation = new MessageBox(shell, SWT.ICON_QUESTION | SWT.CANCEL | SWT.OK); confirmOperation.setText(Messages.DeleteDialog_Title); confirmOperation.setMessage(Messages.DeleteFolderHandler_Message); if (confirmOperation.open() != SWT.OK) { return null; } IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); if (part == null) { return Boolean.FALSE; } ISelection selection = part.getSite().getSelectionProvider().getSelection(); if (selection instanceof TreeSelection) { TreeSelection sel = (TreeSelection) selection; Iterator<Object> iterator = sel.iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof TmfTraceFolder) { final TmfTraceFolder folder = (TmfTraceFolder) element; IResource resource = folder.getResource(); try { for (TmfTraceElement traceElement : folder.getTraces()) { traceElement.delete(null); } resource.delete(true, null); } catch (final CoreException e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); mb.setText(Messages.DeleteFolderHandler_Error + ' ' + folder.getName()); mb.setMessage(e.getMessage()); mb.open(); } }); Activator.getDefault().logError("Error deleting folder: " + folder.getName(), e); } } } } return null; }

Target:
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return null; } Shell shell = window.getShell(); MessageBox confirmOperation = new MessageBox(shell, SWT.ICON_QUESTION | SWT.CANCEL | SWT.OK); confirmOperation.setText(Messages.DeleteDialog_Title); confirmOperation.setMessage(Messages.DeleteFolderHandler_Message); if (confirmOperation.open() != SWT.OK) { return null; } ISelection selection = HandlerUtil.getCurrentSelection(event); if (!(selection instanceof IStructuredSelection)) { return null; } final Iterator<Object> iterator = ((IStructuredSelection) selection).iterator(); WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override public void execute(IProgressMonitor monitor) throws CoreException { monitor.beginTask("", 1000); while (iterator.hasNext()) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } Object element = iterator.next(); if (element instanceof TmfTraceFolder) { final TmfTraceFolder folder = (TmfTraceFolder) element; IResource resource = folder.getResource(); try { for (TmfTraceElement traceElement : folder.getTraces()) { traceElement.delete(null); } resource.delete(true, monitor); } catch (final CoreException e) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); mb.setText(Messages.DeleteFolderHandler_Error + ' ' + folder.getName()); mb.setMessage(e.getMessage()); mb.open(); } }); Activator.getDefault().logError("Error deleting folder: " + folder.getName(), e); } } } } }; try { PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation); } catch (InterruptedException e) { return null; } catch (InvocationTargetException e) { MessageDialog.openError(window.getShell(), e.toString(), e.getTargetException().toString()); return null; } return null; }