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