protected Collection<V> refreshValueIfNeeded() { EntityOptions<V> options = (EntityOptions<V>) getOptions(); Collection<V> valueSourceValue = getValueSourceValue(); if (options == null || !isRefreshOptionsOnLookupClose()) { return valueSourceValue; } options.refresh(); for (V value : valueSourceValue) { options.getOptions() .filter(option -> Objects.equals(option.getId(), value.getId())) .findFirst() .ifPresent(option -> { valueSourceValue.remove(value); valueSourceValue.add(option); }); } return valueSourceValue; }
@SuppressWarnings("unchecked") protected <E extends Entity> void handleSelectionWithField(@SuppressWarnings("unused") LookupBuilder<E> builder, HasValue<E> field, Collection<E> selectedItems) { if (!selectedItems.isEmpty()) { Entity newValue = selectedItems.iterator().next(); 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); } } }
@SuppressWarnings("unchecked") protected void handleLookupWindowSelection(Collection items) { if (items.isEmpty()) { return; } Entity item = (Entity) items.iterator().next(); Entity newValue = transformValueFromLookupWindow(item); if (pickerField instanceof LookupPickerField) { LookupPickerField lookupPickerField = (LookupPickerField) pickerField; Options options = lookupPickerField.getOptions(); if (options instanceof EntityOptions) { EntityOptions entityOptionsSource = (EntityOptions) options; if (entityOptionsSource.containsItem(newValue)) { entityOptionsSource.updateItem(newValue); } if (lookupPickerField.isRefreshOptionsOnLookupClose()) { entityOptionsSource.refresh(); } } } // Set the value as if the user had set it pickerField.setValueFromUser(newValue); afterSelect(items); if (afterLookupSelectionHandler != null) { afterLookupSelectionHandler.onSelect(items); } }
if (options instanceof EntityOptions && lookupPickerField.isRefreshOptionsOnLookupClose()) { ((EntityOptions) options).refresh();