1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 É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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.handlers
;
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
.tracecompass
.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
;
28 * Handler to programatically open a view
30 * @author Geneviève Bastien
32 public class OpenAnalysisOutputHandler
extends AbstractHandler
{
34 private TmfAnalysisOutputElement fOutputElement
;
37 public boolean isEnabled() {
38 /* Check if we are closing down */
39 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
44 /* Get the selection */
45 final IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
46 final IWorkbenchPart part
= page
.getActivePart();
50 final ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
51 if (selectionProvider
== null) {
54 final ISelection selection
= selectionProvider
.getSelection();
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
;
67 return (fOutputElement
!= null);
71 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 /* Check if we are closing down */
74 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
79 /* Check that the view is valid */
80 if (fOutputElement
== null) {
84 fOutputElement
.outputAnalysis();