Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2009, 2013 Ericsson |
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 | |
11 | *******************************************************************************/ | |
12 | ||
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; |
12c155f5 | 14 | |
12c155f5 FC |
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; | |
1595249b | 19 | import org.eclipse.jface.viewers.ISelectionProvider; |
12c155f5 | 20 | import org.eclipse.jface.viewers.TreeSelection; |
12c155f5 | 21 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; |
67c53011 | 22 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; |
12c155f5 FC |
23 | import org.eclipse.ui.IWorkbenchPage; |
24 | import org.eclipse.ui.IWorkbenchPart; | |
25 | import org.eclipse.ui.IWorkbenchWindow; | |
26 | import org.eclipse.ui.PlatformUI; | |
27 | ||
28 | /** | |
29 | * <b><u>OpenExperimentHandler</u></b> | |
30 | * <p> | |
12c155f5 FC |
31 | */ |
32 | public class OpenExperimentHandler extends AbstractHandler { | |
33 | ||
34 | private TmfExperimentElement fExperiment = null; | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Validation | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | @Override | |
41 | public boolean isEnabled() { | |
42 | ||
43 | // Check if we are closing down | |
25e48683 | 44 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
6256d8ad | 45 | if (window == null) { |
12c155f5 | 46 | return false; |
6256d8ad | 47 | } |
12c155f5 FC |
48 | |
49 | // Get the selection | |
25e48683 FC |
50 | final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
51 | final IWorkbenchPart part = page.getActivePart(); | |
d5210347 PT |
52 | if (part == null) { |
53 | return false; | |
54 | } | |
25e48683 | 55 | final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); |
6256d8ad | 56 | if (selectionProvider == null) { |
1595249b | 57 | return false; |
6256d8ad | 58 | } |
25e48683 | 59 | final ISelection selection = selectionProvider.getSelection(); |
12c155f5 FC |
60 | |
61 | // Make sure there is only one selection and that it is an experiment | |
62 | fExperiment = null; | |
63 | if (selection instanceof TreeSelection) { | |
25e48683 | 64 | final TreeSelection sel = (TreeSelection) selection; |
12c155f5 | 65 | // There should be only one item selected as per the plugin.xml |
25e48683 | 66 | final Object element = sel.getFirstElement(); |
6256d8ad | 67 | if (element instanceof TmfExperimentElement) { |
12c155f5 | 68 | fExperiment = (TmfExperimentElement) element; |
6256d8ad | 69 | } |
12c155f5 FC |
70 | } |
71 | ||
72 | // We only enable opening from the Traces folder for now | |
cbac3b6b | 73 | return ((fExperiment != null) && (fExperiment.getTraces().size() > 0)); |
12c155f5 FC |
74 | } |
75 | ||
76 | // ------------------------------------------------------------------------ | |
77 | // Execution | |
78 | // ------------------------------------------------------------------------ | |
79 | ||
12c155f5 | 80 | @Override |
25e48683 | 81 | public Object execute(final ExecutionEvent event) throws ExecutionException { |
12c155f5 FC |
82 | |
83 | // Check if we are closing down | |
25e48683 | 84 | final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
6256d8ad | 85 | if (window == null) { |
67c53011 | 86 | return null; |
6256d8ad | 87 | } |
12c155f5 | 88 | |
67c53011 PT |
89 | // Check that the experiment is valid |
90 | if (fExperiment == null) { | |
91 | return null; | |
92 | } | |
12c155f5 | 93 | |
67c53011 | 94 | TmfOpenTraceHelper.openExperimentFromElement(fExperiment); |
12c155f5 FC |
95 | return null; |
96 | } | |
97 | ||
12c155f5 | 98 | } |