tmf: Simple warning fixes in tmf.core and tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / DeleteExperimentSupplementaryFilesHandler.java
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 java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
19 import org.eclipse.core.commands.AbstractHandler;
20 import org.eclipse.core.commands.ExecutionEvent;
21 import org.eclipse.core.commands.ExecutionException;
22 import org.eclipse.core.resources.IResource;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.core.runtime.NullProgressMonitor;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.ISelectionProvider;
27 import org.eclipse.jface.viewers.TreeSelection;
28 import org.eclipse.jface.window.Window;
29 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
30 import org.eclipse.linuxtools.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog;
31 import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
32 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
33 import org.eclipse.ui.IWorkbenchPage;
34 import org.eclipse.ui.IWorkbenchPart;
35 import org.eclipse.ui.IWorkbenchWindow;
36 import org.eclipse.ui.PlatformUI;
37
38 /**
39 * <b><u>DeleteExperimentSupplementaryFilesHandler</u></b>
40 * <p>
41 * TODO: Implement me. Please.
42 */
43 public class DeleteExperimentSupplementaryFilesHandler extends AbstractHandler {
44
45 // ------------------------------------------------------------------------
46 // Execution
47 // ------------------------------------------------------------------------
48
49 @Override
50 public Object execute(ExecutionEvent event) throws ExecutionException {
51
52 // Check if we are closing down
53 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
54 if (window == null) {
55 return null;
56 }
57
58 // Get the selection
59 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
60 IWorkbenchPart part = page.getActivePart();
61 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
62 if (selectionProvider == null) {
63 return false;
64 }
65
66 ISelection selection = selectionProvider.getSelection();
67
68 // Make sure there is only selection and that it is an experiment
69 if (selection instanceof TreeSelection) {
70 TreeSelection sel = (TreeSelection) selection;
71 // There should be only one item selected as per the plugin.xml
72 Object element = sel.getFirstElement();
73 List<IResource> resourcesList = new ArrayList<IResource>();
74
75 if (element instanceof TmfExperimentElement) {
76
77 TmfExperimentElement trace = (TmfExperimentElement) element;
78
79 for (TmfTraceElement aTrace : trace.getTraces()) {
80
81 // If trace is under an experiment, use the original trace from the traces folder
82 aTrace = aTrace.getElementUnderTraceFolder();
83
84 // Delete the selected resources
85 IResource[] resources = aTrace.getSupplementaryResources();
86 resourcesList.addAll(Arrays.asList(resources));
87 }
88
89 SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(), resourcesList.toArray(new IResource[resourcesList.size()]));
90
91 if (dialog.open() != Window.OK) {
92 return null;
93 }
94
95 IResource[] resourcesToDelete = dialog.getResources();
96
97 for (int i = 0; i < resourcesToDelete.length; i++) {
98 try {
99 resourcesToDelete[i].delete(true, new NullProgressMonitor());
100 } catch (CoreException e) {
101 Activator.getDefault().logError("Error deleting supplementary resource " + resourcesToDelete[i], e); //$NON-NLS-1$
102 }
103 }
104
105 IResource resource = trace.getProject().getResource();
106 if (resource != null) {
107 try {
108 if (resource != null) {
109 resource.refreshLocal(IResource.DEPTH_INFINITE, null);
110 }
111 } catch (CoreException e) {
112 Activator.getDefault().logError("Error refreshing resource " + resource, e); //$NON-NLS-1$
113 }
114 }
115 }
116 }
117 return null;
118 }
119 }
This page took 0.032031 seconds and 5 git commands to generate.