| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012, 2014 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 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
| 12 | **********************************************************************/ |
| 13 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl; |
| 14 | |
| 15 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType; |
| 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; |
| 23 | import org.eclipse.ui.views.properties.IPropertySource; |
| 24 | |
| 25 | /** |
| 26 | * <p> |
| 27 | * Implementation of the base trace event component. |
| 28 | * </p> |
| 29 | * |
| 30 | * @author Bernd Hufmann |
| 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$ |
| 40 | |
| 41 | // ------------------------------------------------------------------------ |
| 42 | // Attributes |
| 43 | // ------------------------------------------------------------------------ |
| 44 | /** |
| 45 | * The Event information implementation. |
| 46 | */ |
| 47 | private IBaseEventInfo fEventInfo; |
| 48 | |
| 49 | // ------------------------------------------------------------------------ |
| 50 | // Constructors |
| 51 | // ------------------------------------------------------------------------ |
| 52 | |
| 53 | /** |
| 54 | * Constructor |
| 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 | } |
| 63 | |
| 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 | } |
| 74 | |
| 75 | /** |
| 76 | * @return the event type. |
| 77 | */ |
| 78 | public TraceEventType getEventType() { |
| 79 | return fEventInfo.getEventType(); |
| 80 | } |
| 81 | |
| 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 | } |
| 89 | |
| 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 | } |
| 104 | |
| 105 | /** |
| 106 | * Sets the trace event log level to the given level |
| 107 | * @param level - event log level to set |
| 108 | */ |
| 109 | public void setLogLevel(TraceLogLevel level) { |
| 110 | fEventInfo.setLogLevel(level); |
| 111 | } |
| 112 | |
| 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 | |
| 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 | |
| 141 | @Override |
| 142 | public <T> T getAdapter(Class<T> adapter) { |
| 143 | if (adapter == IPropertySource.class) { |
| 144 | return adapter.cast(new BaseEventPropertySource(this)); |
| 145 | } |
| 146 | return null; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * @return target node component. |
| 151 | */ |
| 152 | public TargetNodeComponent getTargetNode() { |
| 153 | return (TargetNodeComponent) getParent().getParent(); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @return the domain type ({@link TraceDomainType}) |
| 158 | */ |
| 159 | public TraceDomainType getDomain() { |
| 160 | return getParent() instanceof KernelProviderComponent ? TraceDomainType.KERNEL : TraceDomainType.UST; |
| 161 | } |
| 162 | |
| 163 | // ------------------------------------------------------------------------ |
| 164 | // Operations |
| 165 | // ------------------------------------------------------------------------ |
| 166 | } |