use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class Form method setFieldValues.
public void setFieldValues(final Map<String, ? extends Object> values) {
if (Property.hasValue(values)) {
Invoke.later(() -> {
final Map<String, Object> newValues = new HashMap<>();
final Map<String, Pair<Object, Throwable>> fieldValueErrors = new HashMap<>();
try (BaseCloseable settingFieldValue = this.settingFieldValue.closeable(true)) {
for (final Entry<String, ? extends Object> entry : values.entrySet()) {
final String fieldName = entry.getKey();
Object fieldValue = entry.getValue();
final Field field = getField(fieldName);
if (field != null) {
try {
final boolean valueSet = field.setFieldValue(fieldValue);
fieldValue = field.getFieldValue();
if (!DataType.equal(this.fieldValueByName.put(fieldName, fieldValue), fieldValue) || valueSet) {
newValues.put(fieldName, fieldValue);
}
} catch (final Throwable e) {
fieldValueErrors.put(fieldName, new Pair<>(fieldValue, e));
}
}
}
}
for (final Entry<String, Object> entry : newValues.entrySet()) {
final String fieldName = entry.getKey();
final Object fieldValue = entry.getValue();
fireFieldValueChanged(null, fieldName, fieldValue);
fireFieldValueChanged(fieldName, fieldName, fieldValue);
}
if (!isSettingFieldValue()) {
if (!fieldValueErrors.isEmpty()) {
postSetFieldValuesErrors(fieldValueErrors);
}
if (!newValues.isEmpty()) {
postSetFieldValues(newValues);
}
}
});
}
}
Aggregations