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.core.resources.IFolder; | |
20 | import org.eclipse.jface.viewers.ISelection; | |
21 | import org.eclipse.jface.viewers.StructuredSelection; | |
22 | import org.eclipse.jface.window.Window; | |
23 | import org.eclipse.linuxtools.lttng.ui.views.project.ProjectView; | |
24 | import org.eclipse.linuxtools.lttng.ui.views.project.dialogs.NewExperimentDialog; | |
25 | import org.eclipse.linuxtools.lttng.ui.views.project.model.ILTTngProjectTreeNode; | |
26 | import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngExperimentFolderNode; | |
27 | import org.eclipse.linuxtools.lttng.ui.views.project.model.LTTngProjectNode; | |
28 | import org.eclipse.swt.widgets.Shell; | |
29 | import org.eclipse.ui.IWorkbenchPage; | |
30 | import org.eclipse.ui.IWorkbenchWindow; | |
31 | import org.eclipse.ui.PlatformUI; | |
32 | ||
33 | /** | |
34 | * <b><u>NewExperimentHandler</u></b> | |
35 | * <p> | |
36 | * TODO: Implement me. Please. | |
37 | */ | |
38 | public class NewExperimentHandler implements IHandler { | |
39 | ||
40 | private LTTngProjectNode fProject = null; | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Validation | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
d4011df2 | 46 | @Override |
6e512b93 ASL |
47 | public boolean isEnabled() { |
48 | ||
49 | // Check if we are closing down | |
50 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
51 | if (window == null) | |
52 | return false; | |
53 | ||
54 | // Check if we are in the Project View | |
55 | IWorkbenchPage page = window.getActivePage(); | |
56 | if (!(page.getActivePart() instanceof ProjectView)) | |
57 | return false; | |
58 | ||
59 | // Check if a project is selected | |
60 | ISelection selection = page.getSelection(ProjectView.ID); | |
61 | if (selection instanceof StructuredSelection) { | |
62 | Object element = ((StructuredSelection) selection).getFirstElement(); | |
63 | if (element instanceof ILTTngProjectTreeNode) { | |
64 | ILTTngProjectTreeNode node = (ILTTngProjectTreeNode) element; | |
65 | while (node != null && !(node instanceof LTTngProjectNode)) { | |
66 | node = node.getParent(); | |
67 | } | |
68 | fProject = (node instanceof LTTngProjectNode) ? (LTTngProjectNode) node : null; | |
69 | } | |
70 | } | |
71 | ||
72 | return (fProject != null && fProject.isOpen() && fProject.isLTTngProject()); | |
73 | } | |
74 | ||
75 | // Handled if we are in the ProjectView | |
d4011df2 | 76 | @Override |
6e512b93 ASL |
77 | public boolean isHandled() { |
78 | return true; | |
79 | } | |
80 | ||
81 | // ------------------------------------------------------------------------ | |
82 | // Execution | |
83 | // ------------------------------------------------------------------------ | |
84 | ||
d4011df2 | 85 | @Override |
6e512b93 ASL |
86 | public Object execute(ExecutionEvent event) throws ExecutionException { |
87 | ||
88 | // Open the experiment creation dialog | |
89 | LTTngExperimentFolderNode experimentFolder = fProject.getExperimentsFolder(); | |
90 | Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); | |
91 | NewExperimentDialog dialog = new NewExperimentDialog(shell, experimentFolder); | |
92 | dialog.open(); | |
93 | ||
94 | if (dialog.getReturnCode() == Window.OK) { | |
95 | Object[] experiments = dialog.getResult(); | |
96 | if (experiments[0] instanceof IFolder) { | |
97 | experimentFolder.addExperiment((IFolder) experiments[0]); | |
98 | } | |
99 | } | |
100 | ||
101 | return null; | |
102 | } | |
103 | ||
d4011df2 | 104 | @Override |
6e512b93 ASL |
105 | public void dispose() { |
106 | // TODO Auto-generated method stub | |
107 | } | |
108 | ||
109 | // ------------------------------------------------------------------------ | |
110 | // IHandlerListener | |
111 | // ------------------------------------------------------------------------ | |
112 | ||
d4011df2 | 113 | @Override |
6e512b93 ASL |
114 | public void addHandlerListener(IHandlerListener handlerListener) { |
115 | // TODO Auto-generated method stub | |
116 | } | |
117 | ||
d4011df2 | 118 | @Override |
6e512b93 ASL |
119 | public void removeHandlerListener(IHandlerListener handlerListener) { |
120 | // TODO Auto-generated method stub | |
121 | } | |
122 | ||
123 | } |