1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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
.linuxtools
.internal
.lttng2
.ui
.views
.control
.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
.linuxtools
.internal
.lttng2
.ui
.Activator
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.IGetEventInfoDialog
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
40 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.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 // ------------------------------------------------------------------------
57 * The command execution parameter.
59 private Parameter fParam
;
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
67 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
70 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
74 // Make a copy for thread safety
75 final Parameter param
= new Parameter(fParam
);
77 // Open dialog box to retrieve the session and channel where the events should be enabled in.
78 final IGetEventInfoDialog dialog
= TraceControlDialogFactory
.getInstance().getGetEventInfoDialog();
79 dialog
.setIsKernel(param
.isKernel());
80 dialog
.setSessions(param
.getSessions());
82 if (dialog
.open() != Window
.OK
) {
86 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
88 protected IStatus
run(IProgressMonitor monitor
) {
90 Exception error
= null;
93 List
<String
> eventNames
= new ArrayList
<String
>();
94 List
<BaseEventComponent
> events
= param
.getEvents();
95 // Create list of event names
96 for (Iterator
<BaseEventComponent
> iterator
= events
.iterator(); iterator
.hasNext();) {
97 BaseEventComponent baseEvent
= iterator
.next();
98 eventNames
.add(baseEvent
.getName());
101 TraceChannelComponent channel
= dialog
.getChannel();
102 if (channel
== null) {
103 // enable events on default channel (which will be created by lttng-tools)
104 dialog
.getSession().enableEvents(eventNames
, param
.isKernel(), dialog
.getFilterExpression(), monitor
);
106 channel
.enableEvents(eventNames
, dialog
.getFilterExpression(), monitor
);
109 } catch (ExecutionException e
) {
113 // refresh in all cases
114 refresh(new CommandParameter(dialog
.getSession()));
117 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_EnableEventsFailure
, error
);
119 return Status
.OK_STATUS
;
133 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
136 public boolean isEnabled() {
137 ArrayList
<BaseEventComponent
> events
= new ArrayList
<BaseEventComponent
>();
138 TraceSessionComponent
[] sessions
= null;
139 Boolean isKernel
= null;
141 // Get workbench page for the Control View
142 IWorkbenchPage page
= getWorkbenchPage();
147 // Check if one or more session are selected
148 ISelection selection
= page
.getSelection(ControlView
.ID
);
149 if (selection
instanceof StructuredSelection
) {
151 StructuredSelection structered
= ((StructuredSelection
) selection
);
152 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
153 Object element
= iterator
.next();
154 if (element
instanceof BaseEventComponent
) {
155 BaseEventComponent event
= (BaseEventComponent
) element
;
156 ITraceControlComponent provider
= event
.getParent();
158 // check for kernel or UST provider
159 boolean temp
= false;
160 if (provider
instanceof KernelProviderComponent
) {
162 } else if (provider
instanceof UstProviderComponent
) {
167 if (isKernel
== null) {
168 isKernel
= Boolean
.valueOf(temp
);
170 // don't mix events from Kernel and UST provider
171 if (isKernel
.booleanValue() != temp
) {
176 // Add BaseEventComponents
179 if (sessions
== null) {
180 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
181 sessions
= root
.getSessions();
187 boolean isEnabled
= ((!events
.isEmpty()) && (sessions
!= null) && (sessions
.length
> 0));
189 // To avoid compiler warnings check for null even if isKernel is always not null when used below
190 if (isKernel
== null) {
198 fParam
= new Parameter(sessions
, events
, isKernel
);
207 * Class containing parameter for the command execution.
209 final static private class Parameter
{
212 * The list of event components the command is to be executed on.
214 private final List
<BaseEventComponent
> fEvents
;
217 * The list of available sessions.
219 final private TraceSessionComponent
[] fSessions
;
222 * Flag for indicating Kernel or UST.
224 final private boolean fIsKernel
;
229 * @param sessions - a array of trace sessions
230 * @param events - a lists of events to enable
231 * @param isKernel - domain (true for kernel or UST)
233 public Parameter(TraceSessionComponent
[] sessions
, List
<BaseEventComponent
> events
, boolean isKernel
) {
234 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
235 fEvents
= new ArrayList
<BaseEventComponent
>();
236 fEvents
.addAll(events
);
237 fIsKernel
= isKernel
;
242 * @param other - a parameter to copy
244 public Parameter(Parameter other
) {
245 this(other
.fSessions
, other
.fEvents
, other
.fIsKernel
);
248 public TraceSessionComponent
[] getSessions() {
252 public List
<BaseEventComponent
> getEvents() {
256 public boolean isKernel() {