use of com.haulmont.cuba.gui.components.SupportsUserAction in project cuba by cuba-platform.
the class LookupBuilderProcessor method handleSelectionWithField.
@SuppressWarnings("unchecked")
protected <E extends Entity> void handleSelectionWithField(@SuppressWarnings("unused") LookupBuilder<E> builder, HasValue<E> field, Collection<E> itemsFromLookup) {
if (itemsFromLookup.isEmpty()) {
return;
}
Collection<E> selectedItems = transform(itemsFromLookup, builder);
Entity newValue = selectedItems.iterator().next();
View viewForField = clientConfig.getReloadUnfetchedAttributesFromLookupScreens() && metadataTools.isPersistent(newValue.getClass()) ? getViewForField(field) : null;
if (viewForField != null && !entityStates.isLoadedWithView(newValue, viewForField)) {
newValue = dataManager.reload(newValue, viewForField);
}
if (field instanceof LookupPickerField) {
LookupPickerField lookupPickerField = (LookupPickerField) field;
Options options = lookupPickerField.getOptions();
if (options instanceof EntityOptions) {
EntityOptions entityOptions = (EntityOptions) options;
if (entityOptions.containsItem(newValue)) {
entityOptions.updateItem(newValue);
}
if (lookupPickerField.isRefreshOptionsOnLookupClose()) {
entityOptions.refresh();
}
}
}
// In case of PickerField set the value as if the user had set it
if (field instanceof SupportsUserAction) {
((SupportsUserAction<E>) field).setValueFromUser((E) newValue);
} else {
field.setValue((E) newValue);
}
}
Aggregations