</with>
</visibleWhen>
</command>
+ <command
+ commandId="org.eclipse.ui.edit.delete"
+ disabledIcon="icons/dtool16/delete.gif"
+ icon="icons/etool16/delete.gif"
+ label="%command.clear"
+ mnemonic="%command.clear.mnemonic"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="selection">
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="and">
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder">
+ </instanceof>
+ </iterate>
+ </with>
+ </visibleWhen>
+ </command>
<command
commandId="org.eclipse.ui.edit.delete"
disabledIcon="icons/dtool16/delete.gif"
</iterate>
</activeWhen>
</handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteFolderHandler"
+ commandId="org.eclipse.ui.edit.delete">
+ <activeWhen>
+ <and>
+ <count
+ value="1">
+ </count>
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder">
+ </instanceof>
+ </iterate>
+ </and>
+ </activeWhen>
+ </handler>
<handler
class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.NewFolderHandler"
commandId="org.eclipse.linuxtools.tmf.ui.command.new_folder">
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
return null;
}
+ // Get the selection
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (!(selection instanceof IStructuredSelection)) {
+ return null;
+ }
+ final boolean isTracesFolder = ((IStructuredSelection) selection).iterator().next() instanceof TmfTracesFolder;
+
// Confirm the operation
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);
+ confirmOperation.setText(isTracesFolder ? Messages.ClearDialog_Title : Messages.DeleteDialog_Title);
+ confirmOperation.setMessage(isTracesFolder ? Messages.DeleteFolderHandlerClear_Message : Messages.DeleteFolderHandler_Message);
if (confirmOperation.open() != SWT.OK) {
return null;
}
- // Get the selection
- 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 {
+ public void execute(final IProgressMonitor monitor) throws CoreException {
monitor.beginTask("", 1000); //$NON-NLS-1$
while (iterator.hasNext()) {
if (monitor.isCanceled()) {
Object element = iterator.next();
if (element instanceof TmfTraceFolder) {
final TmfTraceFolder folder = (TmfTraceFolder) element;
- IResource resource = folder.getResource();
+ final IResource resource = folder.getResource();
try {
// delete all traces under this folder
traceElement.delete(null);
}
- // Finally, delete the folder
- resource.delete(true, monitor);
+ // Finally, delete the folder. For the Traces
+ // folder, we only delete the children since the
+ // folder should always be there.
+ if (folder instanceof TmfTracesFolder) {
+ resource.accept(new IResourceVisitor() {
+ @Override
+ public boolean visit(IResource visitedResource) throws CoreException {
+ if (visitedResource != resource) {
+ visitedResource.delete(true, monitor);
+ }
+ return true;
+ }
+ }, IResource.DEPTH_ONE, 0);
+ } else {
+ 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.setText(isTracesFolder ? Messages.DeleteFolderHandlerClear_Error : Messages.DeleteFolderHandler_Error + ' ' + folder.getName());
mb.setMessage(e.getMessage());
mb.open();
}