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
.IStatus
;
25 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
26 import org
.eclipse
.core
.runtime
.Status
;
27 import org
.eclipse
.jface
.viewers
.ISelection
;
28 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
29 import org
.eclipse
.jface
.viewers
.TreeSelection
;
30 import org
.eclipse
.jface
.window
.Window
;
31 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
32 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.dialogs
.SelectSupplementaryResourcesDialog
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
35 import org
.eclipse
.ui
.IWorkbenchPage
;
36 import org
.eclipse
.ui
.IWorkbenchPart
;
37 import org
.eclipse
.ui
.IWorkbenchWindow
;
38 import org
.eclipse
.ui
.PlatformUI
;
41 * <b><u>DeleteExperimentSupplementaryFilesHandler</u></b>
43 * TODO: Implement me. Please.
45 public class DeleteExperimentSupplementaryFilesHandler
extends AbstractHandler
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
54 // Check if we are closing down
55 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
61 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
62 IWorkbenchPart part
= page
.getActivePart();
63 ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
64 if (selectionProvider
== null) {
68 ISelection selection
= selectionProvider
.getSelection();
70 // Make sure there is only selection and that it is an experiment
71 if (selection
instanceof TreeSelection
) {
72 TreeSelection sel
= (TreeSelection
) selection
;
73 // There should be only one item selected as per the plugin.xml
74 Object element
= sel
.getFirstElement();
75 List
<IResource
> resourcesList
= new ArrayList
<IResource
>();
77 if (element
instanceof TmfExperimentElement
) {
79 TmfExperimentElement trace
= (TmfExperimentElement
) element
;
81 for (TmfTraceElement aTrace
: trace
.getTraces()) {
83 // If trace is under an experiment, use the original trace from the traces folder
84 aTrace
= aTrace
.getElementUnderTraceFolder();
86 // Delete the selected resources
87 IResource
[] resources
= aTrace
.getSupplementaryResources();
88 resourcesList
.addAll(Arrays
.asList(resources
));
91 SelectSupplementaryResourcesDialog dialog
= new SelectSupplementaryResourcesDialog(window
.getShell(), resourcesList
.toArray(new IResource
[resourcesList
.size()]));
93 if (dialog
.open() != Window
.OK
) {
97 IResource
[] resourcesToDelete
= dialog
.getResources();
99 for (int i
= 0; i
< resourcesToDelete
.length
; i
++) {
101 resourcesToDelete
[i
].delete(true, new NullProgressMonitor());
102 } catch (CoreException e
) {
103 TmfUiPlugin
.getDefault().getLog().log(new Status(IStatus
.ERROR
, TmfUiPlugin
.PLUGIN_ID
, "Error deleting supplementary resource " + resourcesToDelete
[i
], e
)); //$NON-NLS-1$
107 IResource resource
= trace
.getProject().getResource();
108 if (resource
!= null) {
110 if (resource
!= null) {
111 resource
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
113 } catch (CoreException e
) {
114 TmfUiPlugin
.getDefault().getLog().log(new Status(IStatus
.ERROR
, TmfUiPlugin
.PLUGIN_ID
, "Error refreshing resource " + resource
, e
)); //$NON-NLS-1$