Commit | Line | Data |
---|---|---|
abfad0aa FC |
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.tmf.ui.views.project.handlers; | |
14 | ||
15 | import org.eclipse.core.commands.AbstractHandler; | |
16 | import org.eclipse.core.commands.ExecutionEvent; | |
17 | import org.eclipse.core.commands.ExecutionException; | |
18 | import org.eclipse.core.resources.IFolder; | |
19 | import org.eclipse.core.runtime.CoreException; | |
20 | import org.eclipse.jface.viewers.ISelection; | |
21 | import org.eclipse.jface.viewers.StructuredSelection; | |
22 | import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView; | |
23 | import org.eclipse.linuxtools.tmf.ui.views.project.model.ITmfProjectTreeNode; | |
24 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode; | |
25 | import org.eclipse.ui.IWorkbenchPage; | |
26 | import org.eclipse.ui.IWorkbenchWindow; | |
27 | import org.eclipse.ui.PlatformUI; | |
28 | ||
29 | /** | |
30 | * <b><u>DeleteExperimentHandler</u></b> | |
31 | * <p> | |
32 | * TODO: Implement me. Please. | |
33 | */ | |
34 | public class DeleteExperimentHandler extends AbstractHandler { | |
35 | ||
36 | private TmfExperimentNode fExperiment = null; | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Validation | |
40 | // ------------------------------------------------------------------------ | |
41 | ||
9ccc6d01 | 42 | @Override |
abfad0aa FC |
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 TmfExperimentNode) ? (TmfExperimentNode) element : null; | |
60 | } | |
61 | ||
62 | return (fExperiment != null); | |
63 | } | |
64 | ||
65 | // ------------------------------------------------------------------------ | |
66 | // Execution | |
67 | // ------------------------------------------------------------------------ | |
68 | ||
69 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
70 | ||
71 | IFolder folder = fExperiment.getFolder(); | |
72 | ITmfProjectTreeNode parent = fExperiment.getParent(); | |
73 | try { | |
74 | parent.removeChild(fExperiment); | |
75 | parent.refresh(); | |
76 | folder.delete(true, true, null); | |
77 | } catch (CoreException e) { | |
78 | e.printStackTrace(); | |
79 | } | |
80 | ||
81 | return null; | |
82 | } | |
83 | ||
84 | } |