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