tmf: Support for selecting both traces and folders when deleting
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Wed, 23 Jul 2014 13:50:15 +0000 (09:50 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Fri, 25 Jul 2014 16:41:14 +0000 (12:41 -0400)
Change-Id: Iace8f35b4e85749244291a575040fc82a901ff23
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/30392
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.tmf.ui/plugin.xml
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteFolderHandler.java [deleted file]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceFolderElementHandler.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java [deleted file]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/Messages.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/messages.properties

index feb03a9694582525977bb6ab3c18c81ba3f561e6..78032a090e6c056ad0a0980c51f97dc4694fa012 100644 (file)
                   checkEnabled="false">
                <with
                      variable="selection">
-                  <or>
-                     <iterate
-                           ifEmpty="false"
-                           operator="and">
-                        <and>
+                  <and>
+                     <or>
+                        <iterate
+                              ifEmpty="false"
+                              operator="and">
                            <instanceof
-                                 value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+                                 value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
                            </instanceof>
-                           <not>
-                              <test
-                                    forcePluginActivation="true"
-                                    property="org.eclipse.linuxtools.tmf.ui.isExperimentTrace">
-                              </test>
-                           </not>
-                        </and>
-                     </iterate>
-                     <iterate
-                           ifEmpty="false"
-                           operator="and">
-                        <instanceof
-                              value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
-                        </instanceof>
-                     </iterate>
-                     <iterate
-                           ifEmpty="false"
-                           operator="and">
-                        <and>
-                           <not>
+                        </iterate>
+                        <iterate
+                              ifEmpty="false"
+                              operator="and">
+                           <or>
+                              <instanceof
+                                    value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+                              </instanceof>
+                              <and>
+                                 <instanceof
+                                       value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+                                 </instanceof>
+                                 <not>
+                                    <test
+                                          forcePluginActivation="true"
+                                          property="org.eclipse.linuxtools.tmf.ui.isExperimentTrace">
+                                    </test>
+                                 </not>
+                              </and>
+                           </or>
+                        </iterate>
+                     </or>
+                     <not>
+                        <with
+                              variable="selection">
+                           <iterate
+                                 ifEmpty="false"
+                                 operator="and">
                               <instanceof
                                     value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder">
                               </instanceof>
-                           </not>
-                           <instanceof
-                                 value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
-                           </instanceof>
-                        </and>
-                     </iterate>
-                  </or>
+                           </iterate>
+                        </with>
+                     </not>
+                  </and>
                </with>
             </visibleWhen>
          </command>
                   checkEnabled="false">
                <with
                      variable="selection">
-                  <count
-                        value="1">
-                  </count>
                   <iterate
                         ifEmpty="false"
                         operator="and">
             </and>
          </activeWhen>
       </handler>
-      <handler
-            class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceHandler"
-            commandId="org.eclipse.ui.edit.delete">
-         <activeWhen>
-            <iterate
-                  ifEmpty="false"
-                  operator="and">
-               <instanceof
-                     value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
-               </instanceof>
-            </iterate>
-         </activeWhen>
-      </handler>
       <handler
             class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteExperimentHandler"
             commandId="org.eclipse.ui.edit.delete">
          </activeWhen>
       </handler>
       <handler
-            class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteFolderHandler"
+            class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceFolderElementHandler"
             commandId="org.eclipse.ui.edit.delete">
          <activeWhen>
             <iterate
                   ifEmpty="false"
                   operator="and">
-               <not>
+               <or>
                   <instanceof
-                        value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder">
+                        value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
                   </instanceof>
-               </not>
-               <instanceof
-                     value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
-               </instanceof>
+                  <instanceof
+                        value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder">
+                  </instanceof>
+               </or>
             </iterate>
          </activeWhen>
       </handler>
       <handler
-            class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteFolderHandler"
+            class="org.eclipse.linuxtools.internal.tmf.ui.project.handlers.DeleteTraceFolderElementHandler"
             commandId="org.eclipse.ui.edit.delete">
          <activeWhen>
             <and>
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteFolderHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteFolderHandler.java
deleted file mode 100644 (file)
index f512aba..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Patrick Tasse - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Iterator;
-
-import org.eclipse.core.commands.AbstractHandler;
-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.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-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;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.actions.WorkspaceModifyOperation;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * Handler for the Delete Folder command.
- */
-public class DeleteFolderHandler extends AbstractHandler {
-
-    // ------------------------------------------------------------------------
-    // Execution
-    // ------------------------------------------------------------------------
-
-    @Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
-
-        // Check if we are closing down
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null) {
-            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(isTracesFolder ? Messages.ClearDialog_Title : Messages.DeleteDialog_Title);
-        confirmOperation.setMessage(isTracesFolder ? Messages.DeleteFolderHandlerClear_Message : Messages.DeleteFolderHandler_Message);
-        if (confirmOperation.open() != SWT.OK) {
-            return null;
-        }
-
-        final Iterator<Object> iterator = ((IStructuredSelection) selection).iterator();
-
-        WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
-            @Override
-            public void execute(final IProgressMonitor monitor) throws CoreException {
-                monitor.beginTask("", 1000); //$NON-NLS-1$
-                while (iterator.hasNext()) {
-                    if (monitor.isCanceled()) {
-                        throw new OperationCanceledException();
-                    }
-                    Object element = iterator.next();
-                    if (element instanceof TmfTraceFolder) {
-                        final TmfTraceFolder folder = (TmfTraceFolder) element;
-                        final IResource resource = folder.getResource();
-
-                        try {
-                            // delete all traces under this folder
-                            for (TmfTraceElement traceElement : folder.getTraces()) {
-                                traceElement.delete(null);
-                            }
-
-                            // 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(isTracesFolder ? Messages.DeleteFolderHandlerClear_Error : Messages.DeleteFolderHandler_Error + ' ' + folder.getName());
-                                    mb.setMessage(e.getMessage());
-                                    mb.open();
-                                }
-                            });
-                            Activator.getDefault().logError("Error deleting folder: " + folder.getName(), e); //$NON-NLS-1$
-                        }
-                    }
-                }
-            }
-        };
-
-        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;
-    }
-
-}
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceFolderElementHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceFolderElementHandler.java
new file mode 100644 (file)
index 0000000..f9742ee
--- /dev/null
@@ -0,0 +1,390 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Francois Chouinard - Initial API and implementation
+ *   Patrick Tasse - Close editors to release resources
+ *   Geneviève Bastien - Moved the delete code to element model's classes
+ *   Marc-Andre Laperle - Merged DeleteTraceHandler and DeleteFolderHandler
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+
+import org.eclipse.core.commands.AbstractHandler;
+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.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
+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;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * An handler for deletion of both traces and trace folders. It allows mixing
+ * both types of elements.
+ */
+public class DeleteTraceFolderElementHandler extends AbstractHandler {
+
+    private TreeSelection fSelection = null;
+
+    private enum DeleteType {
+        /**
+         * Only trace folders are selected.
+         */
+        DELETE_TRACE_FOLDERS,
+        /**
+         * Only traces are selected.
+         */
+        DELETE_TRACES,
+        /**
+         * A mix of different elements are selected.
+         */
+        DELETE_GENERIC,
+        /**
+         * Only Traces (top trace folders) are selected.
+         */
+        CLEAR_TRACES_FOLDER,
+        /**
+         * Only Traces under experiments are selected.
+         */
+        REMOVE_TRACES_FROM_EXPERIMENT
+    }
+
+    // ------------------------------------------------------------------------
+    // Validation
+    // ------------------------------------------------------------------------
+
+    @Override
+    public boolean isEnabled() {
+
+        // Check if we are closing down
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        if (window == null) {
+            return false;
+        }
+
+        // Get the selection
+        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+        IWorkbenchPart part = page.getActivePart();
+        if (part == null) {
+            return false;
+        }
+        ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
+        if (selectionProvider == null) {
+            return false;
+        }
+        ISelection selection = selectionProvider.getSelection();
+
+        // Make sure selection contains only traces and trace folders
+        fSelection = null;
+        if (selection instanceof TreeSelection) {
+            fSelection = (TreeSelection) selection;
+            Iterator<Object> iterator = fSelection.iterator();
+            while (iterator.hasNext()) {
+                Object element = iterator.next();
+                if (!(element instanceof TmfTraceElement) && !(element instanceof TmfTraceFolder)) {
+                    return false;
+                }
+            }
+        }
+
+        // If we get here, either nothing is selected or everything is a trace or folder
+        return !selection.isEmpty();
+    }
+
+    // ------------------------------------------------------------------------
+    // Execution
+    // ------------------------------------------------------------------------
+
+    private static DeleteType getDeleteType(ISelection selection) {
+        int numTracesFolder = 0;
+        int numTraceFolder = 0;
+        int numTraces = 0;
+        int numTracesUnderExperiment = 0;
+
+        @SuppressWarnings("rawtypes")
+        Iterator iterator = ((IStructuredSelection) selection).iterator();
+        while (iterator.hasNext()) {
+            Object next = iterator.next();
+            if ((next instanceof TmfTracesFolder)) {
+                numTracesFolder++;
+            } else if (next instanceof TmfTraceFolder) {
+                numTraceFolder++;
+            } else if (next instanceof TmfTraceElement) {
+                TmfTraceElement traceElement = (TmfTraceElement) next;
+                if (traceElement.getParent() instanceof TmfExperimentElement) {
+                    numTracesUnderExperiment++;
+                } else {
+                    numTraces++;
+                }
+            }
+        }
+
+        int total = numTraceFolder + numTracesFolder + numTracesUnderExperiment + numTraces;
+
+        if (numTracesFolder == total) {
+            return DeleteType.CLEAR_TRACES_FOLDER;
+        }
+
+        if (numTraceFolder == total) {
+            return DeleteType.DELETE_TRACE_FOLDERS;
+        }
+
+        if (numTraces == total) {
+            return DeleteType.DELETE_TRACES;
+        }
+
+        if (numTracesUnderExperiment == total) {
+            return DeleteType.REMOVE_TRACES_FROM_EXPERIMENT;
+        }
+
+        return DeleteType.DELETE_GENERIC;
+    }
+
+    private static String getTitle(final DeleteType deleteType) {
+        switch (deleteType)
+        {
+        case DELETE_GENERIC:
+        case DELETE_TRACES:
+        case DELETE_TRACE_FOLDERS:
+            return Messages.DeleteDialog_Title;
+        case CLEAR_TRACES_FOLDER:
+            return Messages.ClearDialog_Title;
+        case REMOVE_TRACES_FROM_EXPERIMENT:
+            return Messages.RemoveDialog_Title;
+        default:
+            throw new IllegalArgumentException();
+        }
+    }
+
+    private static String getMessage(DeleteType deleteType) {
+        switch (deleteType)
+        {
+        case DELETE_GENERIC:
+            return Messages.DeleteTraceHandlerGeneric_Message;
+        case DELETE_TRACES:
+            return Messages.DeleteTraceHandler_Message;
+        case CLEAR_TRACES_FOLDER:
+            return Messages.DeleteFolderHandlerClear_Message;
+        case DELETE_TRACE_FOLDERS:
+            return Messages.DeleteFolderHandler_Message;
+        case REMOVE_TRACES_FROM_EXPERIMENT:
+            return Messages.RemoveTraceFromExperimentHandler_Message;
+        default:
+            throw new IllegalArgumentException();
+        }
+    }
+
+    private static String getTraceErrorMessage(DeleteType deleteType) {
+        return deleteType == DeleteType.REMOVE_TRACES_FROM_EXPERIMENT ? Messages.RemoveTraceFromExperimentHandler_Error : Messages.DeleteFolderHandler_Error;
+    }
+
+    private static String getFolderErrorMessage(DeleteType deleteType) {
+        return deleteType == DeleteType.CLEAR_TRACES_FOLDER ? Messages.DeleteFolderHandlerClear_Error : Messages.DeleteFolderHandler_Error;
+    }
+
+    private static String getTraceTaskName(DeleteType deleteType) {
+        return deleteType == DeleteType.REMOVE_TRACES_FROM_EXPERIMENT ? Messages.RemoveTraceFromExperimentHandler_TaskName : Messages.DeleteFolderHandler_TaskName;
+    }
+
+    private static String getTraceFolderTaskName(DeleteType deleteType) {
+        return deleteType == DeleteType.CLEAR_TRACES_FOLDER ? Messages.DeleteFolderHandlerClear_TaskName : Messages.DeleteFolderHandler_TaskName;
+    }
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+        // Check if we are closing down
+        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+        if (window == null) {
+            return null;
+        }
+
+        // Get the selection
+        ISelection selection = HandlerUtil.getCurrentSelection(event);
+        if (!(selection instanceof IStructuredSelection)) {
+            return null;
+        }
+        final DeleteType deleteType = getDeleteType(selection);
+
+        // Confirm the operation
+        Shell shell = window.getShell();
+        MessageBox confirmOperation = new MessageBox(shell, SWT.ICON_QUESTION | SWT.CANCEL | SWT.OK);
+        confirmOperation.setText(getTitle(deleteType));
+        confirmOperation.setMessage(getMessage(deleteType));
+        if (confirmOperation.open() != SWT.OK) {
+            return null;
+        }
+
+        final Iterator<Object> iterator = fSelection.iterator();
+        final int nbElements = fSelection.size();
+
+        DeleteOperation operation = new DeleteOperation() {
+            @Override
+            public void execute(IProgressMonitor monitor) throws CoreException {
+                SubMonitor subMonitor = SubMonitor.convert(monitor, nbElements);
+
+                while (iterator.hasNext()) {
+                    if (monitor.isCanceled()) {
+                        throw new OperationCanceledException();
+                    }
+                    Object element = iterator.next();
+                    SubProgressMonitor elementSubMonitor = new SubProgressMonitor(subMonitor, 1);
+                    if (element instanceof TmfTraceElement) {
+                        final TmfTraceElement trace = (TmfTraceElement) element;
+                        if (!trace.getResource().exists()) {
+                            continue;
+                        }
+                        subMonitor.setTaskName(getTraceTaskName(deleteType) + " " + trace.getElementPath()); //$NON-NLS-1$
+                        try {
+                            SubMonitor deleteSubMonitor = SubMonitor.convert(elementSubMonitor, 1);
+                            trace.delete(deleteSubMonitor);
+                        } catch (final CoreException e) {
+                            Display.getDefault().asyncExec(new Runnable() {
+                                @Override
+                                public void run() {
+                                    final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+                                    mb.setText(getTraceErrorMessage(deleteType) + ' ' + trace.getName());
+                                    mb.setMessage(e.getMessage());
+                                    mb.open();
+                                }
+                            });
+                            Activator.getDefault().logError(getTraceErrorMessage(deleteType) + trace.getName(), e);
+                        }
+                    } else if (element instanceof TmfTraceFolder) {
+                        final TmfTraceFolder folder = (TmfTraceFolder) element;
+                        final IResource resource = folder.getResource();
+                        if (!resource.exists()) {
+                            continue;
+                        }
+
+                        subMonitor.setTaskName(getTraceFolderTaskName(deleteType) + " " + folder.getPath()); //$NON-NLS-1$
+
+                        try {
+                            // delete all traces under this folder
+                            SubMonitor childrenSubMonitor = SubMonitor.convert(elementSubMonitor, folder.getTraces().size() + 1);
+                            for (TmfTraceElement traceElement : folder.getTraces()) {
+                                SubProgressMonitor deleteSubMonitor = new SubProgressMonitor(childrenSubMonitor, 1);
+                                traceElement.delete(deleteSubMonitor);
+                            }
+
+                            // Finally, delete the folder. For the Traces
+                            // folder, we only delete the children since the
+                            // folder should always be there.
+                            final SubProgressMonitor deleteSubMonitor = new SubProgressMonitor(subMonitor, 1);
+                            if (folder instanceof TmfTracesFolder) {
+                                resource.accept(new IResourceVisitor() {
+                                    @Override
+                                    public boolean visit(IResource visitedResource) throws CoreException {
+                                        if (visitedResource != resource) {
+                                            visitedResource.delete(true, deleteSubMonitor);
+                                        }
+                                        return true;
+                                    }
+                                }, IResource.DEPTH_ONE, 0);
+                            } else {
+                                resource.delete(true, deleteSubMonitor);
+                            }
+                            childrenSubMonitor.done();
+                        } catch (final CoreException e) {
+                            Display.getDefault().asyncExec(new Runnable() {
+                                @Override
+                                public void run() {
+                                    final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+                                    mb.setText(getFolderErrorMessage(deleteType) + ' ' + folder.getName());
+                                    mb.setMessage(e.getMessage());
+                                    mb.open();
+                                }
+                            });
+                            Activator.getDefault().logError(getFolderErrorMessage(deleteType) + folder.getName(), e);
+                        }
+                    }
+                    subMonitor.setTaskName(""); //$NON-NLS-1$
+                    elementSubMonitor.done();
+                }
+           }
+        };
+
+        try {
+            PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
+        } catch (InterruptedException e) {
+            return null;
+        } catch (InvocationTargetException e) {
+            MessageDialog.openError(window.getShell(), e.toString(), e.getTargetException().toString());
+            return null;
+        }
+        return null;
+    }
+
+    private abstract class DeleteOperation implements IRunnableWithProgress {
+        @Override
+        public synchronized final void run(IProgressMonitor monitor)
+                throws InvocationTargetException, InterruptedException {
+            final InvocationTargetException[] iteHolder = new InvocationTargetException[1];
+            try {
+                IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
+                    @Override
+                    public void run(IProgressMonitor pm) throws CoreException {
+                        try {
+                            execute(pm);
+                        } catch (InvocationTargetException e) {
+                            // Pass it outside the workspace runnable
+                            iteHolder[0] = e;
+                        } catch (InterruptedException e) {
+                            // Re-throw as OperationCanceledException, which will be
+                            // caught and re-thrown as InterruptedException below.
+                            throw new OperationCanceledException(e.getMessage());
+                        }
+                        // CoreException and OperationCanceledException are propagated
+                    }
+                };
+
+                IWorkspace workspace = ResourcesPlugin.getWorkspace();
+                workspace.run(workspaceRunnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
+            } catch (CoreException e) {
+                throw new InvocationTargetException(e);
+            } catch (OperationCanceledException e) {
+                throw new InterruptedException(e.getMessage());
+            }
+            // Re-throw the InvocationTargetException, if any occurred
+            if (iteHolder[0] != null) {
+                throw iteHolder[0];
+            }
+        }
+
+        protected abstract void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException;
+    }
+}
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java
deleted file mode 100644 (file)
index 2e5c52c..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Francois Chouinard - Initial API and implementation
- *   Patrick Tasse - Close editors to release resources
- *   Geneviève Bastien - Moved the delete code to element model's classes
- *******************************************************************************/
-
-package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Iterator;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.linuxtools.internal.tmf.ui.Activator;
-import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.MessageBox;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * <b><u>DeleteTraceHandler</u></b>
- * <p>
- */
-public class DeleteTraceHandler extends AbstractHandler {
-
-    private TreeSelection fSelection = null;
-
-    // ------------------------------------------------------------------------
-    // Validation
-    // ------------------------------------------------------------------------
-
-    @Override
-    public boolean isEnabled() {
-
-        // Check if we are closing down
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null) {
-            return false;
-        }
-
-        // Get the selection
-        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-        IWorkbenchPart part = page.getActivePart();
-        if (part == null) {
-            return false;
-        }
-        ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
-        if (selectionProvider == null) {
-            return false;
-        }
-        ISelection selection = selectionProvider.getSelection();
-
-        // Make sure selection contains only traces
-        fSelection = null;
-        if (selection instanceof TreeSelection) {
-            fSelection = (TreeSelection) selection;
-            Iterator<Object> iterator = fSelection.iterator();
-            while (iterator.hasNext()) {
-                Object element = iterator.next();
-                if (!(element instanceof TmfTraceElement)) {
-                    return false;
-                }
-            }
-        }
-
-        // If we get here, either nothing is selected or everything is a trace
-        return !selection.isEmpty();
-    }
-
-    // ------------------------------------------------------------------------
-    // Execution
-    // ------------------------------------------------------------------------
-
-    @Override
-    public Object execute(ExecutionEvent event) throws ExecutionException {
-
-        // Check if we are closing down
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        if (window == null) {
-            return null;
-        }
-
-        // 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.DeleteTraceHandler_Message);
-        if (confirmOperation.open() != SWT.OK) {
-            return null;
-        }
-
-        final Iterator<Object> iterator = fSelection.iterator();
-        final int nbTraces = fSelection.size();
-
-        SelectTraceOperation operation = new SelectTraceOperation() {
-            @Override
-            public void execute(IProgressMonitor monitor) throws CoreException {
-                SubMonitor subMonitor = SubMonitor.convert(monitor, nbTraces);
-
-                while (iterator.hasNext()) {
-                    if (monitor.isCanceled()) {
-                        throw new OperationCanceledException();
-                    }
-                    Object element = iterator.next();
-                    if (element instanceof TmfTraceElement) {
-                        final TmfTraceElement trace = (TmfTraceElement) element;
-                        subMonitor.setTaskName(Messages.DeleteTraceHandler_TaskName + " " + trace.getElementPath()); //$NON-NLS-1$
-                        try {
-                            trace.delete(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.DeleteTraceHandler_Error + ' ' + trace.getName());
-                                    mb.setMessage(e.getMessage());
-                                    mb.open();
-                                }
-                            });
-                            Activator.getDefault().logError("Error deleting trace: " + trace.getName(), e); //$NON-NLS-1$
-                        }
-                    }
-                    subMonitor.setTaskName(""); //$NON-NLS-1$
-                    subMonitor.worked(1);
-                }
-           }
-        };
-
-        try {
-            PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
-        } catch (InterruptedException e) {
-            return null;
-        } catch (InvocationTargetException e) {
-            MessageDialog.openError(window.getShell(), e.toString(), e.getTargetException().toString());
-            return null;
-        }
-        return null;
-    }
-
-    private abstract class SelectTraceOperation implements IRunnableWithProgress {
-        @Override
-        public synchronized final void run(IProgressMonitor monitor)
-                throws InvocationTargetException, InterruptedException {
-            final InvocationTargetException[] iteHolder = new InvocationTargetException[1];
-            try {
-                IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
-                    @Override
-                    public void run(IProgressMonitor pm) throws CoreException {
-                        try {
-                            execute(pm);
-                        } catch (InvocationTargetException e) {
-                            // Pass it outside the workspace runnable
-                            iteHolder[0] = e;
-                        } catch (InterruptedException e) {
-                            // Re-throw as OperationCanceledException, which will be
-                            // caught and re-thrown as InterruptedException below.
-                            throw new OperationCanceledException(e.getMessage());
-                        }
-                        // CoreException and OperationCanceledException are propagated
-                    }
-                };
-
-                IWorkspace workspace = ResourcesPlugin.getWorkspace();
-                workspace.run(workspaceRunnable, workspace.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
-            } catch (CoreException e) {
-                throw new InvocationTargetException(e);
-            } catch (OperationCanceledException e) {
-                throw new InterruptedException(e.getMessage());
-            }
-            // Re-throw the InvocationTargetException, if any occurred
-            if (iteHolder[0] != null) {
-                throw iteHolder[0];
-            }
-        }
-
-        protected abstract void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException;
-    }
-}
\ No newline at end of file
index 040ac2d7dc1a1faec4bfdc05e32424650f3bf2e7..2de6e18e4ceedeba0f6df9150438fe336ca4b849 100644 (file)
@@ -30,14 +30,22 @@ public class Messages extends NLS {
     public static String DeleteTraceHandler_Message;
     public static String DeleteTraceHandler_Error;
     public static String DeleteTraceHandler_TaskName;
+    public static String DeleteTraceHandlerGeneric_Message;
+    public static String DeleteTraceHandlerGeneric_Error;
     public static String DeleteExperimentHandler_Message;
     public static String DeleteExperimentHandler_Error;
     public static String DeleteFolderHandler_Message;
     public static String DeleteFolderHandler_Error;
+    public static String DeleteFolderHandler_TaskName;
 
+    public static String RemoveDialog_Title;
+    public static String RemoveTraceFromExperimentHandler_Message;
+    public static String RemoveTraceFromExperimentHandler_TaskName;
+    public static String RemoveTraceFromExperimentHandler_Error;
     public static String ClearDialog_Title;
     public static String DeleteFolderHandlerClear_Message;
     public static String DeleteFolderHandlerClear_Error;
+    public static String DeleteFolderHandlerClear_TaskName;
 
     public static String SelectTraceTypeHandler_ErrorSelectingTrace;
     public static String SelectTraceTypeHandler_Title;
index 7071a19c0c4491a4be4d3d693e4387871ce0776d..e2e5635dd8831027d9b38baffc0f0943020ed012 100644 (file)
 
 # Delete message
 DeleteDialog_Title = Confirm Delete
-DeleteTraceHandler_Message = Are you sure you want to delete this trace?
+DeleteTraceHandler_Message = Are you sure you want to delete the selected trace(s)?
 DeleteTraceHandler_Error = Error deleting trace
-DeleteTraceHandler_TaskName = Removing trace
+DeleteTraceHandler_TaskName = Deleting trace
+RemoveDialog_Title = Confirm Remove
+RemoveTraceFromExperimentHandler_Message = Are you sure you want to remove the selected trace(s)?
+RemoveTraceFromExperimentHandler_TaskName = Removing trace
+RemoveTraceFromExperimentHandler_Error = Error removing trace
 DeleteExperimentHandler_Message = Are you sure you want to delete this experiment?
 DeleteExperimentHandler_Error = Error deleting experiment
-DeleteFolderHandler_Message = Are you sure you want to delete this folder?
+DeleteFolderHandler_Message = Are you sure you want to delete the selected folder(s)?
 DeleteFolderHandler_Error = Error deleting folder
+DeleteFolderHandler_TaskName = Deleting folder
+DeleteTraceHandlerGeneric_Message = Are you sure you want to delete the selected elements?
+DeleteTraceHandlerGeneric_Error= Error deleting elements
 
 # Clear message
 ClearDialog_Title = Confirm Clear
-DeleteFolderHandlerClear_Message = Are you sure you want to clear this folder?
+DeleteFolderHandlerClear_TaskName = Clearing folder
+DeleteFolderHandlerClear_Message = Are you sure you want to clear the selected folder(s)?
 DeleteFolderHandlerClear_Error = Error clearing folder
 
 # Set Trace Type
This page took 0.03654 seconds and 5 git commands to generate.