1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2011 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.List
;
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
;
39 * <b><u>DeleteExperimentSupplementaryFilesHandler</u></b>
41 * TODO: Implement me. Please.
43 public class DeleteExperimentSupplementaryFilesHandler
extends AbstractHandler
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
50 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
52 // Check if we are closing down
53 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
59 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
60 IWorkbenchPart part
= page
.getActivePart();
64 ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
65 if (selectionProvider
== null) {
69 ISelection selection
= selectionProvider
.getSelection();
71 // Make sure there is only selection and that it is an experiment
72 if (selection
instanceof TreeSelection
) {
73 TreeSelection sel
= (TreeSelection
) selection
;
74 // There should be only one item selected as per the plugin.xml
75 Object element
= sel
.getFirstElement();
76 List
<IResource
> resourcesList
= new ArrayList
<IResource
>();
78 if (element
instanceof TmfExperimentElement
) {
80 TmfExperimentElement trace
= (TmfExperimentElement
) element
;
82 for (TmfTraceElement aTrace
: trace
.getTraces()) {
84 // If trace is under an experiment, use the original trace from the traces folder
85 aTrace
= aTrace
.getElementUnderTraceFolder();
87 // Delete the selected resources
88 IResource
[] resources
= aTrace
.getSupplementaryResources();
89 resourcesList
.addAll(Arrays
.asList(resources
));
92 SelectSupplementaryResourcesDialog dialog
= new SelectSupplementaryResourcesDialog(window
.getShell(), resourcesList
.toArray(new IResource
[resourcesList
.size()]));
94 if (dialog
.open() != Window
.OK
) {
98 IResource
[] resourcesToDelete
= dialog
.getResources();
100 for (int i
= 0; i
< resourcesToDelete
.length
; i
++) {
102 resourcesToDelete
[i
].delete(true, new NullProgressMonitor());
103 } catch (CoreException e
) {
104 Activator
.getDefault().logError("Error deleting supplementary resource " + resourcesToDelete
[i
], e
); //$NON-NLS-1$
108 IResource resource
= trace
.getProject().getResource();
109 if (resource
!= null) {
111 resource
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
112 } catch (CoreException e
) {
113 Activator
.getDefault().logError("Error refreshing resource " + resource
, e
); //$NON-NLS-1$