Class AbstractSingleUploadField<C extends AbstractSingleUploadField<C,V>,V>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<C,V>
io.jmix.flowui.kit.component.upload.AbstractSingleUploadField<C,V>
Type Parameters:
C - type of upload field
V - value type
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C,V>,V>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C,V>,V>, com.vaadin.flow.component.shared.HasTooltip, Serializable
Direct Known Subclasses:
JmixFileStorageUploadField, JmixFileUploadField

@Tag("jmix-upload-field") @JsModule("./src/uploadfield/jmix-upload-field.js") public abstract class AbstractSingleUploadField<C extends AbstractSingleUploadField<C,V>,V> extends com.vaadin.flow.component.AbstractField<C,V> implements com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.shared.HasTooltip
See Also:
  • Field Details

    • INPUT_CONTAINER_CLASS_NAME

      protected static final String INPUT_CONTAINER_CLASS_NAME
      See Also:
    • FILE_NAME_COMPONENT_CLASS_NAME

      protected static final String FILE_NAME_COMPONENT_CLASS_NAME
      See Also:
    • FILE_NAME_COMPONENT_EMPTY_CLASS_NAME

      protected static final String FILE_NAME_COMPONENT_EMPTY_CLASS_NAME
      See Also:
    • CLEAR_COMPONENT_CLASS_NAME

      protected static final String CLEAR_COMPONENT_CLASS_NAME
      See Also:
    • FILE_NOT_SELECTED

      protected static final String FILE_NOT_SELECTED
      See Also:
    • UPLOAD

      protected static final String UPLOAD
      See Also:
    • CLEAR_COMPONENT_ARIA_LABEL

      protected static final String CLEAR_COMPONENT_ARIA_LABEL
      See Also:
    • NO_MARGIN_THEME

      protected static final String NO_MARGIN_THEME
      See Also:
    • uploadButton

      protected JmixUploadButton uploadButton
    • content

      protected com.vaadin.flow.component.HasComponents content
    • fileNameComponent

      protected com.vaadin.flow.component.Component fileNameComponent
    • clearComponent

      protected com.vaadin.flow.component.Component clearComponent
    • internalValue

      protected V internalValue
    • uploadText

      protected String uploadText
    • fileNotSelectedText

      protected String fileNotSelectedText
    • clearButtonVisible

      protected boolean clearButtonVisible
    • fileNameVisible

      protected boolean fileNameVisible
  • Constructor Details

    • AbstractSingleUploadField

      public AbstractSingleUploadField(V defaultValue)
  • Method Details

    • createUploadComponent

      protected JmixUploadButton createUploadComponent()
    • createContentComponent

      protected com.vaadin.flow.component.HasComponents createContentComponent()
    • createFileNameComponent

      protected com.vaadin.flow.component.Component createFileNameComponent()
    • initFileNameComponent

      protected void initFileNameComponent(com.vaadin.flow.component.Component fileNameComponent)
    • createClearComponent

      protected com.vaadin.flow.component.Component createClearComponent()
    • initClearComponent

      protected void initClearComponent(com.vaadin.flow.component.Component clearComponent)
    • onClearButtonClick

      protected void onClearButtonClick(com.vaadin.flow.component.ClickEvent<?> clickEvent)
    • attachContent

      protected void attachContent(com.vaadin.flow.component.HasComponents content)
    • initUploadComponent

      protected void initUploadComponent(JmixUploadButton upload)
    • createUploadButtonComponent

      protected com.vaadin.flow.component.Component createUploadButtonComponent()
    • initUploadButtonComponent

      protected void initUploadButtonComponent(com.vaadin.flow.component.Component component)
    • attachUploadEvents

      protected void attachUploadEvents(JmixUploadButton upload)
    • initContentComponent

      protected void initContentComponent(com.vaadin.flow.component.HasComponents component)
    • getContent

      protected <T extends com.vaadin.flow.component.HasComponents> T getContent()
    • createUploadReceiver

      protected com.vaadin.flow.component.upload.Receiver createUploadReceiver()
    • setValue

      public void setValue(@Nullable V value)
      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<C extends AbstractSingleUploadField<C,V>,V>
      Overrides:
      setValue in class com.vaadin.flow.component.AbstractField<C extends AbstractSingleUploadField<C,V>,V>
    • getValue

      @Nullable public V getValue()
      Specified by:
      getValue in interface com.vaadin.flow.component.HasValue<C extends AbstractSingleUploadField<C,V>,V>
      Overrides:
      getValue in class com.vaadin.flow.component.AbstractField<C extends AbstractSingleUploadField<C,V>,V>
    • getEmptyValue

      public V getEmptyValue()
      Specified by:
      getEmptyValue in interface com.vaadin.flow.component.HasValue<C extends AbstractSingleUploadField<C,V>,V>
      Overrides:
      getEmptyValue in class com.vaadin.flow.component.AbstractField<C extends AbstractSingleUploadField<C,V>,V>
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValue<C extends AbstractSingleUploadField<C,V>,V>
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValueAndElement<C extends AbstractSingleUploadField<C,V>,V>
    • setEnabled

      public void setEnabled(boolean enabled)
      Specified by:
      setEnabled in interface com.vaadin.flow.component.HasEnabled
    • addFileUploadProgressListener

      public com.vaadin.flow.shared.Registration addFileUploadProgressListener(com.vaadin.flow.component.ComponentEventListener<FileUploadProgressEvent<C>> listener)
      Adds file upload progress listener that is informed on upload progress.
      Parameters:
      listener - progress listener to add
      Returns:
      registration for removal of listener
    • onProgressEvent

      protected void onProgressEvent(com.vaadin.flow.component.upload.ProgressUpdateEvent event)
    • addFileUploadFinishedListener

      public com.vaadin.flow.shared.Registration addFileUploadFinishedListener(com.vaadin.flow.component.ComponentEventListener<FileUploadFinishedEvent<C>> listener)
      Adds a succeeded listener that is informed on upload finished.
      Parameters:
      listener - listener to add
      Returns:
      registration for removal of listener
    • onFinishedEvent

      protected void onFinishedEvent(com.vaadin.flow.component.upload.FinishedEvent event)
    • addFileUploadFailedListener

      public com.vaadin.flow.shared.Registration addFileUploadFailedListener(com.vaadin.flow.component.ComponentEventListener<FileUploadFailedEvent<C>> listener)
      Add a listener that is informed on upload failure.
      Parameters:
      listener - listener to add
      Returns:
      registration for removal of listener
    • onFailedEvent

      protected void onFailedEvent(com.vaadin.flow.component.upload.FailedEvent event)
    • addFileUploadStartedListener

      public com.vaadin.flow.shared.Registration addFileUploadStartedListener(com.vaadin.flow.component.ComponentEventListener<FileUploadStartedEvent<C>> listener)
      Add a succeeded listener that is informed on upload start.
      Parameters:
      listener - listener to add
      Returns:
      registration for removal of listener
    • onStartedEvent

      protected void onStartedEvent(com.vaadin.flow.component.upload.StartedEvent event)
    • addFileUploadFileRejectedListener

      public com.vaadin.flow.shared.Registration addFileUploadFileRejectedListener(com.vaadin.flow.component.ComponentEventListener<FileUploadFileRejectedEvent<C>> listener)
      Adds a listener for file-reject events fired when a file cannot be added due to some constrains:
      Parameters:
      listener - listener to add
      Returns:
      registration for removal of listener
    • onFileRejectedEvent

      protected void onFileRejectedEvent(com.vaadin.flow.component.upload.FileRejectedEvent event)
    • addFileUploadSucceededListener

      public com.vaadin.flow.shared.Registration addFileUploadSucceededListener(com.vaadin.flow.component.ComponentEventListener<FileUploadSucceededEvent<C>> listener)
      Add a succeeded listener that is informed on upload succeeded.
      Parameters:
      listener - listener to add
      Returns:
      registration for removal of listener
    • onSucceededEvent

      protected void onSucceededEvent(com.vaadin.flow.component.upload.SucceededEvent event)
    • getMaxFileSize

      public int getMaxFileSize()
      Returns:
      the maximum allowed file size in the client-side, in bytes
    • setMaxFileSize

      public void setMaxFileSize(int maxFileSize)
    • getAcceptedFileTypes

      public List<String> getAcceptedFileTypes()
      Returns:
      the list of accepted file types for upload
    • setAcceptedFileTypes

      public void setAcceptedFileTypes(String... acceptedFileTypes)
      Specify the types of files that the server accepts. Syntax: a MIME type pattern (wildcards are allowed) or file extensions. Notice that MIME types are widely supported, while file extensions are only implemented in certain browsers, so it should be avoided.

      Example: "video/*","image/tiff" or ".pdf","audio/mp3"

      Parameters:
      acceptedFileTypes - the allowed file types to be uploaded, or null to clear any restrictions
      See Also:
      • Upload.setAcceptedFileTypes(String...)
    • getI18n

      @Nullable public JmixUploadI18N getI18n()
      Returns:
      internationalization properties or null if not set
    • setI18n

      public void setI18n(JmixUploadI18N i18n)
      Sets the internationalization properties.
      Parameters:
      i18n - properties to set
    • getUploadIcon

      @Nullable public com.vaadin.flow.component.Component getUploadIcon()
      Returns:
      a component that is set as icon to upload button or null if not set
    • setUploadIcon

      public void setUploadIcon(@Nullable com.vaadin.flow.component.Component icon)
      Sets a component as icon to upload button.
      Parameters:
      icon - component to set as icon
    • isDropAllowed

      public boolean isDropAllowed()
      Returns:
      true if file dropping is enabled, false otherwise.
      See Also:
      • Upload.isDropAllowed()
    • setDropAllowed

      public void setDropAllowed(boolean allowed)
      Sets whether the component supports dropping files for uploading. The default value is true.

      See Upload.setDropAllowed(boolean) for details.

      Parameters:
      allowed - true to enable dropping
    • getUploadText

      @Nullable public String getUploadText()
      Returns:
      text that should be shown in the upload button or null if not set
    • setUploadText

      public void setUploadText(@Nullable String uploadText)
      Sets the text that should be shown in the upload button. null value resets the default value.
      Parameters:
      uploadText - text to set
    • getFileNotSelectedText

      @Nullable public String getFileNotSelectedText()
      Returns:
      text that is shown when file is not uploaded or null if not set
    • setFileNotSelectedText

      public void setFileNotSelectedText(@Nullable String fileNotSelectedText)
      Sets text that is shown when file is not uploaded
      Parameters:
      fileNotSelectedText - text to set
    • isFileNameVisible

      public boolean isFileNameVisible()
      Returns:
      true if name of uploaded file is shown
    • setFileNameVisible

      public void setFileNameVisible(boolean visible)
      Enables or disables displaying name of uploaded file.

      The default value is false.

      Parameters:
      visible - whether file name should be shown
    • isClearButtonVisible

      public boolean isClearButtonVisible()
      Returns:
      true if clear button is shown
    • setClearButtonVisible

      public void setClearButtonVisible(boolean visible)
      Enables or disables displaying clear button.

      The default value is false.

      Parameters:
      visible - whether clear button should be shown
    • getClearButtonAriaLabel

      @Nullable public String getClearButtonAriaLabel()
      Returns:
      aria-label of clear button or null if not set
    • setClearButtonAriaLabel

      public void setClearButtonAriaLabel(@Nullable String ariaLabel)
      Sets aria-label attribute to clear button.
      Parameters:
      ariaLabel - aria-label to set
    • addValueChangeListener

      public com.vaadin.flow.shared.Registration addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C,V>> listener)
      Specified by:
      addValueChangeListener in interface com.vaadin.flow.component.HasValue<C extends AbstractSingleUploadField<C,V>,V>
      Overrides:
      addValueChangeListener in class com.vaadin.flow.component.AbstractField<C extends AbstractSingleUploadField<C,V>,V>
    • setInternalValue

      protected void setInternalValue(@Nullable V value)
    • setInternalValue

      protected void setInternalValue(@Nullable V value, boolean fromClient)
    • setPresentationValue

      protected void setPresentationValue(@Nullable V newPresentationValue)
      Specified by:
      setPresentationValue in class com.vaadin.flow.component.AbstractField<C extends AbstractSingleUploadField<C,V>,V>
    • generateFileName

      protected abstract String generateFileName()
    • getDefaultUploadText

      protected abstract String getDefaultUploadText()
    • onJmixUploadInternalError

      protected void onJmixUploadInternalError(JmixUploadButton.JmixUploadInternalErrorEvent event)
    • handleJmixUploadInternalError

      protected void handleJmixUploadInternalError(String fileName)
    • addClassNames

      protected void addClassNames(com.vaadin.flow.component.HasElement component, String... classNames)
    • addThemeNames

      protected void addThemeNames(com.vaadin.flow.component.Component component, String... themeNames)
    • removeClassNames

      protected void removeClassNames(com.vaadin.flow.component.HasElement component, String... classNames)
    • setComponentEnabled

      protected void setComponentEnabled(com.vaadin.flow.component.Component component, boolean enabled)
    • setComponentText

      protected void setComponentText(com.vaadin.flow.component.Component component, String text)
    • setComponentClickListener

      protected void setComponentClickListener(com.vaadin.flow.component.Component component, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<?>> listener)
    • setComponentAriaLabel

      protected void setComponentAriaLabel(com.vaadin.flow.component.Component component, @Nullable String ariaLabel)
    • updateComponentsVisibility

      protected void updateComponentsVisibility()