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
.NonNull
;
27 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
28 import org
.eclipse
.jface
.viewers
.ISelection
;
29 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
30 import org
.eclipse
.jface
.window
.Window
;
31 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.IGetEventInfoDialog
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
41 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
42 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
43 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.UstProviderComponent
;
44 import org
.eclipse
.ui
.IWorkbenchPage
;
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 * @author Bernd Hufmann
54 public class AssignEventHandler
extends BaseControlViewHandler
{
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * The command execution parameter.
63 private Parameter fParam
;
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
72 // Make a copy for thread safety
73 Parameter tmpParam
= null;
77 if (tmpParam
== null) {
80 tmpParam
= new Parameter(tmpParam
);
84 final Parameter param
= tmpParam
;
86 // Open dialog box to retrieve the session and channel where the events should be enabled in.
87 final IGetEventInfoDialog dialog
= TraceControlDialogFactory
.getInstance().getGetEventInfoDialog();
88 dialog
.setIsKernel(param
.isKernel());
89 dialog
.setSessions(param
.getSessions());
91 if (dialog
.open() != Window
.OK
) {
95 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
97 protected IStatus
run(IProgressMonitor monitor
) {
99 Exception error
= null;
100 TraceSessionComponent session
= dialog
.getSession();
102 List
<String
> eventNames
= new ArrayList
<>();
103 List
<BaseEventComponent
> events
= param
.getEvents();
104 // Create list of event names
105 for (Iterator
<BaseEventComponent
> iterator
= events
.iterator(); iterator
.hasNext();) {
106 BaseEventComponent baseEvent
= iterator
.next();
107 eventNames
.add(baseEvent
.getName());
110 TraceChannelComponent channel
= dialog
.getChannel();
111 if (channel
== null) {
112 // enable events on default channel (which will be created by lttng-tools)
113 session
.enableEvents(eventNames
, param
.isKernel(), dialog
.getFilterExpression(), monitor
);
115 channel
.enableEvents(eventNames
, dialog
.getFilterExpression(), monitor
);
118 } catch (ExecutionException e
) {
122 // refresh in all cases
123 if (session
!= null) {
124 refresh(new CommandParameter(session
));
128 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_EnableEventsFailure
, error
);
130 return Status
.OK_STATUS
;
140 public boolean isEnabled() {
141 @NonNull ArrayList
<@NonNull BaseEventComponent
> events
= new ArrayList
<>();
142 @NonNull TraceSessionComponent
[] sessions
= null;
143 Boolean isKernel
= null;
145 // Get workbench page for the Control View
146 IWorkbenchPage page
= getWorkbenchPage();
151 // Check if one or more session are selected
152 ISelection selection
= page
.getSelection(ControlView
.ID
);
153 if (selection
instanceof StructuredSelection
) {
155 StructuredSelection structered
= ((StructuredSelection
) selection
);
156 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
157 Object element
= iterator
.next();
158 if (element
instanceof BaseEventComponent
) {
159 BaseEventComponent event
= (BaseEventComponent
) element
;
160 ITraceControlComponent provider
= event
.getParent();
162 // check for kernel or UST provider
163 boolean temp
= false;
164 if (provider
instanceof KernelProviderComponent
) {
166 } else if (provider
instanceof UstProviderComponent
) {
171 if (isKernel
== null) {
172 isKernel
= Boolean
.valueOf(temp
);
174 // don't mix events from Kernel and UST provider
175 if (isKernel
.booleanValue() != temp
) {
180 // Add BaseEventComponents
183 if (sessions
== null) {
184 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
185 sessions
= root
.getSessions();
191 boolean isEnabled
= ((!events
.isEmpty()) && (sessions
!= null) && (sessions
.length
> 0));
193 // To avoid compiler warnings check for null even if isKernel is always not null when used below
194 if (isKernel
== null) {
202 fParam
= new Parameter(NonNullUtils
.checkNotNull(sessions
), events
, isKernel
);
211 * Class containing parameter for the command execution.
214 private static final class Parameter
{
217 * The list of event components the command is to be executed on.
219 private final List
<BaseEventComponent
> fEvents
;
222 * The list of available sessions.
224 private final @NonNull TraceSessionComponent
[] fSessions
;
227 * Flag for indicating Kernel or UST.
229 private final boolean fIsKernel
;
234 * @param sessions - a array of trace sessions
235 * @param events - a lists of events to enable
236 * @param isKernel - domain (true for kernel or UST)
238 public Parameter(@NonNull TraceSessionComponent
[] sessions
, List
<BaseEventComponent
> events
, boolean isKernel
) {
239 fSessions
= NonNullUtils
.checkNotNull(Arrays
.copyOf(sessions
, sessions
.length
));
240 fEvents
= new ArrayList
<>();
241 fEvents
.addAll(events
);
242 fIsKernel
= isKernel
;
247 * @param other - a parameter to copy
249 public Parameter(Parameter other
) {
250 this(other
.fSessions
, other
.fEvents
, other
.fIsKernel
);
253 public TraceSessionComponent
[] getSessions() {
257 public List
<BaseEventComponent
> getEvents() {
261 public boolean isKernel() {