(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / handlers / DeleteExperimentHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.ui.views.project.handlers;
14
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.IHandler;
18 import org.eclipse.core.commands.IHandlerListener;
19 import org.eclipse.core.resources.IFolder;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.StructuredSelection;
23 import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView;
24 import org.eclipse.linuxtools.lttng.ui.views.project.model.ILTTngProjectTreeNode;
25 import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngExperimentNode;
26 import org.eclipse.ui.IWorkbenchPage;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.PlatformUI;
29
30 /**
31 * <b><u>DeleteExperimentHandler</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35 public class DeleteExperimentHandler implements IHandler {
36
37 private LTTngExperimentNode fExperiment = null;
38
39 // ------------------------------------------------------------------------
40 // Validation
41 // ------------------------------------------------------------------------
42
43 public boolean isEnabled() {
44
45 // Check if we are closing down
46 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
47 if (window == null)
48 return false;
49
50 // Check if a trace is selected
51 IWorkbenchPage page = window.getActivePage();
52 if (!(page.getActivePart() instanceof ProjectView))
53 return false;
54
55 // Check if a trace is selected
56 ISelection selection = page.getSelection(ProjectView.ID);
57 if (selection instanceof StructuredSelection) {
58 Object element = ((StructuredSelection) selection).getFirstElement();
59 fExperiment = (element instanceof LTTngExperimentNode) ? (LTTngExperimentNode) element : null;
60 }
61
62 return (fExperiment != null);
63 }
64
65 // Handled if we are in the ProjectView
66 public boolean isHandled() {
67 return true;
68 }
69
70 // ------------------------------------------------------------------------
71 // Execution
72 // ------------------------------------------------------------------------
73
74 public Object execute(ExecutionEvent event) throws ExecutionException {
75
76 IFolder folder = fExperiment.getFolder();
77 ILTTngProjectTreeNode parent = fExperiment.getParent();
78 try {
79 parent.removeChild(fExperiment);
80 parent.refresh();
81 folder.delete(true, true, null);
82 } catch (CoreException e) {
83 e.printStackTrace();
84 }
85
86 return null;
87 }
88
89 public void dispose() {
90 // TODO Auto-generated method stub
91 }
92
93 // ------------------------------------------------------------------------
94 // IHandlerListener
95 // ------------------------------------------------------------------------
96
97 public void addHandlerListener(IHandlerListener handlerListener) {
98 // TODO Auto-generated method stub
99 }
100
101 public void removeHandlerListener(IHandlerListener handlerListener) {
102 // TODO Auto-generated method stub
103 }
104
105 }
This page took 0.032893 seconds and 5 git commands to generate.