tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / DeleteTraceSupplementaryFilesHandler.java
CommitLineData
5e4bf87d 1/*******************************************************************************
c8422608 2 * Copyright (c) 2009, 2013 Ericsson
abbdd66a 3 *
5e4bf87d
BH
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
abbdd66a 8 *
5e4bf87d
BH
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;
5e4bf87d
BH
20import org.eclipse.jface.viewers.ISelection;
21import org.eclipse.jface.viewers.ISelectionProvider;
22import org.eclipse.jface.viewers.TreeSelection;
e12ecd30 23import org.eclipse.jface.window.Window;
8fd82db5 24import org.eclipse.linuxtools.internal.tmf.ui.Activator;
e12ecd30 25import org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog;
5e4bf87d
BH
26import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
27import org.eclipse.ui.IWorkbenchPage;
28import org.eclipse.ui.IWorkbenchPart;
29import org.eclipse.ui.IWorkbenchWindow;
30import org.eclipse.ui.PlatformUI;
31
32/**
33 * <b><u>DeleteTraceSupplementaryFilesHandler</u></b>
34 * <p>
35 * TODO: Implement me. Please.
36 */
37public class DeleteTraceSupplementaryFilesHandler extends AbstractHandler {
38
39 // ------------------------------------------------------------------------
40 // Execution
41 // ------------------------------------------------------------------------
42
43 @Override
44 public Object execute(ExecutionEvent event) throws ExecutionException {
45
46 // Check if we are closing down
47 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
abbdd66a 48 if (window == null) {
5e4bf87d 49 return null;
abbdd66a 50 }
5e4bf87d
BH
51
52 // Get the selection
53 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
54 IWorkbenchPart part = page.getActivePart();
d5210347
PT
55 if (part == null) {
56 return false;
57 }
5e4bf87d
BH
58 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
59 if (selectionProvider == null) {
60 return false;
61 }
e12ecd30 62
5e4bf87d
BH
63 ISelection selection = selectionProvider.getSelection();
64
65 // Make sure there is only selection and that it is an experiment
66 if (selection instanceof TreeSelection) {
67 TreeSelection sel = (TreeSelection) selection;
68 // There should be only one item selected as per the plugin.xml
69 Object element = sel.getFirstElement();
70 if (element instanceof TmfTraceElement) {
71 TmfTraceElement trace = (TmfTraceElement) element;
72 // If trace is under an experiment, use the original trace from the traces folder
73 trace = trace.getElementUnderTraceFolder();
e12ecd30
BH
74
75 // Delete the selected resources
76 IResource[] resources = trace.getSupplementaryResources();
abbdd66a 77
e12ecd30
BH
78 SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(), resources);
79 if (dialog.open() != Window.OK) {
80 return null;
81 }
82
83 trace.deleteSupplementaryResources(dialog.getResources());
84
85 // Refresh project
86 IResource resource = trace.getProject().getResource();
87
5e4bf87d
BH
88 if (resource != null) {
89 try {
abbdd66a 90 resource.refreshLocal(IResource.DEPTH_INFINITE, null);
5e4bf87d 91 } catch (CoreException e) {
8fd82db5 92 Activator.getDefault().logError("Error refreshing resource " + resource, e); //$NON-NLS-1$
5e4bf87d
BH
93 }
94 }
95 }
96 }
97
98 return null;
99 }
100
101}
This page took 0.032097 seconds and 5 git commands to generate.