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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.control.model.impl; | |
13 | ||
14 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; | |
15 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; | |
16 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; | |
17 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; | |
18 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; | |
19 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; | |
20 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; | |
06b9339e | 21 | import org.eclipse.linuxtools.lttng.ui.views.control.property.TraceEventPropertySource; |
eb1bab5b | 22 | import org.eclipse.swt.graphics.Image; |
06b9339e | 23 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
24 | |
25 | ||
26 | /** | |
d132bcc7 | 27 | * <b><u>TraceEventComponent</u></b> |
eb1bab5b BH |
28 | * <p> |
29 | * Implementation of the trace channel component. | |
30 | * </p> | |
31 | */ | |
32 | public class TraceEventComponent extends TraceControlComponent { | |
33 | // ------------------------------------------------------------------------ | |
34 | // Constants | |
35 | // ------------------------------------------------------------------------ | |
36 | /** | |
37 | * Path to icon file for this component (enabled state). | |
38 | */ | |
39 | public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$ | |
40 | /** | |
41 | * Path to icon file for this component (disabled state). | |
42 | */ | |
43 | public static final String TRACE_EVENT_ICON_FILE_DISABLED = "icons/obj16/event_disabled.gif"; //$NON-NLS-1$ | |
44 | ||
45 | // ------------------------------------------------------------------------ | |
46 | // Attributes | |
47 | // ------------------------------------------------------------------------ | |
48 | /** | |
49 | * The event information. | |
50 | */ | |
d132bcc7 | 51 | protected IEventInfo fEventInfo = null; |
eb1bab5b BH |
52 | /** |
53 | * The image to be displayed when in disabled state. | |
54 | */ | |
55 | private Image fDisabledImage = null; | |
56 | ||
57 | // ------------------------------------------------------------------------ | |
58 | // Constructors | |
59 | // ------------------------------------------------------------------------ | |
60 | /** | |
61 | * Constructor | |
62 | * @param name - the name of the component. | |
63 | * @param parent - the parent of this component. | |
64 | */ | |
65 | public TraceEventComponent(String name, ITraceControlComponent parent) { | |
66 | super(name, parent); | |
67 | setImage(TRACE_EVENT_ICON_FILE_ENABLED); | |
68 | setToolTip(Messages.TraceControl_EventDisplayName); | |
69 | fEventInfo = new EventInfo(name); | |
70 | fDisabledImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_EVENT_ICON_FILE_DISABLED); | |
71 | } | |
72 | ||
73 | // ------------------------------------------------------------------------ | |
74 | // Accessors | |
75 | // ------------------------------------------------------------------------ | |
76 | /* | |
77 | * (non-Javadoc) | |
78 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage() | |
79 | */ | |
80 | @Override | |
81 | public Image getImage() { | |
82 | if (fEventInfo.getState() == TraceEnablement.DISABLED) { | |
83 | return fDisabledImage; | |
84 | } | |
85 | return super.getImage(); | |
86 | } | |
87 | ||
88 | /** | |
89 | * Sets the event information. | |
90 | * @param eventInfo - the event information to set. | |
91 | */ | |
92 | public void setEventInfo(IEventInfo eventInfo) { | |
93 | fEventInfo = eventInfo; | |
94 | } | |
95 | ||
96 | /** | |
97 | * @return the trace event type | |
98 | */ | |
99 | public TraceEventType getEventType() { | |
100 | return fEventInfo.getEventType(); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Sets the trace event type to the given type | |
105 | * @param type - type to set | |
106 | */ | |
107 | public void setEventType(TraceEventType type) { | |
108 | fEventInfo.setEventType(type); | |
109 | } | |
110 | ||
111 | /** | |
112 | * Sets the trace event type to the type specified by the given name. | |
113 | * @param type - event type name | |
114 | */ | |
115 | public void setEventType(String typeName) { | |
116 | fEventInfo.setEventType(typeName); | |
117 | } | |
118 | ||
119 | /** | |
120 | * @return the event state (enabled or disabled). | |
121 | */ | |
122 | public TraceEnablement getState() { | |
123 | return fEventInfo.getState(); | |
124 | } | |
125 | ||
126 | /** | |
127 | * Sets the event state (enablement) to the given value. | |
128 | * @param state - state to set. | |
129 | */ | |
130 | public void setState(TraceEnablement state) { | |
131 | fEventInfo.setState(state); | |
132 | } | |
133 | ||
134 | /** | |
135 | * Sets the event state (enablement) to the value specified by the given name. | |
136 | * @param stateName - state to set. | |
137 | */ | |
138 | public void setState(String stateName) { | |
139 | fEventInfo.setState(stateName); | |
140 | } | |
141 | ||
142 | /** | |
143 | * @return the trace event log level | |
144 | */ | |
145 | public TraceLogLevel getLogLevel() { | |
146 | return fEventInfo.getLogLevel(); | |
147 | } | |
148 | ||
149 | /** | |
150 | * Sets the trace event log level to the given level | |
151 | * @param level - event log level to set | |
152 | */ | |
153 | public void setLogLevel(TraceLogLevel level) { | |
154 | fEventInfo.setLogLevel(level); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Sets the trace event log level to the level specified by the given name. | |
159 | * @param levelName - event log level name | |
160 | */ | |
161 | public void setLogLevel(String levelName) { | |
162 | fEventInfo.setLogLevel(levelName); | |
163 | } | |
164 | ||
06b9339e BH |
165 | /* |
166 | * (non-Javadoc) | |
167 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) | |
168 | */ | |
169 | @SuppressWarnings("rawtypes") | |
170 | @Override | |
171 | public Object getAdapter(Class adapter) { | |
172 | if (adapter == IPropertySource.class) { | |
173 | return new TraceEventPropertySource(this); | |
174 | } | |
175 | return null; | |
176 | } | |
177 | ||
6503ae0f BH |
178 | /** |
179 | * @return session name from parent | |
180 | */ | |
181 | public String getSessionName() { | |
182 | return ((TraceChannelComponent)getParent()).getSessionName(); | |
183 | } | |
184 | ||
185 | /** | |
186 | * @return channel name from parent | |
187 | */ | |
188 | public String getChannelName() { | |
189 | return getParent().getName(); | |
190 | } | |
191 | ||
192 | /** | |
193 | * @return if domain is kernel or UST | |
194 | */ | |
195 | public boolean isKernel() { | |
196 | return ((TraceChannelComponent)getParent()).isKernel(); | |
197 | } | |
198 | ||
eb1bab5b BH |
199 | // ------------------------------------------------------------------------ |
200 | // Operations | |
201 | // ------------------------------------------------------------------------ | |
202 | } |