1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2011 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
15 import java
.util
.Iterator
;
17 import org
.eclipse
.core
.commands
.AbstractHandler
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.core
.runtime
.CoreException
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.TreeSelection
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.widgets
.MessageBox
;
28 import org
.eclipse
.swt
.widgets
.Shell
;
29 import org
.eclipse
.ui
.IWorkbenchPage
;
30 import org
.eclipse
.ui
.IWorkbenchPart
;
31 import org
.eclipse
.ui
.IWorkbenchWindow
;
32 import org
.eclipse
.ui
.PlatformUI
;
35 * <b><u>DeleteExperimentHandler</u></b>
38 public class DeleteExperimentHandler
extends AbstractHandler
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
47 // Check if we are closing down
48 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
53 // Confirm the operation
54 Shell shell
= window
.getShell();
55 MessageBox confirmOperation
= new MessageBox(shell
, SWT
.ICON_QUESTION
| SWT
.CANCEL
| SWT
.OK
);
56 confirmOperation
.setText(Messages
.DeleteDialog_Title
);
57 confirmOperation
.setMessage(Messages
.DeleteExperimentHandler_Message
);
58 if (confirmOperation
.open() != SWT
.OK
) {
63 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
64 IWorkbenchPart part
= page
.getActivePart();
65 ISelection selection
= part
.getSite().getSelectionProvider().getSelection();
67 if (selection
instanceof TreeSelection
) {
68 TreeSelection sel
= (TreeSelection
) selection
;
69 Iterator
<Object
> iterator
= sel
.iterator();
70 while (iterator
.hasNext()) {
71 Object element
= iterator
.next();
72 if (element
instanceof TmfExperimentElement
) {
73 TmfExperimentElement experiment
= (TmfExperimentElement
) element
;
74 IResource resource
= experiment
.getResource();
76 resource
.delete(true, null);
77 experiment
.getProject().refresh();
78 } catch (CoreException e
) {
79 Activator
.getDefault().logError("Error deleting experiment: " + experiment
.getName(), e
); //$NON-NLS-1$