com.vaadin.collaborationengine.
Class CollaborationBinder<BEAN>
- java.lang.Object
-
- com.vaadin.flow.data.binder.Binder<BEAN>
-
- com.vaadin.collaborationengine.CollaborationBinder<BEAN>
-
Type Parameters:
BEAN
- the bean typeAll Implemented Interfaces:
public class CollaborationBinder<BEAN> extends Binder<BEAN> implements HasExpirationTimeout
Extension of
Binder
for creating collaborative forms withCollaborationEngine
. In addition to Binder's data binding mechanism, CollaborationBinder synchronizes the field values between clients which are connected to the same topic viaTopicConnection
.Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CollaborationBinder.CollaborationBindingBuilderImpl<BEAN,FIELDVALUE,TARGET>
-
Nested classes/interfaces inherited from class com.vaadin.flow.data.binder.Binder
Binder.Binding<BEAN,TARGET>, Binder.BindingBuilder<BEAN,TARGET>, Binder.BindingBuilderImpl<BEAN,FIELDVALUE,TARGET>, Binder.BindingImpl<BEAN,FIELDVALUE,TARGET>
-
-
Constructor Summary
Constructors Constructor Description CollaborationBinder(Class<BEAN> beanType, UserInfo localUser)
Creates a new collaboration binder.
-
Method Summary
All Methods Modifier and Type Method Description <FIELDVALUE>
Binder.Binding<BEAN,FIELDVALUE>bind(HasValue<?,FIELDVALUE> field, ValueProvider<BEAN,FIELDVALUE> getter, Setter<BEAN,FIELDVALUE> setter)
Deprecated.
The method does not work with the collaboration binder.<FIELDVALUE>
Binder.Binding<BEAN,FIELDVALUE>bind(HasValue<?,FIELDVALUE> field, String propertyName)
Binds the given field to the property with the given name, as described in
Binder.bind(HasValue, String)
.void
bindInstanceFields(Object objectWithMemberFields)
Binds the member fields found in the given object, as described in
Binder.bindInstanceFields(Object)
.protected Binder.BindingBuilder<BEAN,?>
configureBinding(Binder.BindingBuilder<BEAN,?> baseBinding, PropertyDefinition<BEAN,?> definition)
Configures the
binding
with the property definitiondefinition
before it's being bound.protected <FIELDVALUE,TARGET>
Binder.BindingBuilder<BEAN,TARGET>doCreateBinding(HasValue<?,FIELDVALUE> field, Converter<FIELDVALUE,TARGET> converter, BindingValidationStatusHandler handler)
<FIELDVALUE>
Binder.BindingBuilder<BEAN,FIELDVALUE>forField(HasValue<?,FIELDVALUE> field)
Creates a new binding for the given field.
<FIELDVALUE extends Collection<ELEMENT>,ELEMENT>
Binder.BindingBuilder<BEAN,FIELDVALUE>forField(HasValue<?,FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType)
Creates a new binding for the given (multi select) field whose value type is a collection.
<FIELDVALUE>
Binder.BindingBuilder<BEAN,FIELDVALUE>forField(HasValue<?,FIELDVALUE> field, Class<FIELDVALUE> fieldType)
Creates a new binding for the given field and type.
<FIELDVALUE>
Binder.BindingBuilder<BEAN,FIELDVALUE>forMemberField(HasValue<?,FIELDVALUE> field)
Creates a new binding for the given field.
<FIELDVALUE extends Collection<ELEMENT>,ELEMENT>
Binder.BindingBuilder<BEAN,FIELDVALUE>forMemberField(HasValue<?,FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType)
Creates a new binding for the given (multi select) field whose value type is a collection.
<FIELDVALUE>
Binder.BindingBuilder<BEAN,FIELDVALUE>forMemberField(HasValue<?,FIELDVALUE> field, Class<FIELDVALUE> fieldType)
Creates a new binding for the given field and type.
BEAN
getBean()
Deprecated.
This operation, along withsetBean(Object)
, is not supported by the collaboration binder.Optional<Duration>
getExpirationTimeout()
Gets the optional expiration timeout of this binder.
void
readBean(BEAN bean)
Deprecated.
This operation is not supported by the collaboration binder.protected void
removeBindingInternal(Binder.Binding<BEAN,?> binding)
Removes (internally) the
Binding
from the bound properties map (if present) and from the list ofBinding
s.void
reset(BEAN bean)
Resets collaborative fields with values from the bound properties of the given bean.
void
setBean(BEAN bean)
Deprecated.
This operation is not supported by the collaboration binder.void
setExpirationTimeout(Duration expirationTimeout)
Sets the expiration timeout of this binder.
<T> void
setSerializer(Class<T> type, SerializableFunction<T,String> serializer, SerializableFunction<String,T> deserializer)
Sets a custom serializer and deserializer to use for a specific value type.
void
setTopic(String topicId, SerializableSupplier<BEAN> initialBeanSupplier)
Sets the topic to use with this binder and initializes the topic contents if not already set.
-
Methods inherited from class com.vaadin.flow.data.binder.Binder
addListener, addStatusChangeListener, addValueChangeListener, bindReadOnly, bindReadOnly, clearError, createBinding, getBeanState, getBinding, getBindingExceptionHandler, getBindings, getConverterFactory, getFields, getStatusLabel, getValidationErrorHandler, getValidationStatusHandler, handleBinderValidationStatus, handleError, handleFieldValueChange, handleValidationStatus, hasChanges, isFieldsValidationStatusChangeListenerEnabled, isValid, isValidatorsDisabled, refreshFields, removeBean, removeBinding, removeBinding, removeBinding, restoreBeanState, setBindingExceptionHandler, setFieldsValidationStatusChangeListenerEnabled, setReadOnly, setStatusLabel, setValidationErrorHandler, setValidationStatusHandler, setValidatorsDisabled, validate, validate, withPropertySet, withValidator, withValidator, withValidator, writeBean, writeBeanAsDraft, writeBeanAsDraft, writeBeanIfValid
-
-
-
-
Constructor Detail
-
CollaborationBinder
public CollaborationBinder(Class<BEAN> beanType, UserInfo localUser)
Creates a new collaboration binder. It uses reflection based on the provided bean type to resolve bean properties.
The provided user information is used in the field editing indicators. The name of the user will be displayed to other users when editing a field, and the user's color index will be used to set the field's highlight color.
Parameters:
beanType
- the bean type to use, notnull
localUser
- the information of the local user, notnull
Since:
1.0
-
-
Method Detail
-
configureBinding
protected Binder.BindingBuilder<BEAN,?> configureBinding(Binder.BindingBuilder<BEAN,?> baseBinding, PropertyDefinition<BEAN,?> definition)
Description copied from class:
Binder
Configures the
binding
with the property definitiondefinition
before it's being bound.Overrides:
configureBinding
in classBinder<BEAN>
Parameters:
baseBinding
- a binding to configuredefinition
- a property definition informationReturns:
the new configured binding
-
removeBindingInternal
protected void removeBindingInternal(Binder.Binding<BEAN,?> binding)
Description copied from class:
Binder
Removes (internally) the
Binding
from the bound properties map (if present) and from the list ofBinding
s. Note that this DOES NOT remove theValueChangeListener
that theBinding
might have registered with anyHasValue
s or decouple theBinder
from within theBinding
. To do that, useBinder.Binding.unbind()
This method should just be used for internal cleanup.Overrides:
removeBindingInternal
in classBinder<BEAN>
Parameters:
binding
- TheBinding
to remove from the binding map
-
doCreateBinding
protected <FIELDVALUE,TARGET> Binder.BindingBuilder<BEAN,TARGET> doCreateBinding(HasValue<?,FIELDVALUE> field, Converter<FIELDVALUE,TARGET> converter, BindingValidationStatusHandler handler)
Overrides:
doCreateBinding
in classBinder<BEAN>
-
bind
@Deprecated public <FIELDVALUE> Binder.Binding<BEAN,FIELDVALUE> bind(HasValue<?,FIELDVALUE> field, ValueProvider<BEAN,FIELDVALUE> getter, Setter<BEAN,FIELDVALUE> setter)
Deprecated.The method does not work with the collaboration binder. Usebind(HasValue, String)
instead.Not supported by the collaboration binder! It requires a property name for binding, so the other overload
bind(HasValue, String)
should be used instead.See
Binder.bind(HasValue, ValueProvider, Setter)
to learn how to use the method with the regular (non-collaboration) binder.Overrides:
Type Parameters:
FIELDVALUE
- the value type of the fieldParameters:
field
- the field to bind, notnull
getter
- the function to get the value of the property to the field, notnull
setter
- the function to write the field value to the property ornull
if read-onlyReturns:
the newly created binding
Throws:
UnsupportedOperationException
- as the method is not supported by the collaboration binder
-
bind
public <FIELDVALUE> Binder.Binding<BEAN,FIELDVALUE> bind(HasValue<?,FIELDVALUE> field, String propertyName)
Binds the given field to the property with the given name, as described in
Binder.bind(HasValue, String)
.In addition, synchronizes the values with other collaboration binder instances which are connected to the same topic.
Overrides:
Type Parameters:
FIELDVALUE
- the value type of the field to bindParameters:
field
- the field to bind, notnull
propertyName
- the name of the property to bind, notnull
Returns:
the newly created binding
Throws:
IllegalArgumentException
- if the property name is invalidIllegalArgumentException
- if the property has no accessible getterSee Also:
-
bindInstanceFields
public void bindInstanceFields(Object objectWithMemberFields)
Binds the member fields found in the given object, as described in
Binder.bindInstanceFields(Object)
.In addition, synchronizes the values with other collaboration binder instances which are connected to the same topic.
Overrides:
bindInstanceFields
in classBinder<BEAN>
Parameters:
objectWithMemberFields
- the object that contains (Java) member fields to bindThrows:
IllegalStateException
- if there are incompatible HasValue<T> and property typesSee Also:
-
setBean
@Deprecated public void setBean(BEAN bean)
Deprecated.This operation is not supported by the collaboration binder. You can instead provide the bean for populating the fields usingsetTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>)
, and write the values back to the bean usingBinder.writeBean(BEAN)
.Description copied from class:
Binder
Binds the given bean to all the fields added to this Binder. A
null
value removes a currently bound bean.When a bean is bound, the field values are updated by invoking their corresponding getter functions. Any changes to field values are reflected back to their corresponding property values of the bean as long as the bean is bound.
Any change made in the fields also runs validation for the field
Binder.Binding
and bean level validation for this binder (bean level validators are added usingBinder.withValidator(Validator)
.After updating each field, the value is read back from the field and the bean's property value is updated if it has been changed from the original value by the field or a converter.
Overrides:
Parameters:
bean
- the bean to edit, ornull
to remove a currently bound bean and clear bound fieldsSee Also:
Binder.readBean(Object)
,Binder.writeBean(Object)
,Binder.writeBeanIfValid(Object)
,Binder.refreshFields()
-
getBean
@Deprecated public BEAN getBean()
Deprecated.This operation, along withsetBean(Object)
, is not supported by the collaboration binder. Instead ofsetBean(Object)
, you can provide the bean for populating the fields usingsetTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>)
, and write the values back to the bean usingBinder.writeBean(BEAN)
.Description copied from class:
Binder
Returns the bean that has been bound with
Binder.bind(com.vaadin.flow.component.HasValue<?, FIELDVALUE>, com.vaadin.flow.function.ValueProvider<BEAN, FIELDVALUE>, com.vaadin.flow.data.binder.Setter<BEAN, FIELDVALUE>)
, or null if a bean is not currently bound.
-
readBean
@Deprecated public void readBean(BEAN bean)
Deprecated.This operation is not supported by the collaboration binder. You can instead provide the bean for populating the fields usingsetTopic(java.lang.String, com.vaadin.flow.function.SerializableSupplier<BEAN>)
to avoid overriding currently edited values. If you explicitly want to reset the field values for every user currently editing the fields, you can usereset(BEAN)
.Description copied from class:
Binder
Reads the bound property values from the given bean to the corresponding fields.
The bean is not otherwise associated with this binder; in particular its property values are not bound to the field value changes. To achieve that, use
Binder.setBean(Object)
.Overrides:
readBean
in classBinder<BEAN>
Parameters:
bean
- the bean whose property values to read ornull
to clear bound fieldsSee Also:
Binder.setBean(Object)
,Binder.writeBeanIfValid(Object)
,Binder.writeBean(Object)
-
reset
public void reset(BEAN bean)
Resets collaborative fields with values from the bound properties of the given bean. The values will be propagated to all collaborating users.
Parameters:
bean
- the bean whose property values to read ornull
to clear bound fieldsSince:
1.0
-
setTopic
public void setTopic(String topicId, SerializableSupplier<BEAN> initialBeanSupplier)
Sets the topic to use with this binder and initializes the topic contents if not already set. Setting a topic removes the connection to the previous topic (if any) and resets all bindings based on values in the new topic. The bean supplier is used to provide initial values for bindings in case the topic doesn't yet contain any values.
Parameters:
topicId
- the topic id to use, ornull
to not use any topicinitialBeanSupplier
- a supplier that is invoked to get a bean from which to read initial values. Only invoked if there are no property values in the topic, or if the topic id isnull
.Since:
1.0
-
forField
public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forField(HasValue<?,FIELDVALUE> field)
Creates a new binding for the given field. The returned builder may be further configured before invoking
Binder.BindingBuilder.bind(ValueProvider, Setter)
which completes the binding. UntilBinding.bind
is called, the binding has no effect.Note: Not all
HasValue
implementations support passingnull
as the value. For these the Binder will automatically changenull
to a null representation provided byHasValue.getEmptyValue()
. This conversion is one-way only, if you want to have a two-way mapping back tonull
, useBinder.BindingBuilder.withNullRepresentation(Object)
.The field value will be sent over the network to synchronize the value with other users also editing the same field. The value type to use for deserializing the value is automatically determined based on the bean property type. The type must be defined separately using another overload of this method in case a converter is used or if the property type is parameterized.
-
forField
public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forField(HasValue<?,FIELDVALUE> field, Class<FIELDVALUE> fieldType)
Creates a new binding for the given field and type. The returned builder may be further configured before invoking
Binder.BindingBuilder.bind(String)
which completes the binding. UntilBinding.bind
is called, the binding has no effect.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the type to use. This is necessary when a converter is used since it's then not possible to derive the type from the bean property.
Type Parameters:
FIELDVALUE
- the value type of the fieldParameters:
field
- the field to be bound, notnull
fieldType
- the type of the field value, notnull
Returns:
the new binding builder
See Also:
forField(HasValue)
,forField(HasValue, Class, Class)
,setSerializer(Class, SerializableFunction, SerializableFunction)
-
forField
public <FIELDVALUE extends Collection<ELEMENT>,ELEMENT> Binder.BindingBuilder<BEAN,FIELDVALUE> forField(HasValue<?,FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType)
Creates a new binding for the given (multi select) field whose value type is a collection. The returned builder may be further configured before invoking
Binder.BindingBuilder.bind(String)
which completes the binding. UntilBinding.bind
is called, the binding has no effect.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the collection type and element type to use.
Type Parameters:
FIELDVALUE
- the base type of the collection, e.g.Set
forCheckboxGroup<String>
ELEMENT
- the type of the elements in the collection, e.g.String
forCheckboxGroup<String>
Parameters:
field
- the field to be bound, notnull
collectionType
- the base type of the collection, e.g.Set.class
forCheckboxGroup<String>
, notnull
elementType
- the type of the elements in the collection, e.g.String.class
forCheckboxGroup<String>
, notnull
Returns:
the new binding builder
See Also:
forField(HasValue)
,forField(HasValue, Class)
,setSerializer(Class, SerializableFunction, SerializableFunction)
-
forMemberField
public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(HasValue<?,FIELDVALUE> field)
Creates a new binding for the given field. The returned builder may be further configured before invoking
Binder.bindInstanceFields(Object)
. Unlike with theBinder.forField(HasValue)
method, no explicit call toBinder.BindingBuilder.bind(String)
is needed to complete this binding in the case that the name of the field matches a field name found in the bean.The field value will be sent over the network to synchronize the value with other users also editing the same field. The value type to use for deserializing the value is automatically determined based on the bean property type. The type must be defined separately using another overload of this method in case a converter is used or if the property type is parameterized.
Overrides:
forMemberField
in classBinder<BEAN>
Type Parameters:
FIELDVALUE
- the value type of the fieldParameters:
field
- the field to be bound, not nullReturns:
the new binding builder
See Also:
forMemberField(HasValue, Class)
,forMemberField(HasValue, Class, Class)
-
forMemberField
public <FIELDVALUE> Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(HasValue<?,FIELDVALUE> field, Class<FIELDVALUE> fieldType)
Creates a new binding for the given field and type. The returned builder may be further configured before invoking
bindInstanceFields(Object)
. Unlike with theforField(HasValue)
method, no explicit call toBinder.BindingBuilder.bind(String)
is needed to complete this binding in the case that the name of the field matches a field name found in the bean.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the type to use. This is necessary when a converter is used since it's then not possible to derive the type from the bean property.
Type Parameters:
FIELDVALUE
- the value type of the fieldParameters:
field
- the field to be bound, notnull
fieldType
-Returns:
the new binding builder
Since:
1.0
See Also:
forMemberField(HasValue)
,forMemberField(HasValue, Class, Class)
,setSerializer(Class, SerializableFunction, SerializableFunction)
-
forMemberField
public <FIELDVALUE extends Collection<ELEMENT>,ELEMENT> Binder.BindingBuilder<BEAN,FIELDVALUE> forMemberField(HasValue<?,FIELDVALUE> field, Class<? super FIELDVALUE> collectionType, Class<ELEMENT> elementType)
Creates a new binding for the given (multi select) field whose value type is a collection. The returned builder may be further configured before invoking
bindInstanceFields(Object)
. Unlike with theforField(HasValue)
method, no explicit call toBinder.BindingBuilder.bind(String)
is needed to complete this binding in the case that the name of the field matches a field name found in the bean.The field value will be sent over the network to synchronize the value with other users also editing the same field. This method allows explicitly defining the collection type and element type to use.
Type Parameters:
FIELDVALUE
- the base type of the collection, e.g.Set
forCheckboxGroup<String>
ELEMENT
- the type of the elements in the collection, e.g.String
forCheckboxGroup<String>
Parameters:
field
- the field to be bound, notnull
collectionType
- the base type of the collection, e.g.Set.class
forCheckboxGroup<String>
, notnull
elementType
- the type of the elements in the collection, e.g.String.class
forCheckboxGroup<String>
, notnull
Returns:
the new binding builder
Since:
1.0
See Also:
forMemberField(HasValue)
,forMemberField(HasValue, Class)
,setSerializer(Class, SerializableFunction, SerializableFunction)
-
setSerializer
public <T> void setSerializer(Class<T> type, SerializableFunction<T,String> serializer, SerializableFunction<String,T> deserializer)
Sets a custom serializer and deserializer to use for a specific value type. The serializer and deserializer will be used for all field bindings that implicitly or explicitly use that type either as the field type or as the collection element type in case of multi select fields. It is not allowed to reconfigure the serializer and deserializer for a previously configued type nor for any of the basic types that are supported without custom logic.
Field values will be sent over the network to synchronize the value with other users also editing the same field. This method allows defining callbacks to convert between the field value and the value that is sent over the network. This is necessary when using complex objects that are not suitable to be sent as-is over the network.
Type Parameters:
T
- the type handled by the serializerParameters:
type
- the type for which to set a serializer and deserializer, notnull
serializer
- a callback that receives a non-empty field value and returns the value to send over the network (notnull
). The callback cannot benull
.deserializer
- a callback that receives a value produced by the serializer callback (notnull
) and returns the field value to use. The callback cannot benull
.Since:
1.0
-
getExpirationTimeout
public Optional<Duration> getExpirationTimeout()
Gets the optional expiration timeout of this binder. An empty
Optional
is returned if no timeout is set, which means the binder is not cleared when there are no connected users to the related topic (this is the default).Specified by:
getExpirationTimeout
in interfaceHasExpirationTimeout
Returns:
the expiration timeout
Since:
3.1
-
setExpirationTimeout
public void setExpirationTimeout(Duration expirationTimeout)
Sets the expiration timeout of this binder. If set, this binder data is cleared when
expirationTimeout
has passed after the last connection to the related topic is closed. If set tonull
, the timeout is cancelled.Specified by:
setExpirationTimeout
in interfaceHasExpirationTimeout
Parameters:
expirationTimeout
- the expiration timeoutSince:
3.1
-
-