Commit | Line | Data |
---|---|---|
ef906471 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 Kalray |
ef906471 XR |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.views.filter; |
ef906471 XR |
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> | |
c4767854 | 28 | * @since 3.0 |
ef906471 XR |
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 | } |