ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / OpenAnalysisOutputHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2013 É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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
14
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.TmfAnalysisOutputElement;
22 import org.eclipse.ui.IWorkbenchPage;
23 import org.eclipse.ui.IWorkbenchPart;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.PlatformUI;
26
27 /**
28 * Handler to programatically open a view
29 *
30 * @author Geneviève Bastien
31 */
32 public class OpenAnalysisOutputHandler extends AbstractHandler {
33
34 private TmfAnalysisOutputElement fOutputElement;
35
36 @Override
37 public boolean isEnabled() {
38 /* Check if we are closing down */
39 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
40 if (window == null) {
41 return false;
42 }
43
44 /* Get the selection */
45 final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
46 final IWorkbenchPart part = page.getActivePart();
47 if (part == null) {
48 return false;
49 }
50 final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
51 if (selectionProvider == null) {
52 return false;
53 }
54 final ISelection selection = selectionProvider.getSelection();
55
56 /* Make sure there is only one selection and that it is an analysis output */
57 fOutputElement = null;
58 if (selection instanceof TreeSelection) {
59 final TreeSelection sel = (TreeSelection) selection;
60 // There should be only one item selected as per the plugin.xml
61 final Object element = sel.getFirstElement();
62 if (element instanceof TmfAnalysisOutputElement) {
63 fOutputElement = (TmfAnalysisOutputElement) element;
64 }
65 }
66
67 return (fOutputElement != null);
68 }
69
70 @Override
71 public Object execute(ExecutionEvent event) throws ExecutionException {
72
73 /* Check if we are closing down */
74 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
75 if (window == null) {
76 return null;
77 }
78
79 /* Check that the view is valid */
80 if (fOutputElement == null) {
81 return null;
82 }
83
84 fOutputElement.outputAnalysis();
85
86 return null;
87 }
88
89 }
This page took 0.039813 seconds and 5 git commands to generate.