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 / DeleteTraceHandler.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.LTTngTraceNode;
26 import org.eclipse.ui.IWorkbenchPage;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.PlatformUI;
29
30 /**
31 * <b><u>DeleteTraceHandler</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35 public class DeleteTraceHandler implements IHandler {
36
37 private LTTngTraceNode fTrace = null;
38
39 // ------------------------------------------------------------------------
40 // Validation
41 // ------------------------------------------------------------------------
42
43 @Override
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 fTrace = (element instanceof LTTngTraceNode) ? (LTTngTraceNode) element : null;
61 }
62
63 return (fTrace != null);
64 }
65
66 // Handled if we are in the ProjectView
67 @Override
68 public boolean isHandled() {
69 return true;
70 }
71
72 // ------------------------------------------------------------------------
73 // Execution
74 // ------------------------------------------------------------------------
75
76 @Override
77 public Object execute(ExecutionEvent event) throws ExecutionException {
78
79 IFolder folder = fTrace.getFolder();
80 ILTTngProjectTreeNode parent = fTrace.getParent();
81 try {
82 parent.removeChild(fTrace);
83 parent.refresh();
84 folder.delete(true, true, null);
85 } catch (CoreException e) {
86 e.printStackTrace();
87 }
88
89 return null;
90 }
91
92 @Override
93 public void dispose() {
94 // TODO Auto-generated method stub
95 }
96
97 // ------------------------------------------------------------------------
98 // IHandlerListener
99 // ------------------------------------------------------------------------
100
101 @Override
102 public void addHandlerListener(IHandlerListener handlerListener) {
103 // TODO Auto-generated method stub
104 }
105
106 @Override
107 public void removeHandlerListener(IHandlerListener handlerListener) {
108 // TODO Auto-generated method stub
109 }
110
111 }
This page took 0.03354 seconds and 5 git commands to generate.