1 /**********************************************************************
2 * Copyright (c) 2014 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
.control
.ui
.views
.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
.control
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.ControlView
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.ISelectCommandScriptDialog
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionGroup
;
29 import org
.eclipse
.ui
.IWorkbenchPage
;
33 * Command handler implementation to execute commands of a command script.
36 * @author Bernd Hufmann
38 public class ExecuteCommandScriptHandler
extends BaseControlViewHandler
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * The trace session group the command is to be executed on.
47 private TraceSessionGroup fSessionGroup
= null;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
58 final TraceSessionGroup sessionGroup
= fSessionGroup
;
60 // Open dialog box for the node name and address
61 final ISelectCommandScriptDialog dialog
= TraceControlDialogFactory
.getInstance().getCommandScriptDialog();
63 if (dialog
.open() != Window
.OK
) {
67 Job job
= new Job(Messages
.TraceControl_ExecuteScriptJob
) {
69 protected IStatus
run(IProgressMonitor monitor
) {
71 sessionGroup
.executeCommands(monitor
, dialog
.getCommands());
72 } catch (ExecutionException e
) {
73 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_CreateSessionFailure
, e
);
75 return Status
.OK_STATUS
;
87 public boolean isEnabled() {
89 // Get workbench page for the Control View
90 IWorkbenchPage page
= getWorkbenchPage();
95 TraceSessionGroup sessionGroup
= null;
97 // Check if the session group project is selected
98 ISelection selection
= page
.getSelection(ControlView
.ID
);
99 if (selection
instanceof StructuredSelection
) {
100 Object element
= ((StructuredSelection
) selection
).getFirstElement();
101 sessionGroup
= (element
instanceof TraceSessionGroup
) ?
(TraceSessionGroup
) element
: null;
104 boolean isEnabled
= sessionGroup
!= null;
107 fSessionGroup
= null;
109 fSessionGroup
= sessionGroup
;