Search in sources :

Example 1 with DataFormatterDescriptor

use of org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor in project dbeaver by serge-rider.

the class PrefPageDataFormat method reloadFormatter.

private void reloadFormatter() {
    DataFormatterDescriptor formatterDescriptor = getCurrentFormatter();
    if (formatterDescriptor == null) {
        return;
    }
    Map<Object, Object> formatterProps = profileProperties.get(formatterDescriptor.getId());
    Map<Object, Object> defaultProps = formatterDescriptor.getSample().getDefaultProperties(localeSelector.getSelectedLocale());
    propertySource = new PropertySourceCustom(formatterDescriptor.getProperties(), formatterProps);
    propertySource.setDefaultValues(defaultProps);
    propertiesControl.loadProperties(propertySource);
    reloadSample();
}
Also used : PropertySourceCustom(org.jkiss.dbeaver.runtime.properties.PropertySourceCustom) DataFormatterDescriptor(org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor)

Example 2 with DataFormatterDescriptor

use of org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor in project dbeaver by serge-rider.

the class PrefPageDataFormat method saveFormatterProperties.

private void saveFormatterProperties() {
    DataFormatterDescriptor formatterDescriptor = getCurrentFormatter();
    if (formatterDescriptor == null) {
        return;
    }
    Map<Object, Object> props = propertySource.getProperties();
    profileProperties.put(formatterDescriptor.getId(), props);
    reloadSample();
}
Also used : DataFormatterDescriptor(org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor)

Example 3 with DataFormatterDescriptor

use of org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor in project dbeaver by serge-rider.

the class PrefPageDataFormat method onLocaleChange.

private void onLocaleChange(Locale locale) {
    if (!locale.equals(profileLocale)) {
        profileLocale = locale;
        DataFormatterDescriptor formatter = getCurrentFormatter();
        if (formatter != null) {
            propertySource.setDefaultValues(formatter.getSample().getDefaultProperties(locale));
            propertiesControl.refresh();
        }
        reloadSample();
    }
}
Also used : DataFormatterDescriptor(org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor)

Example 4 with DataFormatterDescriptor

use of org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor in project dbeaver by serge-rider.

the class PrefPageDataFormat method setCurrentProfile.

private void setCurrentProfile(DBDDataFormatterProfile profile) {
    if (formatterProfile == profile) {
        return;
    }
    formatterProfile = profile;
    formatterDescriptors = new ArrayList<>(DataFormatterRegistry.getInstance().getDataFormatters());
    profileName = formatterProfile.getProfileName();
    profileLocale = formatterProfile.getLocale();
    profileProperties.clear();
    for (DataFormatterDescriptor dfd : formatterDescriptors) {
        Map<Object, Object> formatterProps = formatterProfile.getFormatterProperties(dfd.getId());
        if (formatterProps != null) {
            profileProperties.put(dfd.getId(), formatterProps);
        }
    }
    try {
        // Set locale
        localeSelector.setLocale(profileLocale);
        // Load types
        typeCombo.removeAll();
        for (DataFormatterDescriptor formatter : formatterDescriptors) {
            typeCombo.add(formatter.getName());
        }
        if (typeCombo.getItemCount() > 0) {
            typeCombo.select(0);
        }
        reloadFormatter();
    } catch (Exception e) {
        log.warn(e);
    }
}
Also used : DataFormatterDescriptor(org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor)

Example 5 with DataFormatterDescriptor

use of org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor 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

DataFormatterDescriptor (org.jkiss.dbeaver.registry.formatter.DataFormatterDescriptor)5 DBDDataFormatter (org.jkiss.dbeaver.model.data.DBDDataFormatter)1 PropertySourceCustom (org.jkiss.dbeaver.runtime.properties.PropertySourceCustom)1