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