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 // ------------------------------------------------------------------------
45 public boolean isEnabled() {
47 // Check if we are closing down
48 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
52 // Check if a trace is selected
53 IWorkbenchPage page
= window
.getActivePage();
54 if (!(page
.getActivePart() instanceof ProjectView
))
57 // Check if a trace is selected
58 ISelection selection
= page
.getSelection(ProjectView
.ID
);
59 if (selection
instanceof StructuredSelection
) {
60 Object element
= ((StructuredSelection
) selection
).getFirstElement();
61 fTrace
= (element
instanceof TmfTraceNode
) ?
(TmfTraceNode
) element
: null;
64 return (fTrace
!= null);
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
71 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 IResource resource
= fTrace
.getResource();
74 ITmfProjectTreeNode parent
= fTrace
.getParent();
76 if (!(parent
instanceof TmfExperimentNode
)) {
77 // Delete the trace from every experiment where it appears
78 TmfExperimentFolderNode experimentFolder
= fTrace
.getProject().getExperimentsFolder();
79 for (ITmfProjectTreeNode experiment
: experimentFolder
.getChildren()) {
80 for (int i
= 0; i
< experiment
.getChildren().size(); i
++) {
81 TmfTraceNode trace
= (TmfTraceNode
) experiment
.getChildren().get(i
);
82 if (trace
.getResource().getLocation().equals(resource
.getLocation())) {
83 experiment
.removeChild(trace
);
85 trace
.getResource().delete(true, null);
90 parent
.removeChild(fTrace
);
92 resource
.delete(true, null);
93 } catch (CoreException e
) {