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; | |
115b4a01 | 24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; |
115b4a01 BH |
25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent; |
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 channel. | |
33 | * </p> | |
cfdb727a | 34 | * |
dbd4432d | 35 | * @author Bernd Hufmann |
498704b3 BH |
36 | */ |
37 | public class EnableEventOnChannelHandler extends BaseEnableEventHandler { | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Attributes | |
41 | // ------------------------------------------------------------------------ | |
498704b3 BH |
42 | |
43 | // ------------------------------------------------------------------------ | |
44 | // Operations | |
45 | // ------------------------------------------------------------------------ | |
46 | /* | |
47 | * (non-Javadoc) | |
d4514365 | 48 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
498704b3 BH |
49 | */ |
50 | @Override | |
d4514365 | 51 | public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExression, IProgressMonitor monitor) throws ExecutionException { |
c56972bb | 52 | if (param instanceof ChannelCommandParameter) { |
d4514365 | 53 | ((ChannelCommandParameter)param).getChannel().enableEvents(eventNames, filterExression, monitor); |
c56972bb | 54 | } |
498704b3 BH |
55 | } |
56 | ||
57 | /* | |
58 | * (non-Javadoc) | |
c56972bb | 59 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, org.eclipse.core.runtime.IProgressMonitor) |
498704b3 BH |
60 | */ |
61 | @Override | |
c56972bb BH |
62 | public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException { |
63 | if (param instanceof ChannelCommandParameter) { | |
64 | ((ChannelCommandParameter)param).getChannel().enableSyscalls(monitor); | |
65 | } | |
498704b3 BH |
66 | } |
67 | ||
68 | /* | |
69 | * (non-Javadoc) | |
c56972bb | 70 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
498704b3 BH |
71 | */ |
72 | @Override | |
c56972bb BH |
73 | public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
74 | if (param instanceof ChannelCommandParameter) { | |
75 | ((ChannelCommandParameter)param).getChannel().enableProbe(eventName, isFunction, probe, monitor); | |
76 | } | |
498704b3 BH |
77 | } |
78 | ||
ccc66d01 BH |
79 | /* |
80 | * (non-Javadoc) | |
d4514365 | 81 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) |
ccc66d01 BH |
82 | */ |
83 | @Override | |
d4514365 | 84 | public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExression, IProgressMonitor monitor) throws ExecutionException { |
c56972bb | 85 | if (param instanceof ChannelCommandParameter) { |
d4514365 | 86 | ((ChannelCommandParameter)param).getChannel().enableLogLevel(eventName, logLevelType, level, filterExression, monitor); |
c56972bb | 87 | } |
ccc66d01 BH |
88 | } |
89 | ||
90 | /* | |
91 | * (non-Javadoc) | |
c56972bb | 92 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter) |
ccc66d01 BH |
93 | */ |
94 | @Override | |
c56972bb BH |
95 | public TraceDomainComponent getDomain(CommandParameter param) { |
96 | if (param instanceof ChannelCommandParameter) { | |
97 | return (TraceDomainComponent) ((ChannelCommandParameter)param).getChannel().getParent(); | |
cfdb727a | 98 | } |
c56972bb | 99 | return null; |
ccc66d01 BH |
100 | } |
101 | ||
498704b3 BH |
102 | /* |
103 | * (non-Javadoc) | |
104 | * @see org.eclipse.core.commands.AbstractHandler#isEnabled() | |
105 | */ | |
106 | @Override | |
107 | public boolean isEnabled() { | |
108 | // Get workbench page for the Control View | |
109 | IWorkbenchPage page = getWorkbenchPage(); | |
110 | if (page == null) { | |
111 | return false; | |
112 | } | |
113 | ||
c56972bb BH |
114 | TraceChannelComponent channel = null; |
115 | TraceSessionComponent session = null; | |
498704b3 BH |
116 | ISelection selection = page.getSelection(ControlView.ID); |
117 | if (selection instanceof StructuredSelection) { | |
118 | StructuredSelection structered = ((StructuredSelection) selection); | |
119 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
cfdb727a | 120 | Object element = iterator.next(); |
498704b3 | 121 | if (element instanceof TraceChannelComponent) { |
ccc66d01 | 122 | // Add only if corresponding TraceSessionComponents is inactive and not destroyed |
cfdb727a | 123 | TraceChannelComponent tmpChannel = (TraceChannelComponent) element; |
c56972bb | 124 | session = tmpChannel.getSession(); |
f455db37 | 125 | if(!session.isDestroyed()) { |
c56972bb | 126 | channel = tmpChannel; |
ccc66d01 | 127 | } |
498704b3 BH |
128 | } |
129 | } | |
130 | } | |
cfdb727a | 131 | |
c56972bb BH |
132 | boolean isEnabled = (channel != null); |
133 | fLock.lock(); | |
134 | try { | |
135 | fParam = null; | |
136 | if(isEnabled) { | |
137 | fParam = new ChannelCommandParameter(session, channel); | |
138 | } | |
139 | } finally { | |
140 | fLock.unlock(); | |
141 | } | |
142 | return isEnabled; | |
498704b3 | 143 | } |
498704b3 | 144 | } |
c56972bb | 145 |