1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal
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 * Geneviève Bastien - Experiment instantiates with an experiment type
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
16 import org
.eclipse
.core
.commands
.AbstractHandler
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.jface
.viewers
.ISelection
;
20 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
21 import org
.eclipse
.jface
.viewers
.TreeSelection
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfOpenTraceHelper
;
24 import org
.eclipse
.ui
.IWorkbenchPage
;
25 import org
.eclipse
.ui
.IWorkbenchPart
;
26 import org
.eclipse
.ui
.IWorkbenchWindow
;
27 import org
.eclipse
.ui
.PlatformUI
;
30 * <b><u>OpenExperimentHandler</u></b>
33 public class OpenExperimentHandler
extends AbstractHandler
{
35 private TmfExperimentElement fExperiment
= null;
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 public boolean isEnabled() {
44 // Check if we are closing down
45 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
51 final IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
52 final IWorkbenchPart part
= page
.getActivePart();
56 final ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
57 if (selectionProvider
== null) {
60 final ISelection selection
= selectionProvider
.getSelection();
62 // Make sure there is only one selection and that it is an experiment
64 if (selection
instanceof TreeSelection
) {
65 final TreeSelection sel
= (TreeSelection
) selection
;
66 // There should be only one item selected as per the plugin.xml
67 final Object element
= sel
.getFirstElement();
68 if (element
instanceof TmfExperimentElement
) {
69 fExperiment
= (TmfExperimentElement
) element
;
73 // We only enable opening from the Traces folder for now
74 return ((fExperiment
!= null) && (fExperiment
.getTraces().size() > 0));
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 public Object
execute(final ExecutionEvent event
) throws ExecutionException
{
84 // Check if we are closing down
85 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
90 // Check that the experiment is valid
91 if (fExperiment
== null) {
95 TmfOpenTraceHelper
.openTraceFromElement(fExperiment
);