(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / project / handlers / NewExperimentHandler.java
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
46 public boolean isEnabled() {
47
48 // Check if we are closing down
49 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
50 if (window == null)
51 return false;
52
53 // Check if we are in the Project View
54 IWorkbenchPage page = window.getActivePage();
55 if (!(page.getActivePart() instanceof ProjectView))
56 return false;
57
58 // Check if a project is selected
59 ISelection selection = page.getSelection(ProjectView.ID);
60 if (selection instanceof StructuredSelection) {
61 Object element = ((StructuredSelection) selection).getFirstElement();
62 if (element instanceof ILTTngProjectTreeNode) {
63 ILTTngProjectTreeNode node = (ILTTngProjectTreeNode) element;
64 while (node != null && !(node instanceof LTTngProjectNode)) {
65 node = node.getParent();
66 }
67 fProject = (node instanceof LTTngProjectNode) ? (LTTngProjectNode) node : null;
68 }
69 }
70
71 return (fProject != null && fProject.isOpen() && fProject.isLTTngProject());
72 }
73
74 // Handled if we are in the ProjectView
75 public boolean isHandled() {
76 return true;
77 }
78
79 // ------------------------------------------------------------------------
80 // Execution
81 // ------------------------------------------------------------------------
82
83 public Object execute(ExecutionEvent event) throws ExecutionException {
84
85 // Open the experiment creation dialog
86 LTTngExperimentFolderNode experimentFolder = fProject.getExperimentsFolder();
87 Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
88 NewExperimentDialog dialog = new NewExperimentDialog(shell, experimentFolder);
89 dialog.open();
90
91 if (dialog.getReturnCode() == Window.OK) {
92 Object[] experiments = dialog.getResult();
93 if (experiments[0] instanceof IFolder) {
94 experimentFolder.addExperiment((IFolder) experiments[0]);
95 }
96 }
97
98 return null;
99 }
100
101 public void dispose() {
102 // TODO Auto-generated method stub
103 }
104
105 // ------------------------------------------------------------------------
106 // IHandlerListener
107 // ------------------------------------------------------------------------
108
109 public void addHandlerListener(IHandlerListener handlerListener) {
110 // TODO Auto-generated method stub
111 }
112
113 public void removeHandlerListener(IHandlerListener handlerListener) {
114 // TODO Auto-generated method stub
115 }
116
117 }
This page took 0.032912 seconds and 5 git commands to generate.