Add support for LTTng 2.0 command add-context
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / model / impl / TraceEventComponent.java
CommitLineData
eb1bab5b
BH
1/**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl;
eb1bab5b 13
b793fbe1
BH
14import java.util.List;
15
16import org.eclipse.core.commands.ExecutionException;
17import org.eclipse.core.runtime.IProgressMonitor;
18import org.eclipse.core.runtime.NullProgressMonitor;
115b4a01
BH
19import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
20import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
21import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo;
22import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
23import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement;
24import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType;
25import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel;
26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceEventPropertySource;
eb1bab5b 27import org.eclipse.swt.graphics.Image;
06b9339e 28import org.eclipse.ui.views.properties.IPropertySource;
eb1bab5b
BH
29
30
31/**
d132bcc7 32 * <b><u>TraceEventComponent</u></b>
eb1bab5b
BH
33 * <p>
34 * Implementation of the trace channel component.
35 * </p>
36 */
37public class TraceEventComponent extends TraceControlComponent {
38 // ------------------------------------------------------------------------
39 // Constants
40 // ------------------------------------------------------------------------
41 /**
42 * Path to icon file for this component (enabled state).
43 */
44 public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$
45 /**
46 * Path to icon file for this component (disabled state).
47 */
48 public static final String TRACE_EVENT_ICON_FILE_DISABLED = "icons/obj16/event_disabled.gif"; //$NON-NLS-1$
49
50 // ------------------------------------------------------------------------
51 // Attributes
52 // ------------------------------------------------------------------------
53 /**
54 * The event information.
55 */
d132bcc7 56 protected IEventInfo fEventInfo = null;
eb1bab5b
BH
57 /**
58 * The image to be displayed when in disabled state.
59 */
60 private Image fDisabledImage = null;
61
62 // ------------------------------------------------------------------------
63 // Constructors
64 // ------------------------------------------------------------------------
65 /**
66 * Constructor
67 * @param name - the name of the component.
68 * @param parent - the parent of this component.
69 */
70 public TraceEventComponent(String name, ITraceControlComponent parent) {
71 super(name, parent);
72 setImage(TRACE_EVENT_ICON_FILE_ENABLED);
73 setToolTip(Messages.TraceControl_EventDisplayName);
74 fEventInfo = new EventInfo(name);
31a6a4e4 75 fDisabledImage = Activator.getDefault().loadIcon(TRACE_EVENT_ICON_FILE_DISABLED);
eb1bab5b
BH
76 }
77
78 // ------------------------------------------------------------------------
79 // Accessors
80 // ------------------------------------------------------------------------
81 /*
82 * (non-Javadoc)
115b4a01 83 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
eb1bab5b
BH
84 */
85 @Override
86 public Image getImage() {
87 if (fEventInfo.getState() == TraceEnablement.DISABLED) {
88 return fDisabledImage;
89 }
90 return super.getImage();
91 }
92
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 }
100
101 /**
102 * @return the trace event type
103 */
104 public TraceEventType getEventType() {
105 return fEventInfo.getEventType();
106 }
107
108 /**
109 * Sets the trace event type to the given type
110 * @param type - type to set
111 */
112 public void setEventType(TraceEventType type) {
113 fEventInfo.setEventType(type);
114 }
115
116 /**
117 * Sets the trace event type to the type specified by the given name.
118 * @param type - event type name
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 }
130
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 }
138
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 }
153
154 /**
155 * Sets the trace event log level to the given level
156 * @param level - event log level to set
157 */
158 public void setLogLevel(TraceLogLevel level) {
159 fEventInfo.setLogLevel(level);
160 }
161
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 }
169
06b9339e
BH
170 /*
171 * (non-Javadoc)
115b4a01 172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
06b9339e
BH
173 */
174 @SuppressWarnings("rawtypes")
175 @Override
176 public Object getAdapter(Class adapter) {
177 if (adapter == IPropertySource.class) {
178 return new TraceEventPropertySource(this);
179 }
180 return null;
181 }
182
6503ae0f
BH
183 /**
184 * @return session name from parent
185 */
186 public String getSessionName() {
187 return ((TraceChannelComponent)getParent()).getSessionName();
188 }
189
b793fbe1
BH
190 /**
191 * @return session from parent
192 */
193 public TraceSessionComponent getSession() {
194 return ((TraceChannelComponent)getParent()).getSession();
195 }
196
6503ae0f
BH
197 /**
198 * @return channel name from parent
199 */
200 public String getChannelName() {
201 return getParent().getName();
202 }
203
204 /**
205 * @return if domain is kernel or UST
206 */
207 public boolean isKernel() {
208 return ((TraceChannelComponent)getParent()).isKernel();
209 }
210
eb1bab5b
BH
211 // ------------------------------------------------------------------------
212 // Operations
213 // ------------------------------------------------------------------------
b793fbe1
BH
214
215 /**
216 * Add contexts to given channels and or events
217 * @param contexts - a list of contexts to add
218 * @throws ExecutionException
219 */
220 public void addContexts(List<String> contexts) throws ExecutionException {
221 addContexts(contexts, new NullProgressMonitor());
222 }
223
224 /**
225 * Add contexts to given channels and or events
226 * @param contexts - a list of contexts to add
227 * @param monitor - a progress monitor
228 * @throws ExecutionException
229 */
230 public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
231 getControlService().addContexts(getSessionName(),getChannelName(), getName(), isKernel(), contexts, monitor);
232 }
eb1bab5b 233}
This page took 0.035878 seconds and 5 git commands to generate.