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
.TmfUiPlugin
;
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();
61 ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
62 if (selectionProvider
== null) {
66 ISelection selection
= selectionProvider
.getSelection();
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
>();
75 if (element
instanceof TmfExperimentElement
) {
77 TmfExperimentElement trace
= (TmfExperimentElement
) element
;
79 for (TmfTraceElement aTrace
: trace
.getTraces()) {
81 // If trace is under an experiment, use the original trace from the traces folder
82 aTrace
= aTrace
.getElementUnderTraceFolder();
84 // Delete the selected resources
85 IResource
[] resources
= aTrace
.getSupplementaryResources();
86 resourcesList
.addAll(Arrays
.asList(resources
));
89 SelectSupplementaryResourcesDialog dialog
= new SelectSupplementaryResourcesDialog(window
.getShell(), resourcesList
.toArray(new IResource
[resourcesList
.size()]));
91 if (dialog
.open() != Window
.OK
) {
95 IResource
[] resourcesToDelete
= dialog
.getResources();
97 for (int i
= 0; i
< resourcesToDelete
.length
; i
++) {
99 resourcesToDelete
[i
].delete(true, new NullProgressMonitor());
100 } catch (CoreException e
) {
101 TmfUiPlugin
.getDefault().logError("Error deleting supplementary resource " + resourcesToDelete
[i
], e
); //$NON-NLS-1$
105 IResource resource
= trace
.getProject().getResource();
106 if (resource
!= null) {
108 if (resource
!= null) {
109 resource
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
111 } catch (CoreException e
) {
112 TmfUiPlugin
.getDefault().logError("Error refreshing resource " + resource
, e
); //$NON-NLS-1$