@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); } }
@SuppressWarnings("unchecked") protected void afterCommitOpenedEntity(Entity item) { if (pickerField instanceof LookupField) { LookupField lookupPickerField = ((LookupField) pickerField); EntityOptions entityOptionsSource = (EntityOptions) lookupPickerField.getOptions(); if (entityOptionsSource != null && entityOptionsSource.containsItem(item)) { entityOptionsSource.updateItem(item); } } if (pickerField.getValueSource() instanceof DatasourceValueSource) { DatasourceValueSource datasourceValueSource = (DatasourceValueSource) pickerField.getValueSource(); boolean modified = datasourceValueSource.isModified(); pickerField.setValue(item); datasourceValueSource.setModified(modified); } else { pickerField.setValue(item); } }
EntityOptions entityOptions = (EntityOptions) options; if (entityOptions.containsItem(editedEntity)) { entityOptions.updateItem(editedEntity);