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
.lttng
.ui
.views
.control
.handlers
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Iterator
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.jface
.viewers
.ISelection
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.jface
.window
.Window
;
27 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.ControlView
;
29 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.Messages
;
30 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.dialogs
.IGetEventInfoDialog
;
31 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
32 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
33 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.BaseEventComponent
;
34 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.KernelProviderComponent
;
35 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
36 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
37 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
38 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.UstProviderComponent
;
39 import org
.eclipse
.ui
.IWorkbenchPage
;
42 * <b><u>EnableEventHandler</u></b>
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 public class AssignEventHandler
extends BaseControlViewHandler
{
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
54 * The list of event components the command is to be executed on.
56 private List
<BaseEventComponent
> fEvents
= new ArrayList
<BaseEventComponent
>();
59 * The list of available sessions.
61 private TraceSessionComponent
[] fSessions
;
64 * Flag for indicating Kernel or UST.
66 Boolean fIsKernel
= null;
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
74 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
77 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
79 // Open dialog box to retrieve the session and channel where the events should be enabled in.
80 final IGetEventInfoDialog dialog
= TraceControlDialogFactory
.getInstance().getGetEventInfoDialog();
81 dialog
.setIsKernel(fIsKernel
);
82 dialog
.setSessions(fSessions
);
84 if (dialog
.open() != Window
.OK
) {
88 Job job
= new Job(Messages
.TraceControl_EnableEventsJob
) {
90 protected IStatus
run(IProgressMonitor monitor
) {
92 String errorString
= null;
94 List
<String
> eventNames
= new ArrayList
<String
>();
95 // Create list of event names
96 for (Iterator
<BaseEventComponent
> iterator
= fEvents
.iterator(); iterator
.hasNext();) {
97 BaseEventComponent event
= (BaseEventComponent
) iterator
.next();
98 eventNames
.add(event
.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
, fIsKernel
, monitor
);
106 channel
.enableEvents(eventNames
, monitor
);
109 } catch (ExecutionException e
) {
110 errorString
= e
.toString() + "\n"; //$NON-NLS-1$
113 // get session configuration in all cases
115 dialog
.getSession().getConfigurationFromNode(monitor
);
116 } catch (ExecutionException e
) {
117 if (errorString
== null) {
118 errorString
= new String();
120 errorString
+= Messages
.TraceControl_ListSessionFailure
+ ": " + e
.toString(); //$NON-NLS-1$
123 if (errorString
!= null) {
124 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, errorString
);
126 return Status
.OK_STATUS
;
136 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
139 public boolean isEnabled() {
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
= (Object
) 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 (fIsKernel
== null) {
171 fIsKernel
= Boolean
.valueOf(temp
);
173 // don't mix events from Kernel and UST provider
174 if (fIsKernel
.booleanValue() != temp
) {
179 // Add BaseEventComponents
182 if (fSessions
== null) {
183 TargetNodeComponent root
= (TargetNodeComponent
)event
.getParent().getParent().getParent();
184 fSessions
= root
.getSessions();
189 return ((fEvents
.size() > 0) && (fSessions
!= null) && (fSessions
.length
> 0));