| 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.property; |
| 13 | |
| 14 | import java.util.ArrayList; |
| 15 | import java.util.List; |
| 16 | |
| 17 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; |
| 18 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; |
| 19 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceEventComponent; |
| 20 | import org.eclipse.ui.views.properties.IPropertyDescriptor; |
| 21 | import org.eclipse.ui.views.properties.TextPropertyDescriptor; |
| 22 | |
| 23 | /** |
| 24 | * <b><u>TraceEventPropertySource</u></b> |
| 25 | * <p> |
| 26 | * Property source implementation for the trace event component. |
| 27 | * </p> |
| 28 | */ |
| 29 | public class TraceEventPropertySource extends BasePropertySource { |
| 30 | |
| 31 | // ------------------------------------------------------------------------ |
| 32 | // Constants |
| 33 | // ------------------------------------------------------------------------ |
| 34 | /** |
| 35 | * The trace event 'name' property ID. |
| 36 | */ |
| 37 | public static final String TRACE_EVENT_NAME_PROPERTY_ID = "trace.event.name"; //$NON-NLS-1$ |
| 38 | /** |
| 39 | * The trace event 'type' property ID. |
| 40 | */ |
| 41 | public static final String TRACE_EVENT_TYPE_PROPERTY_ID = "trace.event.type"; //$NON-NLS-1$ |
| 42 | /** |
| 43 | * The trace event 'log level' property ID. |
| 44 | */ |
| 45 | public static final String TRACE_EVENT_LOGLEVEL_PROPERTY_ID = "trace.event.loglevel"; //$NON-NLS-1$ |
| 46 | /** |
| 47 | * The trace event 'state' property ID. |
| 48 | */ |
| 49 | public static final String TRACE_EVENT_STATE_PROPERTY_ID = "trace.event.state"; //$NON-NLS-1$ |
| 50 | /** |
| 51 | * The trace event 'name' property name. |
| 52 | */ |
| 53 | public static final String TRACE_EVENT_NAME_PROPERTY_NAME = Messages.TraceControl_EventNamePropertyName; |
| 54 | /** |
| 55 | * The trace event 'type' property name. |
| 56 | */ |
| 57 | public static final String TRACE_EVENT_TYPE_PROPERTY_NAME = Messages.TraceControl_EventTypePropertyName; |
| 58 | /** |
| 59 | * The trace event 'log level' property name. |
| 60 | */ |
| 61 | public static final String TRACE_EVENT_LOGLEVEL_PROPERTY_NAME = Messages.TraceControl_LogLevelPropertyName; |
| 62 | /** |
| 63 | * The trace event 'state' property name. |
| 64 | */ |
| 65 | public static final String TRACE_EVENT_STATE_PROPERTY_NAME = Messages.TraceControl_StatePropertyName; |
| 66 | |
| 67 | // ------------------------------------------------------------------------ |
| 68 | // Attributes |
| 69 | // ------------------------------------------------------------------------ |
| 70 | /** |
| 71 | * The event component which this property source is for. |
| 72 | */ |
| 73 | protected final TraceEventComponent fEvent; |
| 74 | |
| 75 | // ------------------------------------------------------------------------ |
| 76 | // Constructors |
| 77 | // ------------------------------------------------------------------------ |
| 78 | /** |
| 79 | * Constructor |
| 80 | * @param component - the base event component |
| 81 | */ |
| 82 | public TraceEventPropertySource(TraceEventComponent component) { |
| 83 | fEvent = component; |
| 84 | } |
| 85 | |
| 86 | // ------------------------------------------------------------------------ |
| 87 | // Operations |
| 88 | // ------------------------------------------------------------------------ |
| 89 | /* |
| 90 | * (non-Javadoc) |
| 91 | * @see org.eclipse.linuxtools.lttng.ui.views.control.property.BasePropertySource#getPropertyDescriptors() |
| 92 | */ |
| 93 | @Override |
| 94 | public IPropertyDescriptor[] getPropertyDescriptors() { |
| 95 | List<IPropertyDescriptor> list = new ArrayList<IPropertyDescriptor> (); |
| 96 | list.add(new TextPropertyDescriptor(TRACE_EVENT_NAME_PROPERTY_ID, TRACE_EVENT_NAME_PROPERTY_NAME)); |
| 97 | list.add(new TextPropertyDescriptor(TRACE_EVENT_TYPE_PROPERTY_ID, TRACE_EVENT_TYPE_PROPERTY_NAME)); |
| 98 | list.add( new TextPropertyDescriptor(TRACE_EVENT_STATE_PROPERTY_ID, TRACE_EVENT_STATE_PROPERTY_NAME)); |
| 99 | if (fEvent.getLogLevel() != TraceLogLevel.LEVEL_UNKNOWN) { |
| 100 | list.add(new TextPropertyDescriptor(TRACE_EVENT_LOGLEVEL_PROPERTY_ID, TRACE_EVENT_LOGLEVEL_PROPERTY_NAME)); |
| 101 | } |
| 102 | return (IPropertyDescriptor [])list.toArray(new IPropertyDescriptor[list.size()]); |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * (non-Javadoc) |
| 107 | * @see org.eclipse.linuxtools.lttng.ui.views.control.property.BasePropertySource#getPropertyValue(java.lang.Object) |
| 108 | */ |
| 109 | @Override |
| 110 | public Object getPropertyValue(Object id) { |
| 111 | if(TRACE_EVENT_NAME_PROPERTY_ID.equals(id)) { |
| 112 | return fEvent.getName(); |
| 113 | } |
| 114 | if (TRACE_EVENT_TYPE_PROPERTY_ID.equals(id)) { |
| 115 | return fEvent.getEventType().name(); |
| 116 | } |
| 117 | if (TRACE_EVENT_LOGLEVEL_PROPERTY_ID.equals(id)) { |
| 118 | return fEvent.getLogLevel().name(); |
| 119 | } |
| 120 | if (TRACE_EVENT_STATE_PROPERTY_ID.equals(id)) { |
| 121 | return fEvent.getState().name(); |
| 122 | } |
| 123 | return null; |
| 124 | } |
| 125 | |
| 126 | } |