Commit | Line | Data |
---|---|---|
828e5592 | 1 | /******************************************************************************* |
11252342 | 2 | * Copyright (c) 2012, 2013 Ericsson |
6256d8ad | 3 | * |
828e5592 PT |
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 | |
6256d8ad | 8 | * |
828e5592 PT |
9 | * Contributors: |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; |
828e5592 PT |
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; | |
8fd82db5 | 23 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
828e5592 PT |
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 | ||
ad1195c0 FC |
29 | /** |
30 | * <b><u>DeleteAction</u></b> | |
31 | * <p> | |
32 | * Implement me. Please. | |
33 | * <p> | |
34 | */ | |
828e5592 PT |
35 | public class DeleteAction extends Action { |
36 | ||
ad1195c0 | 37 | private static final String DELETE_COMMAND_ID = "org.eclipse.ui.edit.delete"; //$NON-NLS-1$ |
828e5592 | 38 | |
6256d8ad AM |
39 | private final IWorkbenchPage page; |
40 | private final ISelectionProvider selectionProvider; | |
828e5592 PT |
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 | ||
828e5592 PT |
54 | @Override |
55 | public boolean isEnabled() { | |
56 | ISelection selection = selectionProvider.getSelection(); | |
57 | if (!selection.isEmpty()) { | |
58 | tracesSelected = false; | |
59 | experimentsSelected = false; | |
60 | IStructuredSelection sSelection = (IStructuredSelection) selection; | |
61 | for (Object aSelection : sSelection.toList()) { | |
62 | if (aSelection instanceof TmfTraceElement) { | |
63 | tracesSelected = true; | |
64 | } | |
65 | if (aSelection instanceof TmfExperimentElement) { | |
66 | experimentsSelected = true; | |
67 | } | |
68 | } | |
69 | if (tracesSelected && experimentsSelected) { | |
70 | return false; | |
71 | } | |
6256d8ad | 72 | return (tracesSelected || experimentsSelected); |
828e5592 PT |
73 | } |
74 | return false; | |
75 | } | |
76 | ||
828e5592 PT |
77 | @Override |
78 | public void run() { | |
79 | try { | |
80 | IHandlerService handlerService = (IHandlerService) page.getActivePart().getSite().getService(IHandlerService.class); | |
ad1195c0 FC |
81 | if (tracesSelected || experimentsSelected) { |
82 | handlerService.executeCommand(DELETE_COMMAND_ID, null); | |
828e5592 PT |
83 | } |
84 | } catch (ExecutionException e) { | |
8fd82db5 | 85 | Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$ |
828e5592 | 86 | } catch (NotDefinedException e) { |
8fd82db5 | 87 | Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$ |
828e5592 | 88 | } catch (NotEnabledException e) { |
8fd82db5 | 89 | Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$ |
828e5592 | 90 | } catch (NotHandledException e) { |
8fd82db5 | 91 | Activator.getDefault().logError("Error deleting resources", e); //$NON-NLS-1$ |
828e5592 PT |
92 | } |
93 | } | |
94 | ||
95 | } |