use of org.jkiss.dbeaver.model.data.DBDDataFormatter in project dbeaver by serge-rider.
the class DataFormatterProfile method createFormatter.
@Override
public DBDDataFormatter createFormatter(String typeId) throws IllegalAccessException, InstantiationException, IllegalArgumentException {
DataFormatterDescriptor descriptor = DataFormatterRegistry.getInstance().getDataFormatter(typeId);
if (descriptor == null) {
throw new IllegalArgumentException("Formatter '" + typeId + "' not found");
}
DBDDataFormatter formatter = descriptor.createFormatter();
Map<Object, Object> defProps = descriptor.getSample().getDefaultProperties(locale);
Map<Object, Object> props = getFormatterProperties(typeId);
Map<Object, Object> formatterProps = new HashMap<>();
if (defProps != null && !defProps.isEmpty()) {
formatterProps.putAll(defProps);
}
if (props != null && !props.isEmpty()) {
formatterProps.putAll(props);
}
formatter.init(locale, formatterProps);
return formatter;
}
use of org.jkiss.dbeaver.model.data.DBDDataFormatter in project dbeaver by serge-rider.
the class PrefPageDataFormat method reloadSample.
private void reloadSample() {
DataFormatterDescriptor formatterDescriptor = getCurrentFormatter();
if (formatterDescriptor == null) {
return;
}
try {
DBDDataFormatter formatter = formatterDescriptor.createFormatter();
Map<Object, Object> defProps = formatterDescriptor.getSample().getDefaultProperties(profileLocale);
Map<Object, Object> props = profileProperties.get(formatterDescriptor.getId());
Map<Object, Object> formatterProps = new HashMap<>();
if (defProps != null && !defProps.isEmpty()) {
formatterProps.putAll(defProps);
}
if (props != null && !props.isEmpty()) {
formatterProps.putAll(props);
}
formatter.init(profileLocale, formatterProps);
String sampleValue = formatter.formatValue(formatterDescriptor.getSample().getSampleValue());
sampleText.setText(sampleValue);
} catch (Exception e) {
//$NON-NLS-1$
log.warn("Can't render sample value", e);
}
}
Aggregations