1 /**********************************************************************
2 * Copyright (c) 2012, 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 * 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
.jface
.viewers
.ISelection
;
27 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
28 import org
.eclipse
.jface
.window
.Window
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
31 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.IGetEventInfoDialog
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.BaseEventComponent
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.KernelProviderComponent
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
40 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.UstProviderComponent
;
41 import org
.eclipse
.ui
.IWorkbenchPage
;
45 * Command handler implementation to assign events to a session and channel and enable/configure them.
46 * This is done on the trace provider level.
49 * @author Bernd Hufmann
51 public class AssignEventHandler
extends BaseControlViewHandler
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * The command execution parameter.
60 private Parameter fParam
;
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
67 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
71 // Make a copy for thread safety
72 final Parameter param
= new Parameter(fParam
);
74 // Open dialog box to retrieve the session and channel where the events should be enabled in.
75 final IGetEventInfoDialog dialog
= TraceControlDialogFactory
.getInstance().getGetEventInfoDialog();
76 dialog
.setIsKernel(param
.isKernel());
77 dialog
.setSessions(param
.getSessions());
79 if (dialog
.open() != Window
.OK
) {
83 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
85 protected IStatus
run(IProgressMonitor monitor
) {
87 Exception error
= null;
90 List
<String
> eventNames
= new ArrayList
<>();
91 List
<BaseEventComponent
> events
= param
.getEvents();
92 // Create list of event names
93 for (Iterator
<BaseEventComponent
> iterator
= events
.iterator(); iterator
.hasNext();) {
94 BaseEventComponent baseEvent
= iterator
.next();
95 eventNames
.add(baseEvent
.getName());
98 TraceChannelComponent channel
= dialog
.getChannel();
99 if (channel
== null) {
100 // enable events on default channel (which will be created by lttng-tools)
101 dialog
.getSession().enableEvents(eventNames
, param
.isKernel(), dialog
.getFilterExpression(), monitor
);
103 channel
.enableEvents(eventNames
, dialog
.getFilterExpression(), monitor
);
106 } catch (ExecutionException e
) {
110 // refresh in all cases
111 refresh(new CommandParameter(dialog
.getSession()));
114 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_EnableEventsFailure
, error
);
116 return Status
.OK_STATUS
;
129 public boolean isEnabled() {
130 ArrayList
<BaseEventComponent
> events
= new ArrayList
<>();
131 TraceSessionComponent
[] sessions
= null;
132 Boolean isKernel
= null;
134 // Get workbench page for the Control View
135 IWorkbenchPage page
= getWorkbenchPage();
140 // Check if one or more session are selected
141 ISelection selection
= page
.getSelection(ControlView
.ID
);
142 if (selection
instanceof StructuredSelection
) {
144 StructuredSelection structered
= ((StructuredSelection
) selection
);
145 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
146 Object element
= iterator
.next();
147 if (element
instanceof BaseEventComponent
) {
148 BaseEventComponent event
= (BaseEventComponent
) element
;
149 ITraceControlComponent provider
= event
.getParent();
151 // check for kernel or UST provider
152 boolean temp
= false;
153 if (provider
instanceof KernelProviderComponent
) {
155 } else if (provider
instanceof UstProviderComponent
) {
160 if (isKernel
== null) {
161 isKernel
= Boolean
.valueOf(temp
);
163 // don't mix events from Kernel and UST provider
164 if (isKernel
.booleanValue() != temp
) {
169 // Add BaseEventComponents
172 if (sessions
== null) {
173 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
174 sessions
= root
.getSessions();
180 boolean isEnabled
= ((!events
.isEmpty()) && (sessions
!= null) && (sessions
.length
> 0));
182 // To avoid compiler warnings check for null even if isKernel is always not null when used below
183 if (isKernel
== null) {
191 fParam
= new Parameter(sessions
, events
, isKernel
);
200 * Class containing parameter for the command execution.
202 private static final class Parameter
{
205 * The list of event components the command is to be executed on.
207 private final List
<BaseEventComponent
> fEvents
;
210 * The list of available sessions.
212 private final TraceSessionComponent
[] fSessions
;
215 * Flag for indicating Kernel or UST.
217 private final boolean fIsKernel
;
222 * @param sessions - a array of trace sessions
223 * @param events - a lists of events to enable
224 * @param isKernel - domain (true for kernel or UST)
226 public Parameter(TraceSessionComponent
[] sessions
, List
<BaseEventComponent
> events
, boolean isKernel
) {
227 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
228 fEvents
= new ArrayList
<>();
229 fEvents
.addAll(events
);
230 fIsKernel
= isKernel
;
235 * @param other - a parameter to copy
237 public Parameter(Parameter other
) {
238 this(other
.fSessions
, other
.fEvents
, other
.fIsKernel
);
241 public TraceSessionComponent
[] getSessions() {
245 public List
<BaseEventComponent
> getEvents() {
249 public boolean isKernel() {