TMF: add support of cut/copy/paste/dnd in FilterView
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / filter / DeleteHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2013 Kalray
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 * Xavier Raynaud - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.filter;
14
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.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.IStructuredSelection;
20 import org.eclipse.linuxtools.tmf.core.filter.model.ITmfFilterTreeNode;
21 import org.eclipse.ui.IWorkbenchPage;
22 import org.eclipse.ui.IWorkbenchPart;
23 import org.eclipse.ui.IWorkbenchWindow;
24 import org.eclipse.ui.PlatformUI;
25
26 /**
27 * Handler for delete command in filter view
28 * @author Xavier Raynaud <xavier.raynaud@kalray.eu>
29 * @since 2.2
30 */
31 public class DeleteHandler extends AbstractHandler {
32
33 @Override
34 public Object execute(ExecutionEvent event) throws ExecutionException {
35 // Check if we are closing down
36 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
37 if (window == null) {
38 return null;
39 }
40 IWorkbenchPage page = window.getActivePage();
41 FilterView part = (FilterView) page.getActivePart();
42 ISelection sel = part.getViewSite().getSelectionProvider().getSelection();
43 if (sel instanceof IStructuredSelection) {
44 IStructuredSelection selection = (IStructuredSelection) sel;
45 Object o = selection.getFirstElement();
46 if (o instanceof ITmfFilterTreeNode) {
47 ITmfFilterTreeNode node = (ITmfFilterTreeNode) o;
48 node = node.remove();
49 part.refresh();
50 }
51 }
52 return null;
53 }
54
55 @Override
56 public boolean isEnabled() {
57 // Check if we are closing down
58 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
59 if (window == null) {
60 return false;
61 }
62
63 // Get the selection
64 IWorkbenchPage page = window.getActivePage();
65 IWorkbenchPart part = page.getActivePart();
66 if (part instanceof FilterView) {
67 FilterView tcv = (FilterView) part;
68 ISelection selection = tcv.getSite().getSelectionProvider().getSelection();
69 if (!selection.isEmpty()) {
70 return true;
71 }
72 }
73 return false;
74 }
75 }
This page took 0.032005 seconds and 5 git commands to generate.