Search in sources :

Example 1 with SupportsUserAction

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);
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) LookupPickerField(com.haulmont.cuba.gui.components.LookupPickerField) EntityOptions(com.haulmont.cuba.gui.components.data.meta.EntityOptions) Options(com.haulmont.cuba.gui.components.data.Options) SupportsUserAction(com.haulmont.cuba.gui.components.SupportsUserAction) EntityOptions(com.haulmont.cuba.gui.components.data.meta.EntityOptions)

Aggregations

Entity (com.haulmont.cuba.core.entity.Entity)1 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)1 SupportsUserAction (com.haulmont.cuba.gui.components.SupportsUserAction)1 Options (com.haulmont.cuba.gui.components.data.Options)1 EntityOptions (com.haulmont.cuba.gui.components.data.meta.EntityOptions)1