tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / project / handlers / SelectTracesHandler.java
CommitLineData
12c155f5 1/*******************************************************************************
c8422608 2 * Copyright (c) 2009, 2013 Ericsson
d5210347 3 *
12c155f5
FC
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
d5210347 8 *
12c155f5
FC
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
d34665f9 13package org.eclipse.linuxtools.internal.tmf.ui.project.handlers;
12c155f5
FC
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.jface.viewers.ISelection;
1595249b 19import org.eclipse.jface.viewers.ISelectionProvider;
12c155f5
FC
20import org.eclipse.jface.viewers.TreeSelection;
21import org.eclipse.jface.wizard.WizardDialog;
22import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
23import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder;
24import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
25import org.eclipse.linuxtools.tmf.ui.project.wizards.SelectTracesWizard;
26import org.eclipse.swt.widgets.Shell;
27import org.eclipse.ui.IWorkbench;
28import org.eclipse.ui.IWorkbenchPage;
29import org.eclipse.ui.IWorkbenchPart;
30import org.eclipse.ui.IWorkbenchWindow;
31import org.eclipse.ui.PlatformUI;
32
33/**
34 * <b><u>SelectTracesHandler</u></b>
35 * <p>
36 */
37public class SelectTracesHandler extends AbstractHandler {
38
39 private TmfExperimentElement fExperiment = null;
40
41 // ------------------------------------------------------------------------
42 // Validation
43 // ------------------------------------------------------------------------
44
45 @Override
46 public boolean isEnabled() {
47
48 // Check if we are closing down
49 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
d5210347 50 if (window == null) {
12c155f5 51 return false;
d5210347 52 }
12c155f5
FC
53
54 // Get the selection
55 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
56 IWorkbenchPart part = page.getActivePart();
d5210347
PT
57 if (part == null) {
58 return false;
59 }
1595249b 60 ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
d5210347 61 if (selectionProvider == null) {
1595249b 62 return false;
d5210347 63 }
1595249b 64 ISelection selection = selectionProvider.getSelection();
12c155f5
FC
65
66 // Make sure there is only one selection and that it is an experiment
67 fExperiment = null;
68 if (selection instanceof TreeSelection) {
69 TreeSelection sel = (TreeSelection) selection;
d5efe032 70 // There should be only one item selected as per the plugin.xml
12c155f5
FC
71 Object element = sel.getFirstElement();
72 if (element instanceof TmfExperimentElement) {
d5efe032 73 fExperiment = (TmfExperimentElement) element;
12c155f5
FC
74 }
75 }
76
77 return (fExperiment != null);
78 }
79
80 // ------------------------------------------------------------------------
81 // Execution
82 // ------------------------------------------------------------------------
83
84 @Override
85 public Object execute(ExecutionEvent event) throws ExecutionException {
86
87 // Check if we are closing down
88 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
d5210347 89 if (window == null) {
12c155f5 90 return null;
d5210347 91 }
12c155f5
FC
92
93 // Fire the Select Traces Wizard
94 IWorkbench workbench = PlatformUI.getWorkbench();
95 Shell shell = workbench.getActiveWorkbenchWindow().getShell();
96
97 TmfExperimentFolder experiments = (TmfExperimentFolder) fExperiment.getParent();
98 TmfProjectElement project = (TmfProjectElement) experiments.getParent();
99 SelectTracesWizard wizard = new SelectTracesWizard(project, fExperiment);
100 wizard.init(PlatformUI.getWorkbench(), null);
101 WizardDialog dialog = new WizardDialog(shell, wizard);
102 dialog.open();
103
104 return null;
105 }
106
107}
This page took 0.08173 seconds and 5 git commands to generate.