@Override public void activate() { if (source.getState() == BindingState.ACTIVE) { optionsTarget.setOptions(source.getOptions()); } }
public <E extends Entity> void bind() { if (source instanceof EntityOptions && component instanceof HasValue) { this.componentValueChangeSubscription = ((HasValue<?>) component).addValueChangeListener(this::componentValueChanged); this.sourceValueChangeSupscription = ((EntityOptions<E>) source).addValueChangeListener(this::optionsSourceValueChanged); } this.sourceStateChangeSupscription = source.addStateChangeListener(this::optionsSourceStateChanged); this.sourceOptionsChangeSupscription = source.addOptionsChangeListener(this::optionsSourceOptionsChanged); }
protected void optionsSourceOptionsChanged(@SuppressWarnings("unused") Options.OptionsChangeEvent<V> event) { optionsTarget.setOptions(source.getOptions()); }
@Override protected Collection<V> convertToModel(Set<V> componentRawValue) throws ConversionException { Stream<V> items = optionsBinding == null ? Stream.empty() : optionsBinding.getSource().getOptions().filter(componentRawValue::contains); if (valueBinding != null) { Class<?> targetType = valueBinding.getSource().getType(); if (List.class.isAssignableFrom(targetType)) { return items.collect(Collectors.toList()); } else if (Set.class.isAssignableFrom(targetType)) { return items.collect(Collectors.toCollection(LinkedHashSet::new)); } } return items.collect(Collectors.toCollection(LinkedHashSet::new)); }
protected void optionsSourceStateChanged(Options.StateChangeEvent event) { if (event.getState() == BindingState.ACTIVE) { optionsTarget.setOptions(source.getOptions()); } }
protected void setItemsToPresentation(Stream<V> options) { component.setItems(options); // set value to Vaadin component as it removes value after setItems Collection<V> optionValues = getValue(); if (CollectionUtils.isNotEmpty(optionValues)) { List<V> items = getOptions().getOptions().collect(Collectors.toList()); Set<V> values = new HashSet<>(); for (V value : optionValues) { if (items.contains(value)) { values.add(value); } } component.setValue(values); } }