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
.tmf
.ui
.project
.model
.TmfExperimentElement
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
25 import org
.eclipse
.ui
.IWorkbenchPage
;
26 import org
.eclipse
.ui
.handlers
.IHandlerService
;
28 public class DeleteAction
extends Action
{
30 private static final String DELETE_TRACE_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.trace.delete"; //$NON-NLS-1$
31 private static final String DELETE_EXPERIMENT_COMMAND_ID
= "org.eclipse.linuxtools.tmf.ui.command.project.experiment.delete"; //$NON-NLS-1$
33 private IWorkbenchPage page
;
34 private ISelectionProvider selectionProvider
;
35 private boolean tracesSelected
;
36 private boolean experimentsSelected
;
40 * @param page the workbench page
41 * @param selectionProvider the selection provider
43 public DeleteAction(IWorkbenchPage page
, ISelectionProvider selectionProvider
) {
45 this.selectionProvider
= selectionProvider
;
50 * @see org.eclipse.jface.action.Action#isEnabled()
53 public boolean isEnabled() {
54 ISelection selection
= selectionProvider
.getSelection();
55 if (!selection
.isEmpty()) {
56 tracesSelected
= false;
57 experimentsSelected
= false;
58 IStructuredSelection sSelection
= (IStructuredSelection
) selection
;
59 for (Object aSelection
: sSelection
.toList()) {
60 if (aSelection
instanceof TmfTraceElement
) {
61 tracesSelected
= true;
63 if (aSelection
instanceof TmfExperimentElement
) {
64 experimentsSelected
= true;
67 if (tracesSelected
&& experimentsSelected
) {
70 return (tracesSelected
|| experimentsSelected
);
77 * @see org.eclipse.jface.action.Action#run()
82 IHandlerService handlerService
= (IHandlerService
) page
.getActivePart().getSite().getService(IHandlerService
.class);
84 handlerService
.executeCommand(DELETE_TRACE_COMMAND_ID
, null);
85 } else if (experimentsSelected
) {
86 handlerService
.executeCommand(DELETE_EXPERIMENT_COMMAND_ID
, null);
88 } catch (ExecutionException e
) {
90 } catch (NotDefinedException e
) {
92 } catch (NotEnabledException e
) {
94 } catch (NotHandledException e
) {