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
.internal
.lttng2
.ui
.views
.control
.handlers
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.core
.runtime
.jobs
.Job
;
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
.internal
.lttng2
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.ICreateSessionDialog
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionGroup
;
29 import org
.eclipse
.ui
.IWorkbenchPage
;
32 * <b><u>CreateSessionHandler</u></b>
34 * Command handler implementation to create a trace session.
37 public class CreateSessionHandler
extends BaseControlViewHandler
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 * The trace session group the command is to be executed on.
45 private TraceSessionGroup fSessionGroup
= null;
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
52 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
55 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
59 final TraceSessionGroup sessionGroup
= fSessionGroup
;
61 // Open dialog box for the node name and address
62 ICreateSessionDialog dialog
= TraceControlDialogFactory
.getInstance().getCreateSessionDialog();
63 dialog
.setTraceSessionGroup(sessionGroup
);
65 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 sessionGroup
.createSession(sessionName
, sessionPath
, monitor
);
77 } catch (ExecutionException e
) {
78 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_CreateSessionFailure
, e
);
80 return Status
.OK_STATUS
;
93 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
96 public boolean isEnabled() {
98 // Get workbench page for the Control View
99 IWorkbenchPage page
= getWorkbenchPage();
104 TraceSessionGroup sessionGroup
= null;
106 // Check if the session group project is selected
107 ISelection selection
= page
.getSelection(ControlView
.ID
);
108 if (selection
instanceof StructuredSelection
) {
109 Object element
= ((StructuredSelection
) selection
).getFirstElement();
110 sessionGroup
= (element
instanceof TraceSessionGroup
) ?
(TraceSessionGroup
) element
: null;
113 boolean isEnabled
= sessionGroup
!= null;
116 fSessionGroup
= null;
118 fSessionGroup
= sessionGroup
;