Package org.vaadin.firitin.components
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>
public class DynamicFileDownloader extends com.vaadin.flow.component.html.Anchor implements FluentComponent<DynamicFileDownloader>
An anchor which content is produced dynamically.- Author:
- mstahv
- See Also:
setFileName(java.lang.String),setFileHandler(com.vaadin.flow.function.SerializableConsumer), Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDynamicFileDownloader.DownloadFinishedEvent-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>
-
-
Field Summary
Fields Modifier and Type Field Description protected com.vaadin.flow.server.RequestHandlerrequestHandler
-
Constructor Summary
Constructors Constructor Description DynamicFileDownloader()DynamicFileDownloader(String text, String fileName, com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.vaadin.flow.shared.RegistrationaddDownloadFinishedListener(com.vaadin.flow.component.ComponentEventListener<DynamicFileDownloader.DownloadFinishedEvent> listener)Adds a listener that is executed when the file content has been streamed.DynamicFileDownloaderasButton()Makes the download look like a button instead of a normal link.com.vaadin.flow.component.button.ButtongetButton()protected StringgetFileName(com.vaadin.flow.server.VaadinSession session, com.vaadin.flow.server.VaadinRequest request)Gets the filename of downloaded file.protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent)voidsetDisableOnClick(boolean disableOnClick)voidsetFileHandler(com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)voidsetFileName(String fileName)-
Methods inherited from class com.vaadin.flow.component.html.Anchor
getHref, getTarget, getTargetValue, onEnabledStateChanged, removeHref, setHref, setHref, setTarget, setTarget
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, 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 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 com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, addComponentAtIndex, remove, removeAll
-
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
-
-
-
-
Constructor Detail
-
DynamicFileDownloader
public DynamicFileDownloader(String text, String fileName, com.vaadin.flow.function.SerializableConsumer<OutputStream> contentWriter)
-
DynamicFileDownloader
public DynamicFileDownloader()
-
-
Method Detail
-
setDisableOnClick
public void setDisableOnClick(boolean disableOnClick)
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
- Overrides:
onDetachin classcom.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 @Pushin use or useUI.setPollInterval(int)method.- Parameters:
listener- the listener- Returns:
- the
Registrationyou 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 sessionrequest- 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
-
-