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.linuxtools.tmf.ui.views.project.ProjectView; | |
21 | import org.eclipse.linuxtools.tmf.ui.views.project.model.TmfExperimentNode; | |
22 | import org.eclipse.ui.IWorkbenchPage; | |
23 | import org.eclipse.ui.IWorkbenchWindow; | |
24 | import org.eclipse.ui.PlatformUI; | |
25 | ||
26 | /** | |
27 | * <b><u>OpenExperimentHandler</u></b> | |
28 | * <p> | |
29 | * TODO: Implement me. Please. | |
30 | */ | |
31 | public class OpenExperimentHandler extends AbstractHandler { | |
32 | ||
33 | private TmfExperimentNode fExperiment = null; | |
34 | ||
35 | // ------------------------------------------------------------------------ | |
36 | // Validation | |
37 | // ------------------------------------------------------------------------ | |
38 | ||
9ccc6d01 | 39 | @Override |
abfad0aa FC |
40 | public boolean isEnabled() { |
41 | // Check if we are closing down | |
42 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
43 | if (window == null) | |
44 | return false; | |
45 | ||
46 | // Check if a trace is selected | |
47 | IWorkbenchPage page = window.getActivePage(); | |
48 | if (!(page.getActivePart() instanceof ProjectView)) | |
49 | return false; | |
50 | ||
51 | // Check if a trace is selected | |
52 | ISelection selection = page.getSelection(ProjectView.ID); | |
53 | if (selection instanceof StructuredSelection) { | |
54 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
55 | fExperiment = (element instanceof TmfExperimentNode) ? (TmfExperimentNode) element : null; | |
56 | } | |
57 | ||
58 | return (fExperiment != null); | |
59 | } | |
60 | ||
61 | // ------------------------------------------------------------------------ | |
62 | // Execution | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
66 | ||
67 | // Set the selection to the project | |
68 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
69 | ProjectView projectView = (ProjectView) page.getActivePart(); | |
70 | ||
71 | if (projectView != null) { | |
72 | projectView.selectExperiment(fExperiment); | |
73 | } | |
74 | ||
75 | return null; | |
76 | } | |
77 | ||
78 | } |