Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
ea21cd65 | 3 | * |
eb1bab5b BH |
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 | |
ea21cd65 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
eb1bab5b | 12 | **********************************************************************/ |
9bc60be7 | 13 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl; |
eb1bab5b | 14 | |
1bc37054 | 15 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType; |
9bc60be7 AM |
16 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IBaseEventInfo; |
17 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IFieldInfo; | |
18 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceEventType; | |
19 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel; | |
20 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.EventInfo; | |
21 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
22 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.property.BaseEventPropertySource; | |
06b9339e | 23 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
24 | |
25 | /** | |
eb1bab5b BH |
26 | * <p> |
27 | * Implementation of the base trace event component. | |
28 | * </p> | |
ea21cd65 | 29 | * |
dbd4432d | 30 | * @author Bernd Hufmann |
eb1bab5b BH |
31 | */ |
32 | public class BaseEventComponent extends TraceControlComponent { | |
33 | // ------------------------------------------------------------------------ | |
34 | // Constants | |
35 | // ------------------------------------------------------------------------ | |
36 | /** | |
37 | * Path to icon file for this component. | |
38 | */ | |
39 | public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$ | |
ea21cd65 | 40 | |
eb1bab5b BH |
41 | // ------------------------------------------------------------------------ |
42 | // Attributes | |
43 | // ------------------------------------------------------------------------ | |
44 | /** | |
ea21cd65 | 45 | * The Event information implementation. |
eb1bab5b BH |
46 | */ |
47 | private IBaseEventInfo fEventInfo; | |
ea21cd65 | 48 | |
eb1bab5b BH |
49 | // ------------------------------------------------------------------------ |
50 | // Constructors | |
51 | // ------------------------------------------------------------------------ | |
ea21cd65 | 52 | |
eb1bab5b | 53 | /** |
ea21cd65 | 54 | * Constructor |
eb1bab5b BH |
55 | * @param name - the name of the component. |
56 | * @param parent - the parent of this component. | |
57 | */ | |
58 | public BaseEventComponent(String name, ITraceControlComponent parent) { | |
59 | super(name, parent); | |
60 | setImage(TRACE_EVENT_ICON_FILE_ENABLED); | |
61 | fEventInfo = new EventInfo(name); | |
62 | } | |
ea21cd65 | 63 | |
eb1bab5b BH |
64 | // ------------------------------------------------------------------------ |
65 | // Accessors | |
66 | // ------------------------------------------------------------------------ | |
67 | /** | |
68 | * Sets the event information. | |
69 | * @param eventInfo - the event info to set. | |
70 | */ | |
71 | public void setEventInfo(IBaseEventInfo eventInfo) { | |
72 | fEventInfo = eventInfo; | |
73 | } | |
ea21cd65 | 74 | |
eb1bab5b BH |
75 | /** |
76 | * @return the event type. | |
77 | */ | |
78 | public TraceEventType getEventType() { | |
79 | return fEventInfo.getEventType(); | |
80 | } | |
ea21cd65 | 81 | |
eb1bab5b BH |
82 | /** |
83 | * Sets the event type to the given value. | |
84 | * @param type - type to set. | |
85 | */ | |
86 | public void setEventType(TraceEventType type) { | |
87 | fEventInfo.setEventType(type); | |
88 | } | |
ea21cd65 | 89 | |
eb1bab5b BH |
90 | /** |
91 | * Sets the event type to the value specified by the give name. | |
92 | * @param typeName - the type name. | |
93 | */ | |
94 | public void setEventType(String typeName) { | |
95 | fEventInfo.setEventType(typeName); | |
96 | } | |
97 | ||
98 | /** | |
99 | * @return the trace event log level | |
100 | */ | |
101 | public TraceLogLevel getLogLevel() { | |
102 | return fEventInfo.getLogLevel(); | |
103 | } | |
ea21cd65 | 104 | |
eb1bab5b | 105 | /** |
ea21cd65 | 106 | * Sets the trace event log level to the given level |
eb1bab5b BH |
107 | * @param level - event log level to set |
108 | */ | |
109 | public void setLogLevel(TraceLogLevel level) { | |
110 | fEventInfo.setLogLevel(level); | |
111 | } | |
ea21cd65 | 112 | |
eb1bab5b BH |
113 | /** |
114 | * Sets the trace event log level to the level specified by the given name. | |
115 | * @param levelName - event log level name | |
116 | */ | |
117 | public void setLogLevel(String levelName) { | |
118 | fEventInfo.setLogLevel(levelName); | |
119 | } | |
120 | ||
d4514365 BH |
121 | /** |
122 | * @return a String containing pairs if field name and data type | |
123 | */ | |
124 | public String getFieldString() { | |
125 | IFieldInfo[] fields = fEventInfo.getFields(); | |
126 | if ((fields != null) && (fields.length > 0)) { | |
127 | StringBuffer buffer = new StringBuffer(); | |
128 | for (int i = 0; i < fields.length; i++) { | |
129 | buffer.append(fields[i].getName()); | |
130 | buffer.append("="); //$NON-NLS-1$ | |
131 | buffer.append(fields[i].getFieldType()); | |
132 | if (i != fields.length-1) { | |
133 | buffer.append(";"); //$NON-NLS-1$ | |
134 | } | |
135 | } | |
136 | return buffer.toString(); | |
137 | } | |
138 | return null; | |
139 | } | |
140 | ||
06b9339e | 141 | @Override |
e58fe1d5 | 142 | public <T> T getAdapter(Class<T> adapter) { |
06b9339e | 143 | if (adapter == IPropertySource.class) { |
e58fe1d5 | 144 | return adapter.cast(new BaseEventPropertySource(this)); |
06b9339e BH |
145 | } |
146 | return null; | |
ea21cd65 | 147 | } |
6503ae0f BH |
148 | |
149 | /** | |
ea21cd65 | 150 | * @return target node component. |
6503ae0f BH |
151 | */ |
152 | public TargetNodeComponent getTargetNode() { | |
153 | return (TargetNodeComponent) getParent().getParent(); | |
154 | } | |
155 | ||
156 | /** | |
1bc37054 | 157 | * @return the domain type ({@link TraceDomainType}) |
6503ae0f | 158 | */ |
1bc37054 BR |
159 | public TraceDomainType getDomain() { |
160 | return getParent() instanceof KernelProviderComponent ? TraceDomainType.KERNEL : TraceDomainType.UST; | |
6503ae0f BH |
161 | } |
162 | ||
eb1bab5b BH |
163 | // ------------------------------------------------------------------------ |
164 | // Operations | |
165 | // ------------------------------------------------------------------------ | |
166 | } |