diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-09-05 16:29:14 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-09-05 16:29:14 +0300 |
commit | fac79ef88542358bb161aa7d783f0322501850d6 (patch) | |
tree | 3ef1df3f6c255a787e2d5d43fa32d1d65926bcaf /server/src/main | |
parent | bac31cfb7cb71b90d497eb6177c3862d2d861950 (diff) | |
download | vaadin-framework-fac79ef88542358bb161aa7d783f0322501850d6.tar.gz vaadin-framework-fac79ef88542358bb161aa7d783f0322501850d6.zip |
Add methods to remove Bindings from Binder (#9932)
Diffstat (limited to 'server/src/main')
-rw-r--r-- | server/src/main/java/com/vaadin/data/Binder.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index 64f389cc91..f76cdcda2c 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -2387,4 +2387,50 @@ public class Binder<BEAN> implements Serializable { public Stream<HasValue<?>> getFields() { return bindings.stream().map(Binding::getField); } + + /** + * Finds and removes all Bindings for the given field. + * + * @param field + * the field to remove from bindings + * + * @since 8.2 + */ + public void removeBinding(HasValue<?> field) { + Objects.requireNonNull(field, "Field can not be null"); + Set<BindingImpl<BEAN, ?, ?>> toRemove = bindings.stream() + .filter(binding -> field.equals(binding.getField())) + .collect(Collectors.toSet()); + toRemove.forEach(this::removeBinding); + } + + /** + * Removes the given Binding from this Binder. + * + * @param binding + * the binding to remove + * + * @since 8.2 + */ + public void removeBinding(Binding<BEAN, ?> binding) { + Objects.requireNonNull(binding, "Binding can not be null"); + if (bindings.remove(binding)) { + boundProperties.entrySet() + .removeIf(entry -> entry.getValue().equals(binding)); + } + } + + /** + * Finds and removes the Binding for the given property name. + * + * @param propertyName + * the propertyName to remove from bindings + * + * @since 8.2 + */ + public void removeBinding(String propertyName) { + Objects.requireNonNull(propertyName, "Property name can not be null"); + Optional.ofNullable(boundProperties.get(propertyName)) + .ifPresent(this::removeBinding); + } } |