|
24 | 24 | */
|
25 | 25 | package org.graalvm.visualvm.jfr.generic.model.impl;
|
26 | 26 |
|
| 27 | +import java.text.FieldPosition; |
| 28 | +import java.text.Format; |
| 29 | +import java.text.ParsePosition; |
27 | 30 | import java.util.Iterator;
|
28 | 31 | import org.graalvm.visualvm.jfr.model.JFRDataDescriptor;
|
29 | 32 | import org.openjdk.jmc.common.item.IAccessorKey;
|
30 | 33 | import org.openjdk.jmc.common.item.IType;
|
| 34 | +import org.openjdk.jmc.common.unit.ContentType; |
| 35 | +import org.openjdk.jmc.common.unit.IFormatter; |
31 | 36 | import org.openjdk.jmc.common.unit.LinearKindOfQuantity;
|
32 | 37 | import org.openjdk.jmc.common.util.TypeHandling;
|
33 | 38 | import org.openjdk.jmc.flightrecorder.JfrAttributes;
|
@@ -82,11 +87,38 @@ private boolean isDisplayable(IAccessorKey key) {
|
82 | 87 | static JFRDataDescriptor getDataDescriptor(IAccessorKey key) {
|
83 | 88 | String dataName = TypeHandling.getValueString(key);
|
84 | 89 | String dataDescription = TypeHandling.getVerboseString(key);
|
85 |
| - boolean isNumericData = key.getContentType() instanceof LinearKindOfQuantity; |
86 |
| - return new JFRDataDescriptor(dataName, dataDescription, null, null, isNumericData); |
| 90 | + ContentType contentType = key.getContentType(); |
| 91 | + Format dataFormat = new DataFormat(contentType.getDefaultFormatter()); |
| 92 | + boolean isNumericData = contentType instanceof LinearKindOfQuantity; |
| 93 | + return new JFRDataDescriptor(dataName, dataDescription, dataFormat, null, isNumericData); |
87 | 94 | }
|
88 | 95 |
|
89 | 96 |
|
90 | 97 | private DisplayableSupport() {}
|
91 | 98 |
|
| 99 | + |
| 100 | + private static class DataFormat extends Format { |
| 101 | + |
| 102 | + private final IFormatter formatter; |
| 103 | + |
| 104 | + |
| 105 | + DataFormat(IFormatter formatter) { |
| 106 | + this.formatter = formatter; |
| 107 | + } |
| 108 | + |
| 109 | + |
| 110 | + @Override |
| 111 | + public StringBuffer format(Object o, StringBuffer b, FieldPosition p) { |
| 112 | + if (o == null) return b.append(""); // NOI18N |
| 113 | + if (o instanceof String) return b.append(o.toString()); |
| 114 | + return b.append(formatter.format(o)); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public Object parseObject(String source, ParsePosition pos) { |
| 119 | + throw new UnsupportedOperationException("Not supported."); // NOI18N |
| 120 | + } |
| 121 | + |
| 122 | + } |
| 123 | + |
92 | 124 | }
|
0 commit comments