analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / project / handlers / OpenExperimentHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 * Geneviève Bastien - Experiment instantiates with an experiment type
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.internal.tmf.ui.project.handlers;
15
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.tracecompass.tmf.ui.project.model.TmfExperimentElement;
23 import org.eclipse.tracecompass.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;
28
29 /**
30 * <b><u>OpenExperimentHandler</u></b>
31 * <p>
32 */
33 public class OpenExperimentHandler extends AbstractHandler {
34
35 private TmfExperimentElement fExperiment = null;
36
37 // ------------------------------------------------------------------------
38 // Validation
39 // ------------------------------------------------------------------------
40
41 @Override
42 public boolean isEnabled() {
43
44 // Check if we are closing down
45 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
46 if (window == null) {
47 return false;
48 }
49
50 // Get the selection
51 final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
52 final IWorkbenchPart part = page.getActivePart();
53 if (part == null) {
54 return false;
55 }
56 final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
57 if (selectionProvider == null) {
58 return false;
59 }
60 final ISelection selection = selectionProvider.getSelection();
61
62 // Make sure there is only one selection and that it is an experiment
63 fExperiment = null;
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;
70 }
71 }
72
73 // We only enable opening from the Traces folder for now
74 return ((fExperiment != null) && (fExperiment.getTraces().size() > 0));
75 }
76
77 // ------------------------------------------------------------------------
78 // Execution
79 // ------------------------------------------------------------------------
80
81 @Override
82 public Object execute(final ExecutionEvent event) throws ExecutionException {
83
84 // Check if we are closing down
85 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
86 if (window == null) {
87 return null;
88 }
89
90 // Check that the experiment is valid
91 if (fExperiment == null) {
92 return null;
93 }
94
95 TmfOpenTraceHelper.openTraceFromElement(fExperiment);
96 return null;
97 }
98
99 }
This page took 0.042196 seconds and 5 git commands to generate.