use of com.haulmont.chile.core.datatypes.impl.BooleanDatatype in project cuba by cuba-platform.
the class AppPropertiesEdit method init.
@Override
public void init(Map<String, Object> params) {
cannotEditValueLabel.setVisible(item.getOverridden());
Datatype datatype = Datatypes.get(item.getDataTypeName());
fieldGroup.addCustomField("currentValue", (datasource, propertyId) -> {
if (item.getOverridden()) {
TextField textField = componentsFactory.createComponent(TextField.class);
textField.setValue(item.getDisplayedCurrentValue());
textField.setEditable(false);
return textField;
}
if (item.getEnumValues() != null) {
return createLookupField(Arrays.asList(item.getEnumValues().split(",")), item.getCurrentValue());
} else {
if (datatype instanceof BooleanDatatype) {
return createLookupField(Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString()), item.getCurrentValue());
} else {
if (Boolean.TRUE.equals(item.getSecret())) {
PasswordField passwordField = componentsFactory.createComponent(PasswordField.class);
passwordField.setValue(item.getCurrentValue());
passwordField.addValueChangeListener(e -> {
appPropertyDs.getItem().setCurrentValue(e.getValue() == null ? null : e.getValue().toString());
});
return passwordField;
} else {
TextField textField = componentsFactory.createComponent(TextField.class);
textField.setValue(item.getCurrentValue());
try {
datatype.parse(item.getCurrentValue(), userSessionSource.getLocale());
textField.setDatatype(datatype);
} catch (ParseException e) {
// do not assign datatype then
log.trace("Localized parsing by datatype cannot be used for value {}", item.getCurrentValue());
}
textField.addValueChangeListener(e -> {
appPropertyDs.getItem().setCurrentValue(e.getValue() == null ? null : e.getValue().toString());
});
return textField;
}
}
}
});
final Formatter<String> defaultValueFormatter = (value) -> {
if (datatype instanceof BooleanDatatype) {
return value;
}
try {
Object parsedDefaultValue = datatype.parse(value);
return datatype.format(parsedDefaultValue, userSessionSource.getLocale());
} catch (ParseException e) {
log.trace("Localized parsing by datatype cannot be used for value {}", value, e);
}
return value;
};
displayedDefaultValueField.setFormatter(defaultValueFormatter);
appPropertyDs.setItem(metadata.getTools().copy(item));
}
Aggregations