Commit | Line | Data |
---|---|---|
498704b3 | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
498704b3 BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
498704b3 | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
498704b3 | 12 | **********************************************************************/ |
115b4a01 | 13 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; |
498704b3 BH |
14 | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
18 | import org.eclipse.core.commands.ExecutionException; | |
19 | import org.eclipse.core.runtime.IProgressMonitor; | |
20 | import org.eclipse.jface.viewers.ISelection; | |
21 | import org.eclipse.jface.viewers.StructuredSelection; | |
9315aeee BH |
22 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType; |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
115b4a01 | 25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; |
115b4a01 BH |
26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; |
27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; | |
498704b3 BH |
28 | import org.eclipse.ui.IWorkbenchPage; |
29 | ||
30 | /** | |
498704b3 BH |
31 | * <p> |
32 | * Command handler implementation to enable events for a known session and default channel 'channel0' | |
33 | * (which will be created if doesn't exist). | |
34 | * </p> | |
cfdb727a | 35 | * |
dbd4432d | 36 | * @author Bernd Hufmann |
498704b3 BH |
37 | */ |
38 | public class EnableEventOnSessionHandler extends BaseEnableEventHandler { | |
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Attributes | |
42 | // ------------------------------------------------------------------------ | |
cfdb727a | 43 | |
498704b3 BH |
44 | //------------------------------------------------------------------------- |
45 | // Operations | |
46 | // ------------------------------------------------------------------------ | |
11252342 | 47 | |
498704b3 | 48 | @Override |
d4514365 BH |
49 | public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
50 | param.getSession().enableEvents(eventNames, isKernel, filterExpression, monitor); | |
498704b3 BH |
51 | } |
52 | ||
498704b3 | 53 | @Override |
c56972bb BH |
54 | public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException { |
55 | param.getSession().enableSyscalls(monitor); | |
498704b3 BH |
56 | } |
57 | ||
498704b3 | 58 | @Override |
c56972bb BH |
59 | public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
60 | param.getSession().enableProbe(eventName, isFunction, probe, monitor); | |
498704b3 BH |
61 | } |
62 | ||
ccc66d01 | 63 | @Override |
d4514365 BH |
64 | public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException { |
65 | param.getSession().enableLogLevel(eventName, logLevelType, level, filterExpression, monitor); | |
ccc66d01 BH |
66 | } |
67 | ||
ccc66d01 | 68 | @Override |
c56972bb | 69 | public TraceDomainComponent getDomain(CommandParameter param) { |
ccc66d01 BH |
70 | return null; |
71 | } | |
498704b3 | 72 | |
498704b3 BH |
73 | @Override |
74 | public boolean isEnabled() { | |
75 | // Get workbench page for the Control View | |
76 | IWorkbenchPage page = getWorkbenchPage(); | |
77 | if (page == null) { | |
78 | return false; | |
79 | } | |
80 | ||
c56972bb | 81 | TraceSessionComponent session = null; |
498704b3 BH |
82 | // Check if one session is selected |
83 | ISelection selection = page.getSelection(ControlView.ID); | |
84 | if (selection instanceof StructuredSelection) { | |
85 | StructuredSelection structered = ((StructuredSelection) selection); | |
86 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
cfdb727a | 87 | Object element = iterator.next(); |
498704b3 | 88 | if (element instanceof TraceSessionComponent) { |
ccc66d01 | 89 | // Add only if corresponding TraceSessionComponents is inactive and not destroyed |
cfdb727a | 90 | TraceSessionComponent tmpSession = (TraceSessionComponent) element; |
c56972bb BH |
91 | if(tmpSession.getSessionState() == TraceSessionState.INACTIVE && !tmpSession.isDestroyed()) { |
92 | session = tmpSession; | |
498704b3 BH |
93 | } |
94 | } | |
95 | } | |
96 | } | |
c56972bb BH |
97 | boolean isEnabled = (session != null); |
98 | fLock.lock(); | |
99 | try { | |
100 | fParam = null; | |
101 | if(isEnabled) { | |
102 | fParam = new CommandParameter(session); | |
103 | } | |
104 | } finally { | |
105 | fLock.unlock(); | |
106 | } | |
107 | return isEnabled; | |
498704b3 BH |
108 | } |
109 | } |