Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2009, 2013 Ericsson |
ce2388e0 | 3 | * |
12c155f5 FC |
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 | |
ce2388e0 | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; |
12c155f5 | 14 | |
12c155f5 FC |
15 | import org.eclipse.core.commands.AbstractHandler; |
16 | import org.eclipse.core.commands.ExecutionEvent; | |
17 | import org.eclipse.core.commands.ExecutionException; | |
12c155f5 | 18 | import org.eclipse.jface.viewers.ISelection; |
1595249b | 19 | import org.eclipse.jface.viewers.ISelectionProvider; |
12c155f5 | 20 | import org.eclipse.jface.viewers.TreeSelection; |
76fccfb0 | 21 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; |
12c155f5 | 22 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; |
12c155f5 FC |
23 | import org.eclipse.ui.IWorkbenchPage; |
24 | import org.eclipse.ui.IWorkbenchPart; | |
25 | import org.eclipse.ui.IWorkbenchWindow; | |
12c155f5 FC |
26 | import org.eclipse.ui.PlatformUI; |
27 | ||
28 | /** | |
29 | * <b><u>OpenTraceHandler</u></b> | |
30 | * <p> | |
31 | * TODO: Add support for multiple trace selection | |
32 | */ | |
33 | public class OpenTraceHandler extends AbstractHandler { | |
34 | ||
35 | // ------------------------------------------------------------------------ | |
36 | // Attributes | |
37 | // ------------------------------------------------------------------------ | |
38 | ||
39 | private TmfTraceElement fTrace = null; | |
40 | ||
41 | // ------------------------------------------------------------------------ | |
42 | // Validation | |
43 | // ------------------------------------------------------------------------ | |
44 | ||
45 | @Override | |
46 | public boolean isEnabled() { | |
47 | ||
48 | // Check if we are closing down | |
25e48683 | 49 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
abbdd66a | 50 | if (window == null) { |
12c155f5 | 51 | return false; |
abbdd66a | 52 | } |
12c155f5 FC |
53 | |
54 | // Get the selection | |
25e48683 FC |
55 | final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
56 | final IWorkbenchPart part = page.getActivePart(); | |
d5210347 PT |
57 | if (part == null) { |
58 | return false; | |
59 | } | |
25e48683 | 60 | final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); |
abbdd66a | 61 | if (selectionProvider == null) { |
1595249b | 62 | return false; |
abbdd66a | 63 | } |
25e48683 | 64 | final ISelection selection = selectionProvider.getSelection(); |
12c155f5 FC |
65 | |
66 | // Make sure there is only one selection and that it is a trace | |
67 | fTrace = null; | |
68 | if (selection instanceof TreeSelection) { | |
25e48683 | 69 | final TreeSelection sel = (TreeSelection) selection; |
12c155f5 | 70 | // There should be only one item selected as per the plugin.xml |
25e48683 | 71 | final Object element = sel.getFirstElement(); |
abbdd66a | 72 | if (element instanceof TmfTraceElement) { |
12c155f5 | 73 | fTrace = (TmfTraceElement) element; |
abbdd66a | 74 | } |
12c155f5 FC |
75 | } |
76 | ||
77 | // We only enable opening from the Traces folder for now | |
78 | return (fTrace != null); | |
79 | } | |
80 | ||
81 | // ------------------------------------------------------------------------ | |
82 | // Execution | |
83 | // ------------------------------------------------------------------------ | |
84 | ||
85 | @Override | |
25e48683 | 86 | public Object execute(final ExecutionEvent event) throws ExecutionException { |
12c155f5 FC |
87 | |
88 | // Check if we are closing down | |
25e48683 | 89 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
abbdd66a | 90 | if (window == null) { |
12c155f5 | 91 | return null; |
abbdd66a | 92 | } |
12c155f5 FC |
93 | |
94 | // Check that the trace is valid | |
abbdd66a | 95 | if (fTrace == null) { |
12c155f5 | 96 | return null; |
abbdd66a | 97 | } |
12c155f5 | 98 | |
828e5592 | 99 | // If trace is under an experiment, use the original trace from the traces folder |
67c53011 PT |
100 | TmfOpenTraceHelper.openTraceFromElement(fTrace.getElementUnderTraceFolder()); |
101 | return null; | |
12c155f5 FC |
102 | } |
103 | ||
12c155f5 | 104 | } |