Search in sources :

Example 1 with DBDDataFormatter

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;
}
Also used : DBDDataFormatter(org.jkiss.dbeaver.model.data.DBDDataFormatter) HashMap(java.util.HashMap)

Example 2 with DBDDataFormatter

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);
    }
}
Also used : DBDDataFormatter(org.jkiss.dbeaver.model.data.DBDDataFormatter) DataFormatterDescriptor(org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor)

Aggregations

DBDDataFormatter (org.jkiss.dbeaver.model.data.DBDDataFormatter)2 HashMap (java.util.HashMap)1 DataFormatterDescriptor (org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor)1