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();
}
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();
}
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();
}
}
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);
}
}
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);
}
}
Aggregations