2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / project / handlers / SelectTracesHandler.java
CommitLineData
abfad0aa
FC
1/*******************************************************************************
2 * Copyright (c) 2009, 2010 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
13package org.eclipse.linuxtools.tmf.ui.views.project.handlers;
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;
19import org.eclipse.jface.viewers.StructuredSelection;
20import org.eclipse.jface.wizard.WizardDialog;
21import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView;
22import org.eclipse.linuxtools.tmf.ui.views.project.dialogs.AddTraceWizard;
23import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode;
24import org.eclipse.swt.widgets.Shell;
25import org.eclipse.ui.IWorkbench;
26import org.eclipse.ui.IWorkbenchPage;
27import org.eclipse.ui.IWorkbenchWindow;
28import org.eclipse.ui.PlatformUI;
29
30/**
31 * <b><u>SelectTracesHandler</u></b>
32 * <p>
33 * TODO: Implement me. Please.
34 */
35public class SelectTracesHandler extends AbstractHandler {
36
37 private TmfExperimentNode fExperiment = null;
38
39 // ------------------------------------------------------------------------
40 // Validation
41 // ------------------------------------------------------------------------
42
9ccc6d01 43 @Override
abfad0aa
FC
44 public boolean isEnabled() {
45
46 // Check if we are closing down
47 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
48 if (window == null)
49 return false;
50
51 // Check if we are in the Project View
52 IWorkbenchPage page = window.getActivePage();
53 if (!(page.getActivePart() instanceof ProjectView))
54 return false;
55
56 // Check that an experiment is selected
57 ISelection selection = page.getSelection(ProjectView.ID);
58 if (selection instanceof StructuredSelection) {
59 Object element = ((StructuredSelection) selection).getFirstElement();
60 fExperiment = (element instanceof TmfExperimentNode) ? (TmfExperimentNode) element : null;
61 }
62
63 return (fExperiment != null);
64 }
65
66 // ------------------------------------------------------------------------
67 // Execution
68 // ------------------------------------------------------------------------
69
d4011df2 70 @Override
abfad0aa
FC
71 public Object execute(ExecutionEvent event) throws ExecutionException {
72
73 // Open the trace addition wizard
74 IWorkbench workbench = PlatformUI.getWorkbench();
75 Shell shell = workbench.getActiveWorkbenchWindow().getShell();
76
77 AddTraceWizard wizard = new AddTraceWizard(fExperiment.getProject(), fExperiment);
78 wizard.init(PlatformUI.getWorkbench(), null);
79 WizardDialog dialog = new WizardDialog(shell, wizard);
80 dialog.open();
81
82 return null;
83 }
84
85}
This page took 0.026625 seconds and 5 git commands to generate.