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 | ||
54f2dcc0 BH |
186 | /** |
187 | * Returns the log level type | |
188 | * @return event log level type | |
189 | */ | |
190 | public LogLevelType getLogLevelType() { | |
191 | return fEventInfo.getLogLevelType(); | |
192 | } | |
193 | ||
194 | /** | |
195 | * Sets the trace event log level type to the given level type | |
196 | * @param levelType - event log level type to set | |
197 | */ | |
198 | public void setLogLevelType(LogLevelType levelType) { | |
199 | fEventInfo.setLogLevelType(levelType); | |
200 | } | |
201 | ||
06b9339e BH |
202 | @Override |
203 | public Object getAdapter(Class adapter) { | |
204 | if (adapter == IPropertySource.class) { | |
205 | return new TraceEventPropertySource(this); | |
206 | } | |
207 | return null; | |
cfdb727a AM |
208 | } |
209 | ||
bd9f92a8 BH |
210 | /** |
211 | * @return target node component. | |
212 | */ | |
213 | public TargetNodeComponent getTargetNode() { | |
214 | return ((TraceChannelComponent)getParent()).getTargetNode(); | |
215 | } | |
216 | ||
6503ae0f BH |
217 | /** |
218 | * @return session name from parent | |
219 | */ | |
220 | public String getSessionName() { | |
cfdb727a | 221 | return ((TraceChannelComponent)getParent()).getSessionName(); |
6503ae0f BH |
222 | } |
223 | ||
b793fbe1 BH |
224 | /** |
225 | * @return session from parent | |
226 | */ | |
227 | public TraceSessionComponent getSession() { | |
cfdb727a | 228 | return ((TraceChannelComponent)getParent()).getSession(); |
b793fbe1 BH |
229 | } |
230 | ||
6503ae0f BH |
231 | /** |
232 | * @return channel name from parent | |
233 | */ | |
234 | public String getChannelName() { | |
cfdb727a | 235 | return getParent().getName(); |
6503ae0f BH |
236 | } |
237 | ||
238 | /** | |
239 | * @return if domain is kernel or UST | |
240 | */ | |
241 | public boolean isKernel() { | |
242 | return ((TraceChannelComponent)getParent()).isKernel(); | |
243 | } | |
244 | ||
eb1bab5b BH |
245 | // ------------------------------------------------------------------------ |
246 | // Operations | |
247 | // ------------------------------------------------------------------------ | |
cfdb727a | 248 | |
b793fbe1 BH |
249 | /** |
250 | * Add contexts to given channels and or events | |
cfdb727a AM |
251 | * |
252 | * @param contexts | |
253 | * - a list of contexts to add | |
254 | * @param monitor | |
255 | * - a progress monitor | |
b793fbe1 | 256 | * @throws ExecutionException |
cfdb727a | 257 | * If the command fails |
b793fbe1 | 258 | */ |
cfdb727a AM |
259 | public void addContexts(List<String> contexts, IProgressMonitor monitor) |
260 | throws ExecutionException { | |
261 | getControlService().addContexts(getSessionName(), getChannelName(), | |
262 | getName(), isKernel(), contexts, monitor); | |
b793fbe1 | 263 | } |
eb1bab5b | 264 | } |