1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.handlers
;
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
.internal
.lttng2
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.ICreateSessionDialog
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionGroup
;
30 import org
.eclipse
.ui
.IWorkbenchPage
;
34 * Command handler implementation to create a trace session.
37 * @author Bernd Hufmann
39 public class CreateSessionHandler
extends BaseControlViewHandler
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * The trace session group the command is to be executed on.
48 private TraceSessionGroup fSessionGroup
= null;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
55 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
59 final TraceSessionGroup sessionGroup
= fSessionGroup
;
61 // Open dialog box for the node name and address
62 final ICreateSessionDialog dialog
= TraceControlDialogFactory
.getInstance().getCreateSessionDialog();
63 dialog
.initialize(sessionGroup
);
65 if (dialog
.open() != Window
.OK
) {
69 Job job
= new Job(Messages
.TraceControl_CreateSessionJob
) {
71 protected IStatus
run(IProgressMonitor monitor
) {
73 sessionGroup
.createSession(dialog
.getParameters(), monitor
);
74 } catch (ExecutionException e
) {
75 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_CreateSessionFailure
, e
);
77 return Status
.OK_STATUS
;
89 public boolean isEnabled() {
91 // Get workbench page for the Control View
92 IWorkbenchPage page
= getWorkbenchPage();
97 TraceSessionGroup sessionGroup
= null;
99 // Check if the session group project is selected
100 ISelection selection
= page
.getSelection(ControlView
.ID
);
101 if (selection
instanceof StructuredSelection
) {
102 Object element
= ((StructuredSelection
) selection
).getFirstElement();
103 sessionGroup
= (element
instanceof TraceSessionGroup
) ?
(TraceSessionGroup
) element
: null;
106 boolean isEnabled
= sessionGroup
!= null;
109 fSessionGroup
= null;
111 fSessionGroup
= sessionGroup
;