1 /*******************************************************************************
2 * Copyright (c) 2012 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.NotEnabledException
;
17 import org
.eclipse
.core
.commands
.NotHandledException
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.jface
.action
.Action
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
22 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
23 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
26 import org
.eclipse
.ui
.IWorkbenchPage
;
27 import org
.eclipse
.ui
.handlers
.IHandlerService
;
29 public class DeleteAction
extends Action
{
31 private static final String DELETE_TRACE_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.trace.delete"; //$NON-NLS-1$
32 private static final String DELETE_EXPERIMENT_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.experiment.delete"; //$NON-NLS-1$
34 private IWorkbenchPage page
;
35 private ISelectionProvider selectionProvider
;
36 private boolean tracesSelected
;
37 private boolean experimentsSelected
;
41 * @param page the workbench page
42 * @param selectionProvider the selection provider
44 public DeleteAction(IWorkbenchPage page
, ISelectionProvider selectionProvider
) {
46 this.selectionProvider
= selectionProvider
;
51 * @see org.eclipse.jface.action.Action#isEnabled()
54 public boolean isEnabled() {
55 ISelection selection
= selectionProvider
.getSelection();
56 if (!selection
.isEmpty()) {
57 tracesSelected
= false;
58 experimentsSelected
= false;
59 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
60 for (Object aSelection
: sSelection
.toList()) {
61 if (aSelection
instanceof TmfTraceElement
) {
62 tracesSelected
= true;
64 if (aSelection
instanceof TmfExperimentElement
) {
65 experimentsSelected
= true;
68 if (tracesSelected
&& experimentsSelected
) {
71 return (tracesSelected
|| experimentsSelected
);
78 * @see org.eclipse.jface.action.Action#run()
83 IHandlerService handlerService
= (IHandlerService
) page
.getActivePart().getSite().getService(IHandlerService
.class);
85 handlerService
.executeCommand(DELETE_TRACE_COMMAND_ID
, null);
86 } else if (experimentsSelected
) {
87 handlerService
.executeCommand(DELETE_EXPERIMENT_COMMAND_ID
, null);
89 } catch (ExecutionException e
) {
90 Activator
.getDefault().logError("Error deleting resources", e
); //$NON-NLS-1$
91 } catch (NotDefinedException e
) {
92 Activator
.getDefault().logError("Error deleting resources", e
); //$NON-NLS-1$
93 } catch (NotEnabledException e
) {
94 Activator
.getDefault().logError("Error deleting resources", e
); //$NON-NLS-1$
95 } catch (NotHandledException e
) {
96 Activator
.getDefault().logError("Error deleting resources", e
); //$NON-NLS-1$