tmf: Bug 415707: Trace already opened should not be re-opened
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / OpenTraceHandler.java
CommitLineData
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 13package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
12c155f5 14
12c155f5
FC
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
12c155f5 18import org.eclipse.jface.viewers.ISelection;
1595249b 19import org.eclipse.jface.viewers.ISelectionProvider;
12c155f5 20import org.eclipse.jface.viewers.TreeSelection;
76fccfb0 21import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
12c155f5 22import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
12c155f5
FC
23import org.eclipse.ui.IWorkbenchPage;
24import org.eclipse.ui.IWorkbenchPart;
25import org.eclipse.ui.IWorkbenchWindow;
12c155f5
FC
26import org.eclipse.ui.PlatformUI;
27
28/**
29 * <b><u>OpenTraceHandler</u></b>
30 * <p>
31 * TODO: Add support for multiple trace selection
32 */
33public 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}
This page took 0.061321 seconds and 5 git commands to generate.