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 java
.util
.ArrayList
;
15 import java
.util
.Iterator
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.commands
.AbstractHandler
;
19 import org
.eclipse
.core
.commands
.ExecutionEvent
;
20 import org
.eclipse
.core
.commands
.ExecutionException
;
21 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Status
;
24 import org
.eclipse
.core
.runtime
.jobs
.Job
;
25 import org
.eclipse
.jface
.viewers
.ISelection
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.jface
.window
.Window
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.ControlView
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.GetEventInfoDialog
;
32 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.IGetEventInfoDialog
;
33 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
34 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
35 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
36 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
37 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
38 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
39 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.UstProviderComponent
;
40 import org
.eclipse
.ui
.IWorkbenchPage
;
41 import org
.eclipse
.ui
.IWorkbenchPart
;
42 import org
.eclipse
.ui
.IWorkbenchWindow
;
43 import org
.eclipse
.ui
.PlatformUI
;
46 * <b><u>EnableEventHandler</u></b>
48 * Command handler implementation to assign events to a session and channel and enable/configure them.
49 * This is done on the trace provider level.
52 public class AssignEventHandler
extends AbstractHandler
{
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 * The list of event components the command is to be executed on.
60 private List
<BaseEventComponent
> fEvents
= new ArrayList
<BaseEventComponent
>();
63 * The list of available sessions.
65 private TraceSessionComponent
[] fSessions
;
68 * Flag for indicating Kernel or UST.
70 Boolean fIsKernel
= null;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
78 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
81 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
83 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
89 // Open dialog box to retrieve the session and channel where the events should be enabled in.
90 final IGetEventInfoDialog dialog
= new GetEventInfoDialog(window
.getShell(), fIsKernel
, fSessions
);
92 if (dialog
.open() != Window
.OK
) {
96 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
98 protected IStatus
run(IProgressMonitor monitor
) {
100 String errorString
= null;
102 List
<String
> eventNames
= new ArrayList
<String
>();
103 // Create list of event names
104 for (Iterator
<BaseEventComponent
> iterator
= fEvents
.iterator(); iterator
.hasNext();) {
105 BaseEventComponent event
= (BaseEventComponent
) iterator
.next();
106 eventNames
.add(event
.getName());
109 TraceChannelComponent channel
= dialog
.getChannel();
110 if (channel
== null) {
111 // enable events on default channel (which will be created by lttng-tools)
112 dialog
.getSession().enableEvent(eventNames
, fIsKernel
, monitor
);
114 channel
.enableEvent(eventNames
, monitor
);
117 } catch (ExecutionException e
) {
118 errorString
= e
.toString() + "\n"; //$NON-NLS-1$
121 // get session configuration in all cases
123 dialog
.getSession().getConfigurationFromNode(monitor
);
124 } catch (ExecutionException e
) {
125 if (errorString
== null) {
126 errorString
= new String();
128 errorString
+= Messages
.TraceControl_ListSessionFailure
+ ": " + e
.toString(); //$NON-NLS-1$
131 if (errorString
!= null) {
132 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, errorString
);
134 return Status
.OK_STATUS
;
144 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
147 public boolean isEnabled() {
152 // Check if we are closing down
153 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
154 if (window
== null) {
158 // Check if we are in the Project View
159 IWorkbenchPage page
= window
.getActivePage();
164 IWorkbenchPart part
= page
.getActivePart();
165 if (!(part
instanceof ControlView
)) {
169 // Check if one or more session are selected
170 ISelection selection
= page
.getSelection(ControlView
.ID
);
171 if (selection
instanceof StructuredSelection
) {
173 StructuredSelection structered
= ((StructuredSelection
) selection
);
174 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
175 Object element
= (Object
) iterator
.next();
176 if (element
instanceof BaseEventComponent
) {
177 BaseEventComponent event
= (BaseEventComponent
) element
;
178 ITraceControlComponent provider
= event
.getParent();
180 // check for kernel or UST provider
181 boolean temp
= false;
182 if (provider
instanceof KernelProviderComponent
) {
184 } else if (provider
instanceof UstProviderComponent
) {
189 if (fIsKernel
== null) {
190 fIsKernel
= Boolean
.valueOf(temp
);
192 // don't mix events from Kernel and UST provider
193 if (fIsKernel
.booleanValue() != temp
) {
198 // Add BaseEventComponents
201 if (fSessions
== null) {
202 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
203 fSessions
= root
.getSessions();
208 return ((fEvents
.size() > 0) && (fSessions
!= null) && (fSessions
.length
> 0));