401d87937db151dbcb4b9e3aa93f0ac407434a4f
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / filter / CopyHandler.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.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 * @author Xavier Raynaud <xavier.raynaud@kalray.eu>
28 * @since 3.0
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 if (!selection.isEmpty()) {
74 return true;
75 }
76 }
77 return false;
78 }
79 }
This page took 0.032038 seconds and 4 git commands to generate.