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 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
.core
.runtime
.IStatus
;
21 import org
.eclipse
.core
.runtime
.Status
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
24 import org
.eclipse
.jface
.viewers
.TreeSelection
;
25 import org
.eclipse
.jface
.window
.Window
;
26 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiPlugin
;
27 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.dialogs
.SelectSupplementaryResourcesDialog
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
29 import org
.eclipse
.ui
.IWorkbenchPage
;
30 import org
.eclipse
.ui
.IWorkbenchPart
;
31 import org
.eclipse
.ui
.IWorkbenchWindow
;
32 import org
.eclipse
.ui
.PlatformUI
;
35 * <b><u>DeleteTraceSupplementaryFilesHandler</u></b>
37 * TODO: Implement me. Please.
39 public class DeleteTraceSupplementaryFilesHandler
extends AbstractHandler
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
48 // Check if we are closing down
49 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
54 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
55 IWorkbenchPart part
= page
.getActivePart();
56 ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
57 if (selectionProvider
== null) {
61 ISelection selection
= selectionProvider
.getSelection();
63 // Make sure there is only selection and that it is an experiment
64 if (selection
instanceof TreeSelection
) {
65 TreeSelection sel
= (TreeSelection
) selection
;
66 // There should be only one item selected as per the plugin.xml
67 Object element
= sel
.getFirstElement();
68 if (element
instanceof TmfTraceElement
) {
69 TmfTraceElement trace
= (TmfTraceElement
) element
;
70 // If trace is under an experiment, use the original trace from the traces folder
71 trace
= trace
.getElementUnderTraceFolder();
73 // Delete the selected resources
74 IResource
[] resources
= trace
.getSupplementaryResources();
76 SelectSupplementaryResourcesDialog dialog
= new SelectSupplementaryResourcesDialog(window
.getShell(), resources
);
77 if (dialog
.open() != Window
.OK
) {
81 trace
.deleteSupplementaryResources(dialog
.getResources());
84 IResource resource
= trace
.getProject().getResource();
86 if (resource
!= null) {
88 if (resource
!= null) {
89 resource
.refreshLocal(IResource
.DEPTH_INFINITE
, null);
91 } catch (CoreException e
) {
92 TmfUiPlugin
.getDefault().getLog().log(new Status(IStatus
.ERROR
, TmfUiPlugin
.PLUGIN_ID
, "Error refreshing resource " + resource
, e
)); //$NON-NLS-1$