Commit | Line | Data |
---|---|---|
6e512b93 ASL |
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.lttng.ui.views.project.handlers; | |
14 | ||
15 | import org.eclipse.core.commands.ExecutionEvent; | |
16 | import org.eclipse.core.commands.ExecutionException; | |
17 | import org.eclipse.core.commands.IHandler; | |
18 | import org.eclipse.core.commands.IHandlerListener; | |
19 | import org.eclipse.jface.viewers.ISelection; | |
20 | import org.eclipse.jface.viewers.StructuredSelection; | |
21 | import org.eclipse.jface.wizard.WizardDialog; | |
22 | import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView; | |
23 | import org.eclipse.linuxtools.lttng.ui.views.project.dialogs.AddTraceWizard; | |
24 | import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngExperimentNode; | |
25 | import org.eclipse.swt.widgets.Shell; | |
26 | import org.eclipse.ui.IWorkbench; | |
27 | import org.eclipse.ui.IWorkbenchPage; | |
28 | import org.eclipse.ui.IWorkbenchWindow; | |
29 | import org.eclipse.ui.PlatformUI; | |
30 | ||
31 | /** | |
32 | * <b><u>SelectTracesHandler</u></b> | |
33 | * <p> | |
34 | * TODO: Implement me. Please. | |
35 | */ | |
36 | public class SelectTracesHandler implements IHandler { | |
37 | ||
38 | private LTTngExperimentNode fExperiment = null; | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Validation | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
d4011df2 | 44 | @Override |
6e512b93 ASL |
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 | // Check if we are in the Project View | |
53 | IWorkbenchPage page = window.getActivePage(); | |
54 | if (!(page.getActivePart() instanceof ProjectView)) | |
55 | return false; | |
56 | ||
57 | // Check that an experiment is selected | |
58 | ISelection selection = page.getSelection(ProjectView.ID); | |
59 | if (selection instanceof StructuredSelection) { | |
60 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
61 | fExperiment = (element instanceof LTTngExperimentNode) ? (LTTngExperimentNode) element : null; | |
62 | } | |
63 | ||
64 | return (fExperiment != null); | |
65 | } | |
66 | ||
67 | // Handled if we are in the ProjectView | |
d4011df2 | 68 | @Override |
6e512b93 ASL |
69 | public boolean isHandled() { |
70 | return true; | |
71 | } | |
72 | ||
73 | // ------------------------------------------------------------------------ | |
74 | // Execution | |
75 | // ------------------------------------------------------------------------ | |
76 | ||
d4011df2 | 77 | @Override |
6e512b93 ASL |
78 | public Object execute(ExecutionEvent event) throws ExecutionException { |
79 | ||
80 | // Open the trace addition wizard | |
81 | IWorkbench workbench = PlatformUI.getWorkbench(); | |
82 | Shell shell = workbench.getActiveWorkbenchWindow().getShell(); | |
83 | ||
84 | AddTraceWizard wizard = new AddTraceWizard(fExperiment.getProject(), fExperiment); | |
85 | wizard.init(PlatformUI.getWorkbench(), null); | |
86 | WizardDialog dialog = new WizardDialog(shell, wizard); | |
87 | dialog.open(); | |
88 | ||
89 | return null; | |
90 | } | |
91 | ||
d4011df2 | 92 | @Override |
6e512b93 ASL |
93 | public void dispose() { |
94 | // TODO Auto-generated method stub | |
95 | } | |
96 | ||
97 | // ------------------------------------------------------------------------ | |
98 | // IHandlerListener | |
99 | // ------------------------------------------------------------------------ | |
100 | ||
d4011df2 | 101 | @Override |
6e512b93 ASL |
102 | public void addHandlerListener(IHandlerListener handlerListener) { |
103 | // TODO Auto-generated method stub | |
104 | } | |
105 | ||
d4011df2 | 106 | @Override |
6e512b93 ASL |
107 | public void removeHandlerListener(IHandlerListener handlerListener) { |
108 | // TODO Auto-generated method stub | |
109 | } | |
110 | ||
111 | } |