Improve package tangle index for LTTng 2.0 control design
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / model / impl / TraceEventComponent.java
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.internal.lttng2.ui.views.control.model.impl;
13
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;
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;
24 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
25 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
26 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
27 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceEventPropertySource;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.ui.views.properties.IPropertySource;
30
31
32 /**
33 * <b><u>TraceEventComponent</u></b>
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 */
57 protected IEventInfo fEventInfo = null;
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);
76 fDisabledImage = Activator.getDefault().loadIcon(TRACE_EVENT_ICON_FILE_DISABLED);
77 }
78
79 // ------------------------------------------------------------------------
80 // Accessors
81 // ------------------------------------------------------------------------
82 /*
83 * (non-Javadoc)
84 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
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
171 /*
172 * (non-Javadoc)
173 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
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
184 /**
185 * @return session name from parent
186 */
187 public String getSessionName() {
188 return ((TraceChannelComponent)getParent()).getSessionName();
189 }
190
191 /**
192 * @return session from parent
193 */
194 public TraceSessionComponent getSession() {
195 return ((TraceChannelComponent)getParent()).getSession();
196 }
197
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
212 // ------------------------------------------------------------------------
213 // Operations
214 // ------------------------------------------------------------------------
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 }
234 }
This page took 0.035811 seconds and 6 git commands to generate.