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
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.ISelectionProvider;
22 import org.eclipse.jface.viewers.TreeSelection;
23 import org.eclipse.jface.window.Window;
24 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
25 import org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog;
26 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
27 import org.eclipse.ui.IWorkbenchPage;
28 import org.eclipse.ui.IWorkbenchPart;
29 import org.eclipse.ui.IWorkbenchWindow;
30 import org.eclipse.ui.PlatformUI;
31
32 /**
33 * <b><u>DeleteTraceSupplementaryFilesHandler</u></b>
34 * <p>
35 * TODO: Implement me. Please.
36 */
37 public 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();
48 if (window == null) {
49 return null;
50 }
51
52 // Get the selection
53 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
54 IWorkbenchPart part = page.getActivePart();
55 if (part == null) {
56 return false;
57 }
58 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
59 if (selectionProvider == null) {
60 return false;
61 }
62
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();
74
75 // Delete the selected resources
76 IResource[] resources = trace.getSupplementaryResources();
77
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
88 if (resource != null) {
89 try {
90 resource.refreshLocal(IResource.DEPTH_INFINITE, null);
91 } catch (CoreException e) {
92 Activator.getDefault().logError("Error refreshing resource " + resource, e); //$NON-NLS-1$
93 }
94 }
95 }
96 }
97
98 return null;
99 }
100
101 }
This page took 0.031896 seconds and 5 git commands to generate.