Class DynamicFileDownloader

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.HtmlComponent
com.vaadin.flow.component.HtmlContainer
com.vaadin.flow.component.html.Anchor
org.vaadin.firitin.components.DynamicFileDownloader
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.html.Anchor>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.html.Anchor>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.html.Anchor>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, Serializable, FluentAttachNotifier<DynamicFileDownloader>, FluentComponent<DynamicFileDownloader>, FluentDetachNotifier<DynamicFileDownloader>, FluentHasEnabled<DynamicFileDownloader>

public class DynamicFileDownloader extends com.vaadin.flow.component.html.Anchor implements FluentComponent<DynamicFileDownloader>, FluentHasEnabled<DynamicFileDownloader>
An anchor which content is produced dynamically.
Author:
mstahv
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
    static class 
     

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText

    com.vaadin.flow.component.HasText.WhiteSpace
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.vaadin.flow.server.RequestHandler
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    DynamicFileDownloader(com.vaadin.flow.component.Component downloadComponent, String fileName, com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
     
    DynamicFileDownloader(String text, String fileName, com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.shared.Registration
    addDownloadFailedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownlocadFailedEvent> listener)
    Adds a listener that is executed when the file content streaming has failed due to an exception.
    com.vaadin.flow.shared.Registration
    addDownloadFinishedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadFinishedEvent> listener)
    Adds a listener that is executed when the file content has been streamed.
    Makes the download look like a button instead of a normal link.
    com.vaadin.flow.component.button.Button
     
    protected String
    getFileName(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request)
    Gets the filename of downloaded file.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    protected void
    onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
     
    void
    setDisableOnClick(boolean disableOnClick)
     
    void
    setFileHandler(com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
     
    void
    setFileName(String fileName)
     

    Methods inherited from class com.vaadin.flow.component.html.Anchor

    getHref, getTarget, getTargetValue, isRouterIgnore, onEnabledStateChanged, removeHref, setHref, setHref, setRouterIgnore, setTarget, setTarget

    Methods inherited from class com.vaadin.flow.component.HtmlComponent

    getTitle, setTitle

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentAttachNotifier

    withAttachListener

    Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentComponent

    setId, setVisible, withId, withVisible

    Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentDetachNotifier

    withDetachListener

    Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentHasEnabled

    withEnabled

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasAriaLabel

    getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasText

    getText, getWhiteSpace, setText, setWhiteSpace
  • Field Details

    • requestHandler

      protected com.vaadin.flow.server.RequestHandler requestHandler
  • Constructor Details

    • DynamicFileDownloader

      public DynamicFileDownloader(String text, String fileName, com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
    • DynamicFileDownloader

      public DynamicFileDownloader(com.vaadin.flow.component.Component downloadComponent, String fileName, com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
    • DynamicFileDownloader

      public DynamicFileDownloader()
  • Method Details

    • setDisableOnClick

      public void setDisableOnClick(boolean disableOnClick)
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • onDetach

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component
    • addDownloadFinishedListener

      public com.vaadin.flow.shared.Registration addDownloadFinishedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadFinishedEvent> listener)
      Adds a listener that is executed when the file content has been streamed. Note that the UI changes done in the listener don't necessarily happen live if you don't have @Push in use or use UI.setPollInterval(int) method.
      Parameters:
      listener - the listener
      Returns:
      the Registration you can use to remove this listener.
    • addDownloadFailedListener

      public com.vaadin.flow.shared.Registration addDownloadFailedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownlocadFailedEvent> listener)
      Adds a listener that is executed when the file content streaming has failed due to an exception. Note that the UI changes done in the listener don't necessarily happen live if you don't have @Push in use or use UI.setPollInterval(int) method.
      Parameters:
      listener - the listener
      Returns:
      the Registration you can use to remove this listener.
    • setFileHandler

      public void setFileHandler(com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
    • setFileName

      public void setFileName(String fileName)
    • getFileName

      protected String getFileName(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request)
      Gets the filename of downloaded file. Override if you want to generate the name dynamically.
      Parameters:
      session - the vaadin session
      request - the vaadin request
      Returns:
      the file name
    • asButton

      public DynamicFileDownloader asButton()
      Makes the download look like a button instead of a normal link.
      Returns:
      the same instance, fluent method
    • getButton

      public com.vaadin.flow.component.button.Button getButton()
      Returns:
      a Button component wrapped inside the file downloader, if configured as a Button