Class ActionButton<T>
- Type Parameters:
T
- the type of the result of the slow task
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier
,com.vaadin.flow.component.DetachNotifier
,com.vaadin.flow.component.HasElement
,com.vaadin.flow.component.HasStyle
,Serializable
NOTE! This class is still in early development and likely to get some changes still in the future. Suggestions/contributions are more than welcome!
The button will be disabled while the task is running and re-enabled when the task is done.
The actual task, set with setAction(Supplier)
or setCompletableFutureAction(Supplier)
, is run in a
separate thread. If your task wants to update the UI during its execution, you need to synchronize with the UI thread
using UI.access(Command)
.
UI updates are suggested to be done in #setPostTaskAction(Consumer) which is called after the task has completed or #setPreTaskAction(Runnable) which is called before the task is started. These are run in the UI thread.
The button will automatically enable polling if push is not enabled and call push() if "manual server push" is active.
- See Also:
-
Constructor Summary
ConstructorDescriptionActionButton
(String buttonText) ActionButton
(String buttonText, Runnable action) ActionButton
(String buttonText, Supplier<CompletableFuture<T>> action) -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.component.button.Button
Returns the underlying button component, for further configaration.Deprecated.boolean
protected void
onAttach
(com.vaadin.flow.component.AttachEvent attachEvent) protected VProgressBar
protected void
void
setEstimatedDuration
(Integer estimatedDuration) Set the estimated duration of the task in milliseconds.void
setExecutor
(Executor executor) Set an executor to be used for running the task.setPostUiUpdate
(Consumer<? super T> postUiUpdate) setPreUiUpdate
(Runnable preUiUpdate) void
setShowProgressBar
(boolean showProgressBar) void
void
updateProgressAsync
(double progress) API for updating the progress bar from the task.void
updateProgressAsync
(double progress, double min, double max) API for updating the progress bar from the task.Methods inherited from class com.vaadin.flow.component.Composite
getChildren, getElement, initContent
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, 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.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
ActionButton
public ActionButton() -
ActionButton
-
ActionButton
-
ActionButton
-
-
Method Details
-
setAction
-
setAction
-
setCompletableFutureAction
-
setPostUiUpdate
-
setPreUiUpdate
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttach
in classcom.vaadin.flow.component.Component
-
getCompletableFuture
-
setText
-
reEnableAfterTask
protected void reEnableAfterTask() -
isShowProgressBar
public boolean isShowProgressBar() -
setShowProgressBar
public void setShowProgressBar(boolean showProgressBar) - Parameters:
showProgressBar
- true if the built-in progress bar should be shown while the task is running
-
prepareProgressBar
-
updateProgressAsync
public void updateProgressAsync(double progress, double min, double max) API for updating the progress bar from the task. This method is safe to call from the task thread.- Parameters:
progress
- the progress value to setmin
- the minimum value of the progress barmax
- the maximum value of the progress bar
-
updateProgressAsync
public void updateProgressAsync(double progress) API for updating the progress bar from the task. This method is safe to call from the task thread.- Parameters:
progress
- the progress value to set
-
getExecutor
-
setExecutor
Set an executor to be used for running the task. If not set, the default executor is used.- Parameters:
executor
- the executor to use for the task
-
getEstimatedDuration
-
setEstimatedDuration
Set the estimated duration of the task in milliseconds. This can be used to show a progress bar that is not indeterminate.- Parameters:
estimatedDuration
-
-
getButton
public com.vaadin.flow.component.button.Button getButton()Returns the underlying button component, for further configaration.- Returns:
- the underlying button component
-
getContent
Deprecated.usegetButton()
instead, the composition root is likely to change for improved A11y support- Overrides:
getContent
in classcom.vaadin.flow.component.Composite<VButton>
- Returns:
- the underlying content component
-
getButton()
instead, the composition root is likely to change for improved A11y support