1 /**********************************************************************
2 * Copyright (c) 2012, 2015 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
.tracecompass
.internal
.lttng2
.control
.ui
.views
.handlers
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
20 import org
.eclipse
.core
.commands
.ExecutionEvent
;
21 import org
.eclipse
.core
.commands
.ExecutionException
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.IStatus
;
24 import org
.eclipse
.core
.runtime
.Status
;
25 import org
.eclipse
.core
.runtime
.jobs
.Job
;
26 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
27 import org
.eclipse
.jface
.viewers
.ISelection
;
28 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
29 import org
.eclipse
.jface
.window
.Window
;
30 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.IGetEventInfoDialog
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.UstProviderComponent
;
43 import org
.eclipse
.ui
.IWorkbenchPage
;
47 * Command handler implementation to assign events to a session and channel and enable/configure them.
48 * This is done on the trace provider level.
51 * @author Bernd Hufmann
53 public class AssignEventHandler
extends BaseControlViewHandler
{
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * The command execution parameter.
62 private Parameter fParam
;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
71 // Make a copy for thread safety
72 Parameter tmpParam
= null;
76 if (tmpParam
== null) {
79 tmpParam
= new Parameter(tmpParam
);
83 final Parameter param
= tmpParam
;
85 // Open dialog box to retrieve the session and channel where the events should be enabled in.
86 final IGetEventInfoDialog dialog
= TraceControlDialogFactory
.getInstance().getGetEventInfoDialog();
87 dialog
.setIsKernel(param
.isKernel());
88 dialog
.setSessions(param
.getSessions());
90 if (dialog
.open() != Window
.OK
) {
94 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
96 protected IStatus
run(IProgressMonitor monitor
) {
98 Exception error
= null;
99 TraceSessionComponent session
= dialog
.getSession();
101 List
<String
> eventNames
= new ArrayList
<>();
102 List
<BaseEventComponent
> events
= param
.getEvents();
103 // Create list of event names
104 for (Iterator
<BaseEventComponent
> iterator
= events
.iterator(); iterator
.hasNext();) {
105 BaseEventComponent baseEvent
= iterator
.next();
106 eventNames
.add(baseEvent
.getName());
109 TraceChannelComponent channel
= dialog
.getChannel();
110 if (channel
== null) {
111 // enable events on default channel (which will be created by lttng-tools)
112 session
.enableEvents(eventNames
, param
.isKernel(), dialog
.getFilterExpression(), monitor
);
114 channel
.enableEvents(eventNames
, dialog
.getFilterExpression(), monitor
);
117 } catch (ExecutionException e
) {
121 // refresh in all cases
122 if (session
!= null) {
123 refresh(new CommandParameter(session
));
127 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_EnableEventsFailure
, error
);
129 return Status
.OK_STATUS
;
139 public boolean isEnabled() {
140 ArrayList
<BaseEventComponent
> events
= new ArrayList
<>();
141 TraceSessionComponent
[] sessions
= null;
142 Boolean isKernel
= null;
144 // Get workbench page for the Control View
145 IWorkbenchPage page
= getWorkbenchPage();
150 // Check if one or more session are selected
151 ISelection selection
= page
.getSelection(ControlView
.ID
);
152 if (selection
instanceof StructuredSelection
) {
154 StructuredSelection structered
= ((StructuredSelection
) selection
);
155 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
156 Object element
= iterator
.next();
157 if (element
instanceof BaseEventComponent
) {
158 BaseEventComponent event
= (BaseEventComponent
) element
;
159 ITraceControlComponent provider
= event
.getParent();
161 // check for kernel or UST provider
162 boolean temp
= false;
163 if (provider
instanceof KernelProviderComponent
) {
165 } else if (provider
instanceof UstProviderComponent
) {
170 if (isKernel
== null) {
171 isKernel
= Boolean
.valueOf(temp
);
173 // don't mix events from Kernel and UST provider
174 if (isKernel
.booleanValue() != temp
) {
179 // Add BaseEventComponents
182 if (sessions
== null) {
183 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
184 sessions
= root
.getSessions();
190 boolean isEnabled
= ((!events
.isEmpty()) && (sessions
!= null) && (sessions
.length
> 0));
192 // To avoid compiler warnings check for null even if isKernel is always not null when used below
193 if (isKernel
== null) {
201 fParam
= new Parameter(NonNullUtils
.checkNotNull(sessions
), events
, isKernel
);
210 * Class containing parameter for the command execution.
213 private static final class Parameter
{
216 * The list of event components the command is to be executed on.
218 private final List
<BaseEventComponent
> fEvents
;
221 * The list of available sessions.
223 private final TraceSessionComponent
[] fSessions
;
226 * Flag for indicating Kernel or UST.
228 private final boolean fIsKernel
;
233 * @param sessions - a array of trace sessions
234 * @param events - a lists of events to enable
235 * @param isKernel - domain (true for kernel or UST)
237 public Parameter(TraceSessionComponent
[] sessions
, List
<BaseEventComponent
> events
, boolean isKernel
) {
238 fSessions
= NonNullUtils
.checkNotNull(Arrays
.copyOf(sessions
, sessions
.length
));
239 fEvents
= new ArrayList
<>();
240 fEvents
.addAll(events
);
241 fIsKernel
= isKernel
;
246 * @param other - a parameter to copy
248 public Parameter(Parameter other
) {
249 this(other
.fSessions
, other
.fEvents
, other
.fIsKernel
);
252 public TraceSessionComponent
[] getSessions() {
256 public List
<BaseEventComponent
> getEvents() {
260 public boolean isKernel() {