1 /*******************************************************************************
2 * Copyright (c) 2013 É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
.swt
.widgets
.Display
;
22 import org
.eclipse
.swt
.widgets
.MessageBox
;
23 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfAnalysisElement
;
24 import org
.eclipse
.ui
.IWorkbenchPage
;
25 import org
.eclipse
.ui
.IWorkbenchPart
;
26 import org
.eclipse
.ui
.IWorkbenchWindow
;
27 import org
.eclipse
.ui
.PlatformUI
;
30 * Handler for when user wants to open the analysis help text
32 * @author Geneviève Bastien
34 public class OpenAnalysisHelpHandler
extends AbstractHandler
{
36 private TmfAnalysisElement fAnalysis
;
39 public boolean isEnabled() {
40 // Check if we are closing down
41 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
47 final IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
48 final IWorkbenchPart part
= page
.getActivePart();
52 final ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
53 if (selectionProvider
== null) {
56 final ISelection selection
= selectionProvider
.getSelection();
58 // Make sure there is only one selection and that it is a trace
60 if (selection
instanceof TreeSelection
) {
61 final TreeSelection sel
= (TreeSelection
) selection
;
62 // There should be only one item selected as per the plugin.xml
63 final Object element
= sel
.getFirstElement();
64 if (element
instanceof TmfAnalysisElement
) {
65 fAnalysis
= (TmfAnalysisElement
) element
;
69 return (fAnalysis
!= null);
73 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
75 // Check if we are closing down
76 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
81 // Check that the trace is valid
82 if (fAnalysis
== null) {
86 Thread thread
= new Thread() {
89 displayHelpMsg(fAnalysis
.getHelpMessage());
98 private static void displayHelpMsg(final String errorMsg
) {
99 Display
.getDefault().asyncExec(new Runnable() {
103 * TODO: A message box is not the best place to show help.
104 * Something should be done with the Eclipse help
106 final MessageBox mb
= new MessageBox(PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell());
107 mb
.setText(Messages
.AnalysisModule_Help
);
108 mb
.setMessage(errorMsg
);