acf42e57a4d20396a2c6428adeea764c468882f7
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / filter / CopyHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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.tracecompass.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.util.LocalSelectionTransfer;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.ui.IWorkbenchPage;
21 import org.eclipse.ui.IWorkbenchPart;
22 import org.eclipse.ui.IWorkbenchWindow;
23 import org.eclipse.ui.PlatformUI;
24
25 /**
26 * Handler for copy command in filter view
27 *
28 * @author Xavier Raynaud <xavier.raynaud@kalray.eu>
29 */
30 public class CopyHandler extends AbstractHandler {
31
32 @Override
33 public Object execute(ExecutionEvent event) throws ExecutionException {
34 // Check if we are closing down
35 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
36 if (window == null) {
37 return null;
38 }
39 IWorkbenchPage page = window.getActivePage();
40 FilterView part = (FilterView) page.getActivePart();
41 ISelection selection = getSelection(part);
42
43 LocalSelectionTransfer.getTransfer().setSelection(selection);
44 LocalSelectionTransfer.getTransfer().setSelectionSetTime(System.currentTimeMillis());
45 return null;
46 }
47
48 /**
49 * Retrieve the current selection
50 *
51 * @param tcv
52 * the FilterView
53 * @return the current selection in the FilterView
54 */
55 protected ISelection getSelection(FilterView tcv) {
56 return tcv.getViewSite().getSelectionProvider().getSelection();
57 }
58
59 @Override
60 public boolean isEnabled() {
61 // Check if we are closing down
62 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
63 if (window == null) {
64 return false;
65 }
66
67 // Get the selection
68 IWorkbenchPage page = window.getActivePage();
69 IWorkbenchPart part = page.getActivePart();
70 if (part instanceof FilterView) {
71 FilterView tcv = (FilterView) part;
72 ISelection selection = tcv.getSite().getSelectionProvider().getSelection();
73 // only enable if tree is in focus
74 if (!selection.isEmpty() && tcv.isTreeInFocus()) {
75 return true;
76 }
77 }
78 return false;
79 }
80 }
This page took 0.051488 seconds and 4 git commands to generate.