Commit | Line | Data |
---|---|---|
12c155f5 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010, 2011 Ericsson | |
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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.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.TreeSelection; | |
20 | import org.eclipse.jface.wizard.WizardDialog; | |
21 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; | |
22 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; | |
23 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; | |
24 | import org.eclipse.linuxtools.tmf.ui.project.wizards.SelectTracesWizard; | |
25 | import org.eclipse.swt.widgets.Shell; | |
26 | import org.eclipse.ui.IWorkbench; | |
27 | import org.eclipse.ui.IWorkbenchPage; | |
28 | import org.eclipse.ui.IWorkbenchPart; | |
29 | import org.eclipse.ui.IWorkbenchWindow; | |
30 | import org.eclipse.ui.PlatformUI; | |
31 | ||
32 | /** | |
33 | * <b><u>SelectTracesHandler</u></b> | |
34 | * <p> | |
35 | */ | |
36 | public class SelectTracesHandler extends AbstractHandler { | |
37 | ||
38 | private TmfExperimentElement fExperiment = null; | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Validation | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
44 | @Override | |
45 | public boolean isEnabled() { | |
46 | ||
47 | // Check if we are closing down | |
48 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
49 | if (window == null) | |
50 | return false; | |
51 | ||
52 | // Get the selection | |
53 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
54 | IWorkbenchPart part = page.getActivePart(); | |
55 | ISelection selection = part.getSite().getSelectionProvider().getSelection(); | |
56 | ||
57 | // Make sure there is only one selection and that it is an experiment | |
58 | fExperiment = null; | |
59 | if (selection instanceof TreeSelection) { | |
60 | TreeSelection sel = (TreeSelection) selection; | |
61 | // There should be only one item selected as per the plugin.xml | |
62 | Object element = sel.getFirstElement(); | |
63 | if (element instanceof TmfExperimentElement) { | |
64 | fExperiment = (TmfExperimentElement) element; | |
65 | } | |
66 | } | |
67 | ||
68 | return (fExperiment != null); | |
69 | } | |
70 | ||
71 | // ------------------------------------------------------------------------ | |
72 | // Execution | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
75 | @Override | |
76 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
77 | ||
78 | // Check if we are closing down | |
79 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
80 | if (window == null) | |
81 | return null; | |
82 | ||
83 | // Fire the Select Traces Wizard | |
84 | IWorkbench workbench = PlatformUI.getWorkbench(); | |
85 | Shell shell = workbench.getActiveWorkbenchWindow().getShell(); | |
86 | ||
87 | TmfExperimentFolder experiments = (TmfExperimentFolder) fExperiment.getParent(); | |
88 | TmfProjectElement project = (TmfProjectElement) experiments.getParent(); | |
89 | SelectTracesWizard wizard = new SelectTracesWizard(project, fExperiment); | |
90 | wizard.init(PlatformUI.getWorkbench(), null); | |
91 | WizardDialog dialog = new WizardDialog(shell, wizard); | |
92 | dialog.open(); | |
93 | ||
94 | return null; | |
95 | } | |
96 | ||
97 | } |