Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
9d2e08b9 | 2 | * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal |
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 | |
9d2e08b9 | 11 | * Geneviève Bastien - Experiment instantiates with an experiment type |
12c155f5 FC |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.internal.tmf.ui.project.handlers; |
12c155f5 | 15 | |
12c155f5 FC |
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; | |
1595249b | 20 | import org.eclipse.jface.viewers.ISelectionProvider; |
12c155f5 | 21 | import org.eclipse.jface.viewers.TreeSelection; |
2bdf0193 AM |
22 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; |
23 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper; | |
12c155f5 FC |
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> | |
12c155f5 FC |
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 | |
25e48683 | 45 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
6256d8ad | 46 | if (window == null) { |
12c155f5 | 47 | return false; |
6256d8ad | 48 | } |
12c155f5 FC |
49 | |
50 | // Get the selection | |
25e48683 FC |
51 | final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
52 | final IWorkbenchPart part = page.getActivePart(); | |
d5210347 PT |
53 | if (part == null) { |
54 | return false; | |
55 | } | |
25e48683 | 56 | final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); |
6256d8ad | 57 | if (selectionProvider == null) { |
1595249b | 58 | return false; |
6256d8ad | 59 | } |
25e48683 | 60 | final ISelection selection = selectionProvider.getSelection(); |
12c155f5 FC |
61 | |
62 | // Make sure there is only one selection and that it is an experiment | |
63 | fExperiment = null; | |
64 | if (selection instanceof TreeSelection) { | |
25e48683 | 65 | final TreeSelection sel = (TreeSelection) selection; |
12c155f5 | 66 | // There should be only one item selected as per the plugin.xml |
25e48683 | 67 | final Object element = sel.getFirstElement(); |
6256d8ad | 68 | if (element instanceof TmfExperimentElement) { |
12c155f5 | 69 | fExperiment = (TmfExperimentElement) element; |
6256d8ad | 70 | } |
12c155f5 FC |
71 | } |
72 | ||
73 | // We only enable opening from the Traces folder for now | |
cbac3b6b | 74 | return ((fExperiment != null) && (fExperiment.getTraces().size() > 0)); |
12c155f5 FC |
75 | } |
76 | ||
77 | // ------------------------------------------------------------------------ | |
78 | // Execution | |
79 | // ------------------------------------------------------------------------ | |
80 | ||
12c155f5 | 81 | @Override |
25e48683 | 82 | public Object execute(final ExecutionEvent event) throws ExecutionException { |
12c155f5 FC |
83 | |
84 | // Check if we are closing down | |
25e48683 | 85 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
6256d8ad | 86 | if (window == null) { |
67c53011 | 87 | return null; |
6256d8ad | 88 | } |
12c155f5 | 89 | |
67c53011 PT |
90 | // Check that the experiment is valid |
91 | if (fExperiment == null) { | |
92 | return null; | |
93 | } | |
12c155f5 | 94 | |
9d2e08b9 | 95 | TmfOpenTraceHelper.openTraceFromElement(fExperiment); |
12c155f5 FC |
96 | return null; |
97 | } | |
98 | ||
12c155f5 | 99 | } |