1 /*******************************************************************************
2 * Copyright (c) 2009, 2010, 2011 Ericsson
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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.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
.jface
.wizard
.WizardDialog
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentElement
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectElement
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
.SelectTracesWizard
;
26 import org
.eclipse
.swt
.widgets
.Shell
;
27 import org
.eclipse
.ui
.IWorkbench
;
28 import org
.eclipse
.ui
.IWorkbenchPage
;
29 import org
.eclipse
.ui
.IWorkbenchPart
;
30 import org
.eclipse
.ui
.IWorkbenchWindow
;
31 import org
.eclipse
.ui
.PlatformUI
;
34 * <b><u>SelectTracesHandler</u></b>
37 public class SelectTracesHandler
extends AbstractHandler
{
39 private TmfExperimentElement fExperiment
= null;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 public boolean isEnabled() {
48 // Check if we are closing down
49 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
54 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
55 IWorkbenchPart part
= page
.getActivePart();
56 ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
57 if (selectionProvider
== null)
59 ISelection selection
= selectionProvider
.getSelection();
61 // Make sure there is only one selection and that it is an experiment
63 if (selection
instanceof TreeSelection
) {
64 TreeSelection sel
= (TreeSelection
) selection
;
65 // There should be only one item selected as per the plugin.xml
66 Object element
= sel
.getFirstElement();
67 if (element
instanceof TmfExperimentElement
) {
68 fExperiment
= (TmfExperimentElement
) element
;
72 return (fExperiment
!= null);
75 // ------------------------------------------------------------------------
77 // ------------------------------------------------------------------------
80 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
82 // Check if we are closing down
83 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
87 // Fire the Select Traces Wizard
88 IWorkbench workbench
= PlatformUI
.getWorkbench();
89 Shell shell
= workbench
.getActiveWorkbenchWindow().getShell();
91 TmfExperimentFolder experiments
= (TmfExperimentFolder
) fExperiment
.getParent();
92 TmfProjectElement project
= (TmfProjectElement
) experiments
.getParent();
93 SelectTracesWizard wizard
= new SelectTracesWizard(project
, fExperiment
);
94 wizard
.init(PlatformUI
.getWorkbench(), null);
95 WizardDialog dialog
= new WizardDialog(shell
, wizard
);