Fix NLS-related Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / DeleteAction.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
14
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;
28
29 /**
30 * <b><u>DeleteAction</u></b>
31 * <p>
32 * Implement me. Please.
33 * <p>
34 */
35 public class DeleteAction extends Action {
36
37 private static final String DELETE_COMMAND_ID = "org.eclipse.ui.edit.delete"; //$NON-NLS-1$
38
39 private final IWorkbenchPage page;
40 private final ISelectionProvider selectionProvider;
41 private boolean tracesSelected;
42 private boolean experimentsSelected;
43
44 /**
45 * Default constructor
46 * @param page the workbench page
47 * @param selectionProvider the selection provider
48 */
49 public DeleteAction(IWorkbenchPage page, ISelectionProvider selectionProvider) {
50 this.page = page;
51 this.selectionProvider = selectionProvider;
52 }
53
54 /*
55 * (non-Javadoc)
56 * @see org.eclipse.jface.action.Action#isEnabled()
57 */
58 @Override
59 public boolean isEnabled() {
60 ISelection selection = selectionProvider.getSelection();
61 if (!selection.isEmpty()) {
62 tracesSelected = false;
63 experimentsSelected = false;
64 IStructuredSelection sSelection = (IStructuredSelection) selection;
65 for (Object aSelection : sSelection.toList()) {
66 if (aSelection instanceof TmfTraceElement) {
67 tracesSelected = true;
68 }
69 if (aSelection instanceof TmfExperimentElement) {
70 experimentsSelected = true;
71 }
72 }
73 if (tracesSelected && experimentsSelected) {
74 return false;
75 }
76 return (tracesSelected || experimentsSelected);
77 }
78 return false;
79 }
80
81 /*
82 * (non-Javadoc)
83 * @see org.eclipse.jface.action.Action#run()
84 */
85 @Override
86 public void run() {
87 try {
88 IHandlerService handlerService = (IHandlerService) page.getActivePart().getSite().getService(IHandlerService.class);
89 if (tracesSelected || experimentsSelected) {
90 handlerService.executeCommand(DELETE_COMMAND_ID, null);
91 }
92 } catch (ExecutionException e) {
93 Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$
94 } catch (NotDefinedException e) {
95 Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$
96 } catch (NotEnabledException e) {
97 Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$
98 } catch (NotHandledException e) {
99 Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$
100 }
101 }
102
103 }
This page took 0.032994 seconds and 5 git commands to generate.