1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Close editors to release resources
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
16 import java
.util
.Iterator
;
18 import org
.eclipse
.core
.commands
.AbstractHandler
;
19 import org
.eclipse
.core
.commands
.ExecutionEvent
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.core
.resources
.IResource
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.core
.runtime
.IPath
;
24 import org
.eclipse
.jface
.viewers
.ISelection
;
25 import org
.eclipse
.jface
.viewers
.TreeSelection
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.widgets
.Display
;
30 import org
.eclipse
.swt
.widgets
.MessageBox
;
31 import org
.eclipse
.swt
.widgets
.Shell
;
32 import org
.eclipse
.ui
.IWorkbenchPage
;
33 import org
.eclipse
.ui
.IWorkbenchPart
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
35 import org
.eclipse
.ui
.PlatformUI
;
38 * <b><u>DeleteExperimentHandler</u></b>
41 public class DeleteExperimentHandler
extends AbstractHandler
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
48 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
50 // Check if we are closing down
51 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
56 // Confirm the operation
57 Shell shell
= window
.getShell();
58 MessageBox confirmOperation
= new MessageBox(shell
, SWT
.ICON_QUESTION
| SWT
.CANCEL
| SWT
.OK
);
59 confirmOperation
.setText(Messages
.DeleteDialog_Title
);
60 confirmOperation
.setMessage(Messages
.DeleteExperimentHandler_Message
);
61 if (confirmOperation
.open() != SWT
.OK
) {
66 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
67 IWorkbenchPart part
= page
.getActivePart();
71 ISelection selection
= part
.getSite().getSelectionProvider().getSelection();
73 if (selection
instanceof TreeSelection
) {
74 TreeSelection sel
= (TreeSelection
) selection
;
75 Iterator
<Object
> iterator
= sel
.iterator();
76 while (iterator
.hasNext()) {
77 Object element
= iterator
.next();
78 if (element
instanceof TmfExperimentElement
) {
79 final TmfExperimentElement experiment
= (TmfExperimentElement
) element
;
80 IResource resource
= experiment
.getResource();
83 // Close the experiment if open
84 experiment
.closeEditors();
86 IPath path
= resource
.getLocation();
88 // Delete supplementary files
89 experiment
.deleteSupplementaryFolder();
92 // Finally, delete the experiment
93 resource
.delete(true, null);
95 } catch (final CoreException e
) {
96 Display
.getDefault().asyncExec(new Runnable() {
99 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
100 mb
.setText(Messages
.DeleteTraceHandler_Error
+ ' ' + experiment
.getName());
101 mb
.setMessage(e
.getMessage());
105 Activator
.getDefault().logError("Error deleting experiment: " + experiment
.getName(), e
); //$NON-NLS-1$