Add handling of supplementary files of traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / DeleteExperimentSupplementaryFilesHandler.java
CommitLineData
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
13package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.resources.IResource;
19import org.eclipse.core.runtime.CoreException;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.Status;
22import org.eclipse.jface.viewers.ISelection;
23import org.eclipse.jface.viewers.ISelectionProvider;
24import org.eclipse.jface.viewers.TreeSelection;
25import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin;
26import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
27import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
28import org.eclipse.ui.IWorkbenchPage;
29import org.eclipse.ui.IWorkbenchPart;
30import org.eclipse.ui.IWorkbenchWindow;
31import org.eclipse.ui.PlatformUI;
32
33/**
34 * <b><u>DeleteExperimentSupplementaryFilesHandler</u></b>
35 * <p>
36 * TODO: Implement me. Please.
37 */
38public 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()) {
73
74 // If trace is under an experiment, use the original trace from the traces folder
75 aTrace = aTrace.getElementUnderTraceFolder();
76
77 aTrace.deleteSupplementaryFiles();
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}
This page took 0.026582 seconds and 5 git commands to generate.