1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.handlers
;
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
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfOpenTraceHelper
;
22 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceElement
;
23 import org
.eclipse
.ui
.IWorkbenchPage
;
24 import org
.eclipse
.ui
.IWorkbenchPart
;
25 import org
.eclipse
.ui
.IWorkbenchWindow
;
26 import org
.eclipse
.ui
.PlatformUI
;
29 * <b><u>OpenTraceHandler</u></b>
31 * TODO: Add support for multiple trace selection
33 public class OpenTraceHandler
extends AbstractHandler
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 private TmfTraceElement fTrace
= null;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 public boolean isEnabled() {
48 // Check if we are closing down
49 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
55 final IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
56 final IWorkbenchPart part
= page
.getActivePart();
60 final ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
61 if (selectionProvider
== null) {
64 final ISelection selection
= selectionProvider
.getSelection();
66 // Make sure there is only one selection and that it is a trace
68 if (selection
instanceof TreeSelection
) {
69 final TreeSelection sel
= (TreeSelection
) selection
;
70 // There should be only one item selected as per the plugin.xml
71 final Object element
= sel
.getFirstElement();
72 if (element
instanceof TmfTraceElement
) {
73 fTrace
= (TmfTraceElement
) element
;
77 // We only enable opening from the Traces folder for now
78 return (fTrace
!= null);
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
86 public Object
execute(final ExecutionEvent event
) throws ExecutionException
{
88 // Check if we are closing down
89 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
94 // Check that the trace is valid
99 // If trace is under an experiment, use the original trace from the traces folder
100 TmfOpenTraceHelper
.openTraceFromElement(fTrace
.getElementUnderTraceFolder());