Class EditorBuilder


  • public class EditorBuilder
    extends java.lang.Object
    Builder class to help creating and configuring Editor components
    • Constructor Detail

      • EditorBuilder

        public EditorBuilder​(WidgetInstanceManager widgetInstanceManager)
        Creates new builder for Editor that will work with provided widget.

        Specific implementations of facades may be provided.

        Parameters:
        widgetInstanceManager - editor manager of widget with which editor is supposed to work
      • EditorBuilder

        public EditorBuilder​(EditorContext<?> editorContext)
        Creates new builder basing on provided editor's context.
        Parameters:
        editorContext - base editor context
    • Method Detail

      • getTypeFacade

        protected TypeFacade getTypeFacade()
      • getObjectFacade

        protected ObjectFacade getObjectFacade()
      • getWidgetInstanceManager

        public WidgetInstanceManager getWidgetInstanceManager()
        Returns:
        editor manager of widget with which editor is supposed to work
      • build

        public Editor build()
        Builds editor component
        Returns:
        initialized and ready for use Editor
      • buildNotInitialized

        @Deprecated(since="6.7",
                    forRemoval=true)
        public Editor buildNotInitialized()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 6.7, please create an instance manually and use EditorConfigurator instead
        Builds editor component without initializing it. Initialization (Editor.initialize() should be performed before using Editor.
        Returns:
        configured but not initialized Editor
        See Also:
        EditorConfigurator
      • apply

        public EditorBuilder apply​(java.util.function.Consumer<Editor> configuration)
        Allows any modification of editor to be applied before it is initialized.
        Parameters:
        configuration - a function configuring editor
        Returns:
        builder for further settings
      • ifTrue

        public EditorBuilder.Conditional<Editor> ifTrue​(boolean test)
        Allows conditional modification of editor before it is initialized using flow programming.
        Parameters:
        test - condition to be met for modification to be applied
        Returns:
        an object that defines modification depending on condition
      • when

        public EditorBuilder.Conditional<EditorBuilder> when​(boolean test)
        Allows conditional builder configuration using flow programming.
        Parameters:
        test - condition to be met for configuration to be applied
        Returns:
        an object that defines configuration depending on condition
      • configure

        public EditorBuilder configure​(java.lang.String itemKey,
                                       DataAttribute attribute)
        Configures component to use default behavior for specified attribute of item
        Parameters:
        itemKey - model value key under which a manipulated item may be found
        attribute - attribute to be manipulated by editor
        Returns:
        builder for further settings
        See Also:
        configure(String, String)
      • configure

        public EditorBuilder configure​(java.lang.String itemKey,
                                       DataAttribute attribute,
                                       boolean editorValueDetached)
      • configure

        public EditorBuilder configure​(java.lang.String itemKey,
                                       java.lang.String qualifier)
        Configures component to use default behavior for specified attribute of item
        Parameters:
        itemKey - model value key under which a manipulated item may be found
        qualifier - qualifier of attribute to be manipulated by editor
        Returns:
        builder for further settings
        See Also:
        configure(String, DataAttribute)
      • configure

        public EditorBuilder configure​(DataType dataType)
        Configures component to use default behavior for specified type.

        Method should be used, if editor is not supposed to manipulate with any item, rather to provide a value of specified type.

        Parameters:
        dataType - type of value to be provided by editor
        Returns:
        builder for further settings
        See Also:
        configure(String, DataAttribute), configure(String, String)
      • attach

        public EditorBuilder attach​(java.lang.String qualifier)
        Configures editor in the way that it may be used to manipulate with values of specified attribute.
        Parameters:
        qualifier - qualifier of attribute which values will be changed by editor
        Returns:
        builder for further settings
      • attach

        public EditorBuilder attach​(java.lang.Object item,
                                    java.lang.String qualifier)
        Configures editor in the way that it may be used to manipulate with values of specified attribute.
        Parameters:
        item - item which attribute is to be manipulated
        qualifier - qualifier of attribute which values will be changed by editor
        Returns:
        builder for further settings
      • addParameter

        public EditorBuilder addParameter​(java.lang.String parameter,
                                          java.lang.Object value)
        Adds a parameter to editor's context.
        Parameters:
        parameter - parameter's name
        value - parameters's value
        Returns:
        builder for further settings
      • addParameters

        public <V> EditorBuilder addParameters​(java.util.Map<java.lang.String,​V> parameters)
        Adds parameters to editor's context.
        Parameters:
        parameters - parameters to be added
        Returns:
        builder for further settings
      • addParameters

        public <ELEMENT> EditorBuilder addParameters​(java.util.stream.Stream<ELEMENT> stream,
                                                     java.util.function.Function<ELEMENT,​java.lang.String> keySupplier,
                                                     java.util.function.Function<ELEMENT,​java.lang.Object> valueSupplier)
        Adds a parameter to editor's context.
        Parameters:
        stream - stream of parameters definitions
        keySupplier - a supplier to provide parameter name out of definition
        valueSupplier - a supplier to provide parameter value out of definition
        Returns:
        builder for further settings
      • setSingleValued

        public EditorBuilder setSingleValued()
        Changes all multivalued editors into single-valued - i.e. localized editors should allow providing values only for a single language, multi-reference editors should allow providing only single reference, etc.
        Returns:
        builder to continue configuration of editor
      • setReadOnly

        public EditorBuilder setReadOnly​(boolean readOnly)
        Informs whether editor value should work in read-only mode.
        Parameters:
        readOnly - true if value should work in read-only mode.
        Returns:
        builder to continue configuration of editor
      • setMultilingual

        public EditorBuilder setMultilingual​(boolean multilingual)
        Configures editor in context of allowing providing localized values in regards to specified flag.
        Parameters:
        multilingual - true if editor should allow localized values, false otherwise
        Returns:
        builder to continue configuration of editor
        See Also:
        setMultilingual(boolean, Object)
      • setMultilingual

        public EditorBuilder setMultilingual​(boolean multilingual,
                                             java.lang.Object item)
        Configures editor in context of allowing providing localized values in regards to specified flag.
        Parameters:
        item - item which attribute will be manipulated with editor
        multilingual - true if editor should allow localized values, false otherwise
        Returns:
        builder to continue configuration of editor
      • setOptional

        public EditorBuilder setOptional​(boolean optional)
        Informs whether editor value should be mandatory.
        Parameters:
        optional - true if value should not be mandatory
        Returns:
        builder to continue configuration of editor
      • setValue

        public EditorBuilder setValue​(java.lang.Object value)
        Initializes editor component with provided value.
        Parameters:
        value - value to be displayed initially
        Returns:
        builder to continue configuration of editor
      • setValueType

        public EditorBuilder setValueType​(java.lang.String valueType)
        Sets an encoded type of value that editor is supposed to provide (i.e. LIST(Product))

        Editor type is not updated in this method!

        Parameters:
        valueType - encoded value type
        Returns:
        builder to continue configuration of editor
        See Also:
        useEditor(String)
      • setEditorType

        @Deprecated(since="6.7",
                    forRemoval=true)
        public EditorBuilder setEditorType​(java.lang.String editorType)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 6.7, use useEditor(String) instead
      • useEditor

        public EditorBuilder useEditor​(java.lang.String editorType)
        Explicitly defines which editor definition should be used by component
        Parameters:
        editorType - editor definition id
        Returns:
        builder to continue configuration of editor
        See Also:
        setValueType(String)
      • useDefaultEditor

        public EditorBuilder useDefaultEditor()
        Updates editor definition to be used basing on value type
        Returns:
        builder to continue configuration of editor
        See Also:
        setValueType(String)
      • setEditor

        @Deprecated(since="6.7",
                    forRemoval=true)
        public EditorBuilder setEditor​(java.lang.String editorType)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 6.7, use #useEditor(String) instead
        Configures which editor should be used - either specified or default one.
        Parameters:
        editorType - editor to be used or null for default
        Returns:
        builder to continue configuration of editor
      • setValueCreationEnabled

        public EditorBuilder setValueCreationEnabled​(boolean enabled)
        Some editors allows creation new values (i.e. new items to be referenced). This method allows setting whether such possibility should be available.
        Parameters:
        enabled - true if value creation should be possible
        Returns:
        builder to continue configuration of editor
      • appendSClass

        public EditorBuilder appendSClass​(java.lang.String sclass)
        Adds a CSS class to editor component.
        Parameters:
        sclass - name of CSS class to be added
        Returns:
        builder to continue configuration of editor
      • setLabel

        public EditorBuilder setLabel​(java.lang.String label)
        Some editors are capable of decorating editor component with proper label (i.e. localized editors). Please provide proper label to make it possible.
        Parameters:
        label - label to be used
        Returns:
        builder to continue configuration of editor
      • setGroup

        public EditorBuilder setGroup​(java.lang.String groupName)
        Sets a name of editors group, that configured one belongs to. A name of group is then passed directly to editor.
        Parameters:
        groupName - name of group that contains configured editor
      • setDescription

        public EditorBuilder setDescription​(java.lang.String description)
        Some editors are capable of decorating editor component with proper description (i.e. localized editors). Please provide proper text to make it possible.
        Parameters:
        description - description to be used
        Returns:
        builder to continue configuration of editor
      • enableValidation

        @Deprecated(since="20.05")
        public EditorBuilder enableValidation​(java.lang.String modelKey,
                                              java.lang.String qualifier,
                                              ValidatableContainer container)
        Configures validation for editor.
        Parameters:
        modelKey - name of widget model value under which an item may be found, which attribute will be changed by editor
        qualifier - qualifier of attribute which values will be changed by editor
        container - validatable container
        Returns:
        builder to continue configuration of editor
      • enableValidation

        public EditorBuilder enableValidation​(ValidatableContainer container)
        Configures validation for editor.
        Parameters:
        container - validatable container
        Returns:
        builder to continue configuration of editor