1 /**********************************************************************
2 * Copyright (c) 2012 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 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.handlers
;
14 import org
.eclipse
.core
.commands
.AbstractHandler
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.core
.runtime
.jobs
.Job
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
23 import org
.eclipse
.jface
.window
.Window
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.ControlView
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.CreateSessionDialog
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.ICreateSessionDialog
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceSessionGroup
;
30 import org
.eclipse
.ui
.IWorkbenchPage
;
31 import org
.eclipse
.ui
.IWorkbenchPart
;
32 import org
.eclipse
.ui
.IWorkbenchWindow
;
33 import org
.eclipse
.ui
.PlatformUI
;
36 * <b><u>CreateSessionHandler</u></b>
38 * Command handler implementation to create a trace session.
41 public class CreateSessionHandler
extends AbstractHandler
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * The trace session group the command is to be executed on.
49 private TraceSessionGroup fSessionGroup
= null;
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
59 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
60 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
65 // Open dialog box for the node name and address
66 ICreateSessionDialog dialog
= new CreateSessionDialog(window
.getShell(), fSessionGroup
);
68 if (dialog
.open() == Window
.OK
) {
69 final String sessionName
= dialog
.getSessionName();
70 final String sessionPath
= dialog
.isDefaultSessionPath() ?
null : dialog
.getSessionPath();
72 Job job
= new Job(Messages
.TraceControl_CreateSessionJob
) {
74 protected IStatus
run(IProgressMonitor monitor
) {
76 fSessionGroup
.createSession(sessionName
, sessionPath
, monitor
);
77 } catch (ExecutionException e
) {
78 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, e
.toString());
80 return Status
.OK_STATUS
;
92 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
95 public boolean isEnabled() {
98 // Check if we are closing down
99 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
100 if (window
== null) {
104 // Check if we are in the Project View
105 IWorkbenchPage page
= window
.getActivePage();
110 IWorkbenchPart part
= page
.getActivePart();
111 if (!(part
instanceof ControlView
)) {
115 // Check if the session group project is selected
116 ISelection selection
= page
.getSelection(ControlView
.ID
);
117 if (selection
instanceof StructuredSelection
) {
118 Object element
= ((StructuredSelection
) selection
).getFirstElement();
119 fSessionGroup
= (element
instanceof TraceSessionGroup
) ?
(TraceSessionGroup
) element
: null;
121 return fSessionGroup
!= null;