1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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
.tmf
.ui
.views
.project
.handlers
;
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
.IResource
;
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
.TmfExperimentFolderNode
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfExperimentNode
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.project
.model
.TmfTraceNode
;
27 import org
.eclipse
.ui
.IWorkbenchPage
;
28 import org
.eclipse
.ui
.IWorkbenchWindow
;
29 import org
.eclipse
.ui
.PlatformUI
;
32 * <b><u>DeleteTraceHandler</u></b>
34 * TODO: Implement me. Please.
36 public class DeleteTraceHandler
extends AbstractHandler
{
38 private TmfTraceNode fTrace
= null;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 public boolean isEnabled() {
46 // Check if we are closing down
47 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
51 // Check if a trace is selected
52 IWorkbenchPage page
= window
.getActivePage();
53 if (!(page
.getActivePart() instanceof ProjectView
))
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 TmfTraceNode
) ?
(TmfTraceNode
) element
: null;
63 return (fTrace
!= null);
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
72 IResource resource
= fTrace
.getResource();
73 ITmfProjectTreeNode parent
= fTrace
.getParent();
75 if (!(parent
instanceof TmfExperimentNode
)) {
76 // Delete the trace from every experiment where it appears
77 TmfExperimentFolderNode experimentFolder
= fTrace
.getProject().getExperimentsFolder();
78 for (ITmfProjectTreeNode experiment
: experimentFolder
.getChildren()) {
79 for (int i
= 0; i
< experiment
.getChildren().size(); i
++) {
80 TmfTraceNode trace
= (TmfTraceNode
) experiment
.getChildren().get(i
);
81 if (trace
.getResource().getLocation().equals(resource
.getLocation())) {
82 experiment
.removeChild(trace
);
84 trace
.getResource().delete(true, null);
89 parent
.removeChild(fTrace
);
91 resource
.delete(true, null);
92 } catch (CoreException e
) {