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