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
.linuxtools
.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
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfOpenTraceHelper
;
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>OpenExperimentHandler</u></b>
32 public class OpenExperimentHandler
extends AbstractHandler
{
34 private TmfExperimentElement fExperiment
= null;
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
41 public boolean isEnabled() {
43 // Check if we are closing down
44 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
50 final IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
51 final IWorkbenchPart part
= page
.getActivePart();
55 final ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
56 if (selectionProvider
== null) {
59 final ISelection selection
= selectionProvider
.getSelection();
61 // Make sure there is only one selection and that it is an experiment
63 if (selection
instanceof TreeSelection
) {
64 final TreeSelection sel
= (TreeSelection
) selection
;
65 // There should be only one item selected as per the plugin.xml
66 final Object element
= sel
.getFirstElement();
67 if (element
instanceof TmfExperimentElement
) {
68 fExperiment
= (TmfExperimentElement
) element
;
72 // We only enable opening from the Traces folder for now
73 return ((fExperiment
!= null) && (fExperiment
.getTraces().size() > 0));
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
81 public Object
execute(final ExecutionEvent event
) throws ExecutionException
{
83 // Check if we are closing down
84 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
89 // Check that the experiment is valid
90 if (fExperiment
== null) {
94 TmfOpenTraceHelper
.openExperimentFromElement(fExperiment
);