Commit | Line | Data |
---|---|---|
5e4bf87d BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010, 2011 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.internal.tmf.ui.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.IResource; | |
19 | import org.eclipse.core.runtime.CoreException; | |
20 | import org.eclipse.core.runtime.IStatus; | |
21 | import org.eclipse.core.runtime.Status; | |
22 | import org.eclipse.jface.viewers.ISelection; | |
23 | import org.eclipse.jface.viewers.ISelectionProvider; | |
24 | import org.eclipse.jface.viewers.TreeSelection; | |
25 | import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin; | |
26 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; | |
27 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; | |
28 | import org.eclipse.ui.IWorkbenchPage; | |
29 | import org.eclipse.ui.IWorkbenchPart; | |
30 | import org.eclipse.ui.IWorkbenchWindow; | |
31 | import org.eclipse.ui.PlatformUI; | |
32 | ||
33 | /** | |
34 | * <b><u>DeleteExperimentSupplementaryFilesHandler</u></b> | |
35 | * <p> | |
36 | * TODO: Implement me. Please. | |
37 | */ | |
38 | public class DeleteExperimentSupplementaryFilesHandler extends AbstractHandler { | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Execution | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
44 | @Override | |
45 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
46 | ||
47 | // Check if we are closing down | |
48 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
49 | if (window == null) { | |
50 | return null; | |
51 | } | |
52 | ||
53 | // Get the selection | |
54 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
55 | IWorkbenchPart part = page.getActivePart(); | |
56 | ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); | |
57 | if (selectionProvider == null) { | |
58 | return false; | |
59 | } | |
60 | ||
61 | ISelection selection = selectionProvider.getSelection(); | |
62 | ||
63 | // Make sure there is only selection and that it is an experiment | |
64 | if (selection instanceof TreeSelection) { | |
65 | TreeSelection sel = (TreeSelection) selection; | |
66 | // There should be only one item selected as per the plugin.xml | |
67 | Object element = sel.getFirstElement(); | |
68 | if (element instanceof TmfExperimentElement) { | |
69 | ||
70 | TmfExperimentElement trace = (TmfExperimentElement) element; | |
71 | ||
72 | for (TmfTraceElement aTrace : trace.getTraces()) { | |
0f0d17bb | 73 | |
5e4bf87d BH |
74 | // If trace is under an experiment, use the original trace from the traces folder |
75 | aTrace = aTrace.getElementUnderTraceFolder(); | |
0f0d17bb AM |
76 | |
77 | aTrace.deleteSupplementaryFiles(); | |
5e4bf87d BH |
78 | } |
79 | ||
80 | IResource resource = trace.getProject().getResource(); | |
81 | if (resource != null) { | |
82 | try { | |
83 | if (resource != null) { | |
84 | resource.refreshLocal(IResource.DEPTH_INFINITE, null); | |
85 | } | |
86 | } catch (CoreException e) { | |
87 | TmfUiPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TmfUiPlugin.PLUGIN_ID, "Error refreshing resource " + resource, e)); //$NON-NLS-1$ | |
88 | } | |
89 | } | |
90 | } | |
91 | } | |
92 | return null; | |
93 | } | |
94 | } |