Class SimplePropertyComponentBuilder

    • Field Detail

      • DEFAULT_BUILDER

        public static final FieldBuilder<?> DEFAULT_BUILDER
        Default field builder used when no registered predicate matches given property. It always produces a result.
    • Constructor Detail

      • SimplePropertyComponentBuilder

        public SimplePropertyComponentBuilder()
    • Method Detail

      • isExactlyType

        public static Predicate<Property<?,​?>> isExactlyType​(Class<?> type)
        Returns a Predicate that checks if a property is exactly of given type.
        Parameters:
        type - Type to check.
        Returns:
        A Predicate that checks if the given type is equal to the property's type.
      • isOfType

        public static Predicate<Property<?,​?>> isOfType​(Class<?> type)
        Returns a Predicate that checks if a property is of the given type (i.e. is a subclass or implementation of it).
        Parameters:
        type - Type to check.
        Returns:
        A Predicate that evaluates to type.isAssignableFrom(property.getType()).
      • buildPropertyField

        public <P,​C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,​P>> Optional<C> buildPropertyField​(Property<?,​P> property)
        Description copied from interface: PropertyComponentBuilder
        Builds a component for a given property.
        Specified by:
        buildPropertyField in interface PropertyComponentBuilder
        Type Parameters:
        P - Type of the value of the property.
        C - Component to be returned.
        Parameters:
        property - Property to build a component for.
        Returns:
        A component capable of displaying the value of the given property, if any.
      • getRegisteredBuilders

        public Map<Predicate<Property<?,​?>>,​FieldBuilder<?>> getRegisteredBuilders()
        Returns the builders registered so far. Modifications of the returned map will affect this object.
        Returns:
        A non-null, but possibly empty, Map of registered FieldBuilders with matching Predicates.
      • registerType

        public <P,​C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,​P>> void registerType​(Class<P> valueType,
                                                                                                                                         com.vaadin.flow.function.SerializableSupplier<C> componentSupplier)
        Registers a builder for a given Component for properties of exactly the given valueType.
        Type Parameters:
        P - Value type.
        C - Component type.
        Parameters:
        valueType - Type of the property.
        componentSupplier - Supplier of component capable of displaying value of the given type.
      • withRegisteredType

        public final <P,​C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,​P>> SimplePropertyComponentBuilder withRegisteredType​(Class<P> valueType,
                                                                                                                                                                               com.vaadin.flow.function.SerializableSupplier<C> componentSupplier)
        Type Parameters:
        P - Value type.
        C - Component type.
        Parameters:
        valueType - Type of the property.
        componentSupplier - Supplier of component capable of displaying value of the given type.
        Returns:
        This.
        See Also:
        registerType(Class, SerializableSupplier)
      • registerBuilder

        public <P> void registerBuilder​(Class<P> valueType,
                                        FieldBuilder<P> builder)
        Registers a given builder with a predicate that checks for a given (not exact) type.
        Type Parameters:
        P - Property value type.
        Parameters:
        valueType - Type to check.
        builder - Builder to register.
      • registerBuilder

        public <P> void registerBuilder​(Predicate<Property<?,​P>> predicate,
                                        FieldBuilder<P> builder)
        Registers a given Predicate and its matching FieldBuilder.
        Type Parameters:
        P - Property value type.
        Parameters:
        predicate - Predicate.
        builder - Builder.
      • isDefaultLabel

        public boolean isDefaultLabel()
        Checks if the produced component should have its label set to default.
        Returns:
        When true (default), the created component will have its label set to human-readable version of the property name, if it is possible.
      • setDefaultLabel

        public void setDefaultLabel​(boolean defaultLabel)
        Controls whether the produced component should have its label set to default.
        Parameters:
        defaultLabel - When true, the created component will have its label set to human-readable version of the property name, if it is possible.
      • withDefaultLabel

        public final SimplePropertyComponentBuilder withDefaultLabel​(boolean state)
        Chains setDefaultLabel(boolean) and returns itself.
        Parameters:
        state - When true, the created component will have its label set to human-readable version of the property name, if it is possible.
        Returns:
        This.
      • setDefaultBuilder

        public void setDefaultBuilder​(FieldBuilder<?> defaultBuilder)
        Sets a new default FieldBuilder, i.e. the builder used when none of the registered builders are suitable.
        Parameters:
        defaultBuilder - New builder. When null is passed, DEFAULT_BUILDER will be used instead.
      • getDefaultBuilder

        public final FieldBuilder<?> getDefaultBuilder()
        Returns the current default FieldBuilder, i.e. the builder used when none of the registered builders are suitable.
        Returns:
        The current default FieldBuilder. Never null.