Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
cfdb727a | 3 | * |
eb1bab5b 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: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
eb1bab5b | 12 | **********************************************************************/ |
9bc60be7 | 13 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl; |
eb1bab5b | 14 | |
b793fbe1 BH |
15 | import java.util.List; |
16 | ||
17 | import org.eclipse.core.commands.ExecutionException; | |
18 | import org.eclipse.core.runtime.IProgressMonitor; | |
eb1bab5b | 19 | import org.eclipse.swt.graphics.Image; |
9bc60be7 AM |
20 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IEventInfo; |
21 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType; | |
22 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEnablement; | |
23 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType; | |
24 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel; | |
25 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.EventInfo; | |
26 | import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator; | |
27 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages; | |
28 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
29 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.property.TraceEventPropertySource; | |
06b9339e | 30 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
31 | |
32 | ||
33 | /** | |
eb1bab5b BH |
34 | * <p> |
35 | * Implementation of the trace channel component. | |
36 | * </p> | |
cfdb727a | 37 | * |
dbd4432d | 38 | * @author Bernd Hufmann |
eb1bab5b BH |
39 | */ |
40 | public class TraceEventComponent extends TraceControlComponent { | |
41 | // ------------------------------------------------------------------------ | |
42 | // Constants | |
43 | // ------------------------------------------------------------------------ | |
44 | /** | |
45 | * Path to icon file for this component (enabled state). | |
46 | */ | |
47 | public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$ | |
48 | /** | |
49 | * Path to icon file for this component (disabled state). | |
50 | */ | |
51 | public static final String TRACE_EVENT_ICON_FILE_DISABLED = "icons/obj16/event_disabled.gif"; //$NON-NLS-1$ | |
cfdb727a | 52 | |
eb1bab5b BH |
53 | // ------------------------------------------------------------------------ |
54 | // Attributes | |
55 | // ------------------------------------------------------------------------ | |
56 | /** | |
57 | * The event information. | |
58 | */ | |
d132bcc7 | 59 | protected IEventInfo fEventInfo = null; |
eb1bab5b BH |
60 | /** |
61 | * The image to be displayed when in disabled state. | |
62 | */ | |
63 | private Image fDisabledImage = null; | |
cfdb727a | 64 | |
eb1bab5b BH |
65 | // ------------------------------------------------------------------------ |
66 | // Constructors | |
67 | // ------------------------------------------------------------------------ | |
68 | /** | |
cfdb727a | 69 | * Constructor |
eb1bab5b BH |
70 | * @param name - the name of the component. |
71 | * @param parent - the parent of this component. | |
cfdb727a | 72 | */ |
eb1bab5b BH |
73 | public TraceEventComponent(String name, ITraceControlComponent parent) { |
74 | super(name, parent); | |
75 | setImage(TRACE_EVENT_ICON_FILE_ENABLED); | |
76 | setToolTip(Messages.TraceControl_EventDisplayName); | |
77 | fEventInfo = new EventInfo(name); | |
31a6a4e4 | 78 | fDisabledImage = Activator.getDefault().loadIcon(TRACE_EVENT_ICON_FILE_DISABLED); |
eb1bab5b | 79 | } |
cfdb727a | 80 | |
eb1bab5b BH |
81 | // ------------------------------------------------------------------------ |
82 | // Accessors | |
83 | // ------------------------------------------------------------------------ | |
11252342 | 84 | |
eb1bab5b BH |
85 | @Override |
86 | public Image getImage() { | |
87 | if (fEventInfo.getState() == TraceEnablement.DISABLED) { | |
88 | return fDisabledImage; | |
89 | } | |
90 | return super.getImage(); | |
91 | } | |
cfdb727a | 92 | |
eb1bab5b BH |
93 | /** |
94 | * Sets the event information. | |
95 | * @param eventInfo - the event information to set. | |
96 | */ | |
97 | public void setEventInfo(IEventInfo eventInfo) { | |
98 | fEventInfo = eventInfo; | |
99 | } | |
cfdb727a | 100 | |
eb1bab5b BH |
101 | /** |
102 | * @return the trace event type | |
103 | */ | |
104 | public TraceEventType getEventType() { | |
105 | return fEventInfo.getEventType(); | |
106 | } | |
cfdb727a | 107 | |
eb1bab5b | 108 | /** |
cfdb727a | 109 | * Sets the trace event type to the given type |
eb1bab5b BH |
110 | * @param type - type to set |
111 | */ | |
112 | public void setEventType(TraceEventType type) { | |
113 | fEventInfo.setEventType(type); | |
114 | } | |
cfdb727a | 115 | |
eb1bab5b BH |
116 | /** |
117 | * Sets the trace event type to the type specified by the given name. | |
cfdb727a | 118 | * @param typeName - event type name |
eb1bab5b BH |
119 | */ |
120 | public void setEventType(String typeName) { | |
121 | fEventInfo.setEventType(typeName); | |
122 | } | |
123 | ||
124 | /** | |
125 | * @return the event state (enabled or disabled). | |
126 | */ | |
127 | public TraceEnablement getState() { | |
128 | return fEventInfo.getState(); | |
129 | } | |
cfdb727a | 130 | |
eb1bab5b BH |
131 | /** |
132 | * Sets the event state (enablement) to the given value. | |
133 | * @param state - state to set. | |
134 | */ | |
135 | public void setState(TraceEnablement state) { | |
136 | fEventInfo.setState(state); | |
137 | } | |
cfdb727a | 138 | |
eb1bab5b BH |
139 | /** |
140 | * Sets the event state (enablement) to the value specified by the given name. | |
141 | * @param stateName - state to set. | |
142 | */ | |
143 | public void setState(String stateName) { | |
144 | fEventInfo.setState(stateName); | |
145 | } | |
146 | ||
147 | /** | |
148 | * @return the trace event log level | |
149 | */ | |
150 | public TraceLogLevel getLogLevel() { | |
151 | return fEventInfo.getLogLevel(); | |
152 | } | |
cfdb727a | 153 | |
eb1bab5b | 154 | /** |
cfdb727a | 155 | * Sets the trace event log level to the given level |
eb1bab5b BH |
156 | * @param level - event log level to set |
157 | */ | |
158 | public void setLogLevel(TraceLogLevel level) { | |
159 | fEventInfo.setLogLevel(level); | |
160 | } | |
cfdb727a | 161 | |
eb1bab5b BH |
162 | /** |
163 | * Sets the trace event log level to the level specified by the given name. | |
164 | * @param levelName - event log level name | |
165 | */ | |
166 | public void setLogLevel(String levelName) { | |
167 | fEventInfo.setLogLevel(levelName); | |
168 | } | |
cfdb727a | 169 | |
d4514365 BH |
170 | /** |
171 | * Returns filter expression. | |
172 | * @return filter expression | |
173 | */ | |
174 | public String getFilterExpression() { | |
175 | return fEventInfo.getFilterExpression(); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Sets the filter expression. | |
180 | * @param filter The filter expression to set | |
181 | */ | |
182 | public void setFilterExpression(String filter) { | |
183 | fEventInfo.setFilterExpression(filter); | |
184 | } | |
185 | ||
91dc1c3e BR |
186 | /** |
187 | * Returns excluded events. | |
188 | * @return excluded events | |
189 | */ | |
190 | public String getExcludedEvents() { | |
191 | return fEventInfo.getExcludedEvents(); | |
192 | } | |
193 | ||
194 | /** | |
195 | * Sets the excluded events. | |
196 | * @param events The excluded events to set | |
197 | */ | |
198 | public void setExcludedEvents(String events) { | |
199 | fEventInfo.setExcludedEvents(events); | |
200 | } | |
201 | ||
54f2dcc0 BH |
202 | /** |
203 | * Returns the log level type | |
204 | * @return event log level type | |
205 | */ | |
206 | public LogLevelType getLogLevelType() { | |
207 | return fEventInfo.getLogLevelType(); | |
208 | } | |
209 | ||
210 | /** | |
211 | * Sets the trace event log level type to the given level type | |
212 | * @param levelType - event log level type to set | |
213 | */ | |
214 | public void setLogLevelType(LogLevelType levelType) { | |
215 | fEventInfo.setLogLevelType(levelType); | |
216 | } | |
217 | ||
06b9339e | 218 | @Override |
e58fe1d5 | 219 | public <T> T getAdapter(Class<T> adapter) { |
06b9339e | 220 | if (adapter == IPropertySource.class) { |
e58fe1d5 | 221 | return adapter.cast(new TraceEventPropertySource(this)); |
06b9339e BH |
222 | } |
223 | return null; | |
cfdb727a AM |
224 | } |
225 | ||
bd9f92a8 BH |
226 | /** |
227 | * @return target node component. | |
228 | */ | |
229 | public TargetNodeComponent getTargetNode() { | |
230 | return ((TraceChannelComponent)getParent()).getTargetNode(); | |
231 | } | |
232 | ||
6503ae0f BH |
233 | /** |
234 | * @return session name from parent | |
235 | */ | |
236 | public String getSessionName() { | |
cfdb727a | 237 | return ((TraceChannelComponent)getParent()).getSessionName(); |
6503ae0f BH |
238 | } |
239 | ||
b793fbe1 BH |
240 | /** |
241 | * @return session from parent | |
242 | */ | |
243 | public TraceSessionComponent getSession() { | |
cfdb727a | 244 | return ((TraceChannelComponent)getParent()).getSession(); |
b793fbe1 BH |
245 | } |
246 | ||
6503ae0f BH |
247 | /** |
248 | * @return channel name from parent | |
249 | */ | |
250 | public String getChannelName() { | |
cfdb727a | 251 | return getParent().getName(); |
6503ae0f BH |
252 | } |
253 | ||
254 | /** | |
255 | * @return if domain is kernel or UST | |
256 | */ | |
257 | public boolean isKernel() { | |
258 | return ((TraceChannelComponent)getParent()).isKernel(); | |
259 | } | |
260 | ||
eb1bab5b BH |
261 | // ------------------------------------------------------------------------ |
262 | // Operations | |
263 | // ------------------------------------------------------------------------ | |
cfdb727a | 264 | |
b793fbe1 BH |
265 | /** |
266 | * Add contexts to given channels and or events | |
cfdb727a AM |
267 | * |
268 | * @param contexts | |
269 | * - a list of contexts to add | |
270 | * @param monitor | |
271 | * - a progress monitor | |
b793fbe1 | 272 | * @throws ExecutionException |
cfdb727a | 273 | * If the command fails |
b793fbe1 | 274 | */ |
cfdb727a AM |
275 | public void addContexts(List<String> contexts, IProgressMonitor monitor) |
276 | throws ExecutionException { | |
277 | getControlService().addContexts(getSessionName(), getChannelName(), | |
278 | getName(), isKernel(), contexts, monitor); | |
b793fbe1 | 279 | } |
eb1bab5b | 280 | } |