2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / handlers / OpenExperimentHandler.java
CommitLineData
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
13package org.eclipse.linuxtools.lttng.ui.views.project.handlers;
14
15import org.eclipse.core.commands.ExecutionEvent;
16import org.eclipse.core.commands.ExecutionException;
17import org.eclipse.core.commands.IHandler;
18import org.eclipse.core.commands.IHandlerListener;
f0fb9602
FC
19import org.eclipse.jface.viewers.ISelection;
20import org.eclipse.jface.viewers.StructuredSelection;
21import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView;
6e512b93 22import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngExperimentNode;
f0fb9602
FC
23import org.eclipse.ui.IWorkbenchPage;
24import org.eclipse.ui.IWorkbenchWindow;
6e512b93
ASL
25import org.eclipse.ui.PlatformUI;
26
27/**
28 * <b><u>OpenExperimentHandler</u></b>
29 * <p>
30 * TODO: Implement me. Please.
31 */
32public class OpenExperimentHandler implements IHandler {
33
34 private LTTngExperimentNode fExperiment = null;
35
36 // ------------------------------------------------------------------------
37 // Validation
38 // ------------------------------------------------------------------------
39
d4011df2 40 @Override
6e512b93 41 public boolean isEnabled() {
f0fb9602
FC
42 // Check if we are closing down
43 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
44 if (window == null)
45 return false;
46
47 // Check if a trace is selected
48 IWorkbenchPage page = window.getActivePage();
49 if (!(page.getActivePart() instanceof ProjectView))
50 return false;
51
52 // Check if a trace is selected
53 ISelection selection = page.getSelection(ProjectView.ID);
54 if (selection instanceof StructuredSelection) {
55 Object element = ((StructuredSelection) selection).getFirstElement();
56 fExperiment = (element instanceof LTTngExperimentNode) ? (LTTngExperimentNode) element : null;
57 }
58
6e512b93
ASL
59 return (fExperiment != null);
60 }
61
62 // Handled if we are in the ProjectView
d4011df2 63 @Override
6e512b93
ASL
64 public boolean isHandled() {
65 return true;
66 }
67
68 // ------------------------------------------------------------------------
69 // Execution
70 // ------------------------------------------------------------------------
71
d4011df2 72 @Override
6e512b93
ASL
73 public Object execute(ExecutionEvent event) throws ExecutionException {
74
f0fb9602
FC
75 // Set the selection to the project
76 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
77 ProjectView projectView = (ProjectView) page.getActivePart();
6e512b93 78
f0fb9602
FC
79 if (projectView != null) {
80 projectView.selectExperiment(fExperiment);
81 }
6e512b93 82
f0fb9602 83 return null;
2fbfb67b
FC
84 }
85
6e512b93
ASL
86 // ------------------------------------------------------------------------
87 // IHandlerListener
88 // ------------------------------------------------------------------------
89
d4011df2 90 @Override
6e512b93
ASL
91 public void addHandlerListener(IHandlerListener handlerListener) {
92 // TODO Auto-generated method stub
93 }
94
d4011df2 95 @Override
6e512b93
ASL
96 public void removeHandlerListener(IHandlerListener handlerListener) {
97 // TODO Auto-generated method stub
98 }
99
d4011df2 100 @Override
f0fb9602
FC
101 public void dispose() {
102 // TODO Auto-generated method stub
103
104 }
105
6e512b93 106}
This page took 0.034291 seconds and 5 git commands to generate.