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
) {
72 final String sessionName
= dialog
.getSessionName();
73 final String sessionPath
= dialog
.isDefaultSessionPath() ?
null : dialog
.getSessionPath();
75 Job job
= new Job(Messages
.TraceControl_CreateSessionJob
) {
77 protected IStatus
run(IProgressMonitor monitor
) {
79 fSessionGroup
.createSession(sessionName
, sessionPath
, monitor
);
80 } catch (ExecutionException e
) {
81 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, e
.toString());
83 return Status
.OK_STATUS
;
94 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
97 public boolean isEnabled() {
100 // Check if we are closing down
101 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
102 if (window
== null) {
106 // Check if we are in the Project View
107 IWorkbenchPage page
= window
.getActivePage();
112 IWorkbenchPart part
= page
.getActivePart();
113 if (!(part
instanceof ControlView
)) {
117 // Check if the session group project is selected
118 ISelection selection
= page
.getSelection(ControlView
.ID
);
119 if (selection
instanceof StructuredSelection
) {
120 Object element
= ((StructuredSelection
) selection
).getFirstElement();
121 fSessionGroup
= (element
instanceof TraceSessionGroup
) ?
(TraceSessionGroup
) element
: null;
123 return fSessionGroup
!= null;