Commit | Line | Data |
---|---|---|
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 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.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.StructuredSelection; | |
20 | import org.eclipse.jface.wizard.WizardDialog; | |
21 | import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView; | |
22 | import org.eclipse.linuxtools.tmf.ui.views.project.dialogs.AddTraceWizard; | |
23 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode; | |
24 | import org.eclipse.swt.widgets.Shell; | |
25 | import org.eclipse.ui.IWorkbench; | |
26 | import org.eclipse.ui.IWorkbenchPage; | |
27 | import org.eclipse.ui.IWorkbenchWindow; | |
28 | import org.eclipse.ui.PlatformUI; | |
29 | ||
30 | /** | |
31 | * <b><u>SelectTracesHandler</u></b> | |
32 | * <p> | |
33 | * TODO: Implement me. Please. | |
34 | */ | |
35 | public 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 | ||
70 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
71 | ||
72 | // Open the trace addition wizard | |
73 | IWorkbench workbench = PlatformUI.getWorkbench(); | |
74 | Shell shell = workbench.getActiveWorkbenchWindow().getShell(); | |
75 | ||
76 | AddTraceWizard wizard = new AddTraceWizard(fExperiment.getProject(), fExperiment); | |
77 | wizard.init(PlatformUI.getWorkbench(), null); | |
78 | WizardDialog dialog = new WizardDialog(shell, wizard); | |
79 | dialog.open(); | |
80 | ||
81 | return null; | |
82 | } | |
83 | ||
84 | } |