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
.internal
.lttng2
.ui
.views
.control
.handlers
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Arrays
;
16 import java
.util
.Iterator
;
17 import java
.util
.List
;
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
.internal
.lttng2
.ui
.Activator
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.IGetEventInfoDialog
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
35 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
36 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
37 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
38 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
39 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.UstProviderComponent
;
40 import org
.eclipse
.ui
.IWorkbenchPage
;
44 * Command handler implementation to assign events to a session and channel and enable/configure them.
45 * This is done on the trace provider level.
48 * @author Bernd Hufmann
50 public class AssignEventHandler
extends BaseControlViewHandler
{
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 * The command execution parameter.
58 private Parameter fParam
;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
66 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
69 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 // Make a copy for thread safety
74 final Parameter param
= new Parameter(fParam
);
76 // Open dialog box to retrieve the session and channel where the events should be enabled in.
77 final IGetEventInfoDialog dialog
= TraceControlDialogFactory
.getInstance().getGetEventInfoDialog();
78 dialog
.setIsKernel(param
.isKernel());
79 dialog
.setSessions(param
.getSessions());
81 if (dialog
.open() != Window
.OK
) {
85 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
87 protected IStatus
run(IProgressMonitor monitor
) {
89 Exception error
= null;
92 List
<String
> eventNames
= new ArrayList
<String
>();
93 List
<BaseEventComponent
> events
= param
.getEvents();
94 // Create list of event names
95 for (Iterator
<BaseEventComponent
> iterator
= events
.iterator(); iterator
.hasNext();) {
96 BaseEventComponent event
= (BaseEventComponent
) iterator
.next();
97 eventNames
.add(event
.getName());
100 TraceChannelComponent channel
= dialog
.getChannel();
101 if (channel
== null) {
102 // enable events on default channel (which will be created by lttng-tools)
103 dialog
.getSession().enableEvents(eventNames
, param
.isKernel(), monitor
);
105 channel
.enableEvents(eventNames
, monitor
);
108 } catch (ExecutionException e
) {
112 // refresh in all cases
113 refresh(new CommandParameter(dialog
.getSession()));
116 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_EnableEventsFailure
, error
);
118 return Status
.OK_STATUS
;
132 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
135 public boolean isEnabled() {
136 ArrayList
<BaseEventComponent
> events
= new ArrayList
<BaseEventComponent
>();
137 TraceSessionComponent
[] sessions
= null;
138 Boolean isKernel
= null;
140 // Get workbench page for the Control View
141 IWorkbenchPage page
= getWorkbenchPage();
146 // Check if one or more session are selected
147 ISelection selection
= page
.getSelection(ControlView
.ID
);
148 if (selection
instanceof StructuredSelection
) {
150 StructuredSelection structered
= ((StructuredSelection
) selection
);
151 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
152 Object element
= (Object
) iterator
.next();
153 if (element
instanceof BaseEventComponent
) {
154 BaseEventComponent event
= (BaseEventComponent
) element
;
155 ITraceControlComponent provider
= event
.getParent();
157 // check for kernel or UST provider
158 boolean temp
= false;
159 if (provider
instanceof KernelProviderComponent
) {
161 } else if (provider
instanceof UstProviderComponent
) {
166 if (isKernel
== null) {
167 isKernel
= Boolean
.valueOf(temp
);
169 // don't mix events from Kernel and UST provider
170 if (isKernel
.booleanValue() != temp
) {
175 // Add BaseEventComponents
178 if (sessions
== null) {
179 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
180 sessions
= root
.getSessions();
186 boolean isEnabled
= ((!events
.isEmpty()) && (sessions
!= null) && (sessions
.length
> 0));
191 fParam
= new Parameter(sessions
, events
, isKernel
);
200 * Class containing parameter for the command execution.
202 final static private class Parameter
{
205 * The list of event components the command is to be executed on.
207 private List
<BaseEventComponent
> fEvents
;
210 * The list of available sessions.
212 final private TraceSessionComponent
[] fSessions
;
215 * Flag for indicating Kernel or UST.
217 final private 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
<BaseEventComponent
>();
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() {