1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.project
.handlers
;
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
;
34 * <b><u>NewExperimentHandler</u></b>
36 * TODO: Implement me. Please.
38 public class NewExperimentHandler
implements IHandler
{
40 private LTTngProjectNode fProject
= null;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 public boolean isEnabled() {
48 // Check if we are closing down
49 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
53 // Check if we are in the Project View
54 IWorkbenchPage page
= window
.getActivePage();
55 if (!(page
.getActivePart() instanceof ProjectView
))
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();
67 fProject
= (node
instanceof LTTngProjectNode
) ?
(LTTngProjectNode
) node
: null;
71 return (fProject
!= null && fProject
.isOpen() && fProject
.isLTTngProject());
74 // Handled if we are in the ProjectView
75 public boolean isHandled() {
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
83 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
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
);
91 if (dialog
.getReturnCode() == Window
.OK
) {
92 Object
[] experiments
= dialog
.getResult();
93 if (experiments
[0] instanceof IFolder
) {
94 experimentFolder
.addExperiment((IFolder
) experiments
[0]);
101 public void dispose() {
102 // TODO Auto-generated method stub
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
109 public void addHandlerListener(IHandlerListener handlerListener
) {
110 // TODO Auto-generated method stub
113 public void removeHandlerListener(IHandlerListener handlerListener
) {
114 // TODO Auto-generated method stub