Commit | Line | Data |
---|---|---|
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 | 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
eb1bab5b | 13 | |
b793fbe1 BH |
14 | import java.util.List; |
15 | ||
16 | import org.eclipse.core.commands.ExecutionException; | |
17 | import org.eclipse.core.runtime.IProgressMonitor; | |
18 | import org.eclipse.core.runtime.NullProgressMonitor; | |
9315aeee BH |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo; |
20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; | |
21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; | |
22 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.EventInfo; | |
115b4a01 | 24 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 | 26 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
115b4a01 | 27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceEventPropertySource; |
eb1bab5b | 28 | import org.eclipse.swt.graphics.Image; |
06b9339e | 29 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
30 | |
31 | ||
32 | /** | |
d132bcc7 | 33 | * <b><u>TraceEventComponent</u></b> |
eb1bab5b BH |
34 | * <p> |
35 | * Implementation of the trace channel component. | |
36 | * </p> | |
37 | */ | |
38 | public class TraceEventComponent extends TraceControlComponent { | |
39 | // ------------------------------------------------------------------------ | |
40 | // Constants | |
41 | // ------------------------------------------------------------------------ | |
42 | /** | |
43 | * Path to icon file for this component (enabled state). | |
44 | */ | |
45 | public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$ | |
46 | /** | |
47 | * Path to icon file for this component (disabled state). | |
48 | */ | |
49 | public static final String TRACE_EVENT_ICON_FILE_DISABLED = "icons/obj16/event_disabled.gif"; //$NON-NLS-1$ | |
50 | ||
51 | // ------------------------------------------------------------------------ | |
52 | // Attributes | |
53 | // ------------------------------------------------------------------------ | |
54 | /** | |
55 | * The event information. | |
56 | */ | |
d132bcc7 | 57 | protected IEventInfo fEventInfo = null; |
eb1bab5b BH |
58 | /** |
59 | * The image to be displayed when in disabled state. | |
60 | */ | |
61 | private Image fDisabledImage = null; | |
62 | ||
63 | // ------------------------------------------------------------------------ | |
64 | // Constructors | |
65 | // ------------------------------------------------------------------------ | |
66 | /** | |
67 | * Constructor | |
68 | * @param name - the name of the component. | |
69 | * @param parent - the parent of this component. | |
70 | */ | |
71 | public TraceEventComponent(String name, ITraceControlComponent parent) { | |
72 | super(name, parent); | |
73 | setImage(TRACE_EVENT_ICON_FILE_ENABLED); | |
74 | setToolTip(Messages.TraceControl_EventDisplayName); | |
75 | fEventInfo = new EventInfo(name); | |
31a6a4e4 | 76 | fDisabledImage = Activator.getDefault().loadIcon(TRACE_EVENT_ICON_FILE_DISABLED); |
eb1bab5b BH |
77 | } |
78 | ||
79 | // ------------------------------------------------------------------------ | |
80 | // Accessors | |
81 | // ------------------------------------------------------------------------ | |
82 | /* | |
83 | * (non-Javadoc) | |
115b4a01 | 84 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage() |
eb1bab5b BH |
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 type - 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 | ||
06b9339e BH |
171 | /* |
172 | * (non-Javadoc) | |
115b4a01 | 173 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
06b9339e BH |
174 | */ |
175 | @SuppressWarnings("rawtypes") | |
176 | @Override | |
177 | public Object getAdapter(Class adapter) { | |
178 | if (adapter == IPropertySource.class) { | |
179 | return new TraceEventPropertySource(this); | |
180 | } | |
181 | return null; | |
182 | } | |
183 | ||
6503ae0f BH |
184 | /** |
185 | * @return session name from parent | |
186 | */ | |
187 | public String getSessionName() { | |
188 | return ((TraceChannelComponent)getParent()).getSessionName(); | |
189 | } | |
190 | ||
b793fbe1 BH |
191 | /** |
192 | * @return session from parent | |
193 | */ | |
194 | public TraceSessionComponent getSession() { | |
195 | return ((TraceChannelComponent)getParent()).getSession(); | |
196 | } | |
197 | ||
6503ae0f BH |
198 | /** |
199 | * @return channel name from parent | |
200 | */ | |
201 | public String getChannelName() { | |
202 | return getParent().getName(); | |
203 | } | |
204 | ||
205 | /** | |
206 | * @return if domain is kernel or UST | |
207 | */ | |
208 | public boolean isKernel() { | |
209 | return ((TraceChannelComponent)getParent()).isKernel(); | |
210 | } | |
211 | ||
eb1bab5b BH |
212 | // ------------------------------------------------------------------------ |
213 | // Operations | |
214 | // ------------------------------------------------------------------------ | |
b793fbe1 BH |
215 | |
216 | /** | |
217 | * Add contexts to given channels and or events | |
218 | * @param contexts - a list of contexts to add | |
219 | * @throws ExecutionException | |
220 | */ | |
221 | public void addContexts(List<String> contexts) throws ExecutionException { | |
222 | addContexts(contexts, new NullProgressMonitor()); | |
223 | } | |
224 | ||
225 | /** | |
226 | * Add contexts to given channels and or events | |
227 | * @param contexts - a list of contexts to add | |
228 | * @param monitor - a progress monitor | |
229 | * @throws ExecutionException | |
230 | */ | |
231 | public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException { | |
232 | getControlService().addContexts(getSessionName(),getChannelName(), getName(), isKernel(), contexts, monitor); | |
233 | } | |
eb1bab5b | 234 | } |