Commit | Line | Data |
---|---|---|
a20452b1 BR |
1 | /********************************************************************** |
2 | * Copyright (c) 2016 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 | * Bruno Roy- Initial API and implementation | |
11 | **********************************************************************/ | |
12 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.property; | |
13 | ||
14 | import java.util.ArrayList; | |
15 | import java.util.List; | |
16 | ||
17 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType; | |
18 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceJulLogLevel; | |
74fe9bdd | 19 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLog4jLogLevel; |
a20452b1 BR |
20 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages; |
21 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceLoggerComponent; | |
22 | import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; | |
23 | import org.eclipse.ui.views.properties.IPropertyDescriptor; | |
24 | ||
25 | /** | |
26 | * Property source implementation for the trace logger component. | |
27 | * | |
28 | * @author Bruno Roy | |
29 | */ | |
30 | public class TraceLoggerPropertySource extends BasePropertySource { | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Constants | |
34 | // ------------------------------------------------------------------------ | |
35 | /** | |
36 | * The trace logger 'name' property ID. | |
37 | */ | |
38 | public static final String TRACE_LOGGER_NAME_PROPERTY_ID = "trace.logger.name"; //$NON-NLS-1$ | |
39 | /** | |
40 | * The trace logger 'log level' property ID. | |
41 | */ | |
42 | public static final String TRACE_LOGGER_LOGLEVEL_PROPERTY_ID = "trace.logger.loglevel"; //$NON-NLS-1$ | |
43 | /** | |
44 | * The trace logger 'state' property ID. | |
45 | */ | |
46 | public static final String TRACE_LOGGER_STATE_PROPERTY_ID = "trace.logger.state"; //$NON-NLS-1$ | |
47 | ||
48 | /** | |
49 | * The trace logger 'name' property name. | |
50 | */ | |
51 | public static final String TRACE_LOGGER_NAME_PROPERTY_NAME = Messages.TraceControl_LoggerNamePropertyName; | |
52 | /** | |
53 | * The trace logger 'log level' property name. | |
54 | */ | |
55 | public static final String TRACE_LOGGER_LOGLEVEL_PROPERTY_NAME = Messages.TraceControl_LogLevelPropertyName; | |
56 | /** | |
57 | * The trace logger 'state' property name. | |
58 | */ | |
59 | public static final String TRACE_LOGGER_STATE_PROPERTY_NAME = Messages.TraceControl_StatePropertyName; | |
60 | ||
61 | // ------------------------------------------------------------------------ | |
62 | // Attributes | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | /** | |
66 | * The logger component which this property source is for. | |
67 | */ | |
68 | protected final TraceLoggerComponent fLogger; | |
69 | ||
70 | // ------------------------------------------------------------------------ | |
71 | // Constructors | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
74 | /** | |
75 | * Constructor | |
76 | * | |
77 | * @param component | |
78 | * the base logger component | |
79 | */ | |
80 | public TraceLoggerPropertySource(TraceLoggerComponent component) { | |
81 | fLogger = component; | |
82 | } | |
83 | ||
84 | // ------------------------------------------------------------------------ | |
85 | // Operations | |
86 | // ------------------------------------------------------------------------ | |
87 | ||
88 | @Override | |
89 | public IPropertyDescriptor[] getPropertyDescriptors() { | |
90 | List<IPropertyDescriptor> list = new ArrayList<>(); | |
91 | list.add(new ReadOnlyTextPropertyDescriptor(TRACE_LOGGER_NAME_PROPERTY_ID, TRACE_LOGGER_NAME_PROPERTY_NAME)); | |
92 | list.add(new ReadOnlyTextPropertyDescriptor(TRACE_LOGGER_STATE_PROPERTY_ID, TRACE_LOGGER_STATE_PROPERTY_NAME)); | |
74fe9bdd | 93 | if (!fLogger.getLogLevel().equals(TraceJulLogLevel.LEVEL_UNKNOWN) || !fLogger.getLogLevel().equals(TraceLog4jLogLevel.LEVEL_UNKNOWN)) { |
a20452b1 BR |
94 | list.add(new ReadOnlyTextPropertyDescriptor(TRACE_LOGGER_LOGLEVEL_PROPERTY_ID, TRACE_LOGGER_LOGLEVEL_PROPERTY_NAME)); |
95 | } | |
96 | return list.toArray(new IPropertyDescriptor[list.size()]); | |
97 | } | |
98 | ||
99 | @Override | |
100 | public Object getPropertyValue(Object id) { | |
101 | if (TRACE_LOGGER_NAME_PROPERTY_ID.equals(id)) { | |
102 | return fLogger.getName(); | |
74fe9bdd | 103 | } else if (TRACE_LOGGER_LOGLEVEL_PROPERTY_ID.equals(id)) { |
a20452b1 | 104 | StringBuffer buffer = new StringBuffer(); |
b5a170e0 BR |
105 | if (fLogger.getLogLevelType().equals(LogLevelType.LOGLEVEL_ALL)) { |
106 | buffer.append(fLogger.getLogLevelType().getShortName()); | |
107 | } else { | |
0a004264 | 108 | buffer.append(fLogger.getLogLevelType().getShortName()).append(" "); //$NON-NLS-1$ |
b5a170e0 | 109 | buffer.append(fLogger.getLogLevel().getInName()); |
a20452b1 | 110 | } |
a20452b1 | 111 | return buffer.toString(); |
74fe9bdd | 112 | } else if (TRACE_LOGGER_STATE_PROPERTY_ID.equals(id)) { |
a20452b1 BR |
113 | return fLogger.getState().name(); |
114 | } | |
115 | return null; | |
116 | } | |
117 | ||
118 | } |