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 TypeMethodDescriptionReturns the underlying button component, for further configaration.boolean
boolean
protected void
onAttach
(com.vaadin.flow.component.AttachEvent attachEvent) protected VProgressBar
protected void
setBusyText
(String text) Set the text of the button to show while the task is running (and button disabled).setEnableAfterAction
(boolean enableAfterAction) 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.setPostUiAction
(Consumer<? super T> postUiAction) Sets an action to update the UI after the actual slow actions is completed.setPostUiUpdate
(Consumer<? super T> postUiUpdate) Deprecated.setPreUiAction
(Runnable preUiAction) Sets an action to update the UI before the actual slow actions is started.setPreUiUpdate
(Runnable preUiUpdate) Deprecated, for removal: This API element is subject to removal in a future version.usesetPreUiAction(Runnable)
insteadvoid
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, getContent, 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
-
setPostUiAction
Sets an action to update the UI after the actual slow actions is completed. This is "run in the UI thread", meaning you don't need to synchronize with the UI using UI.access().- Parameters:
postUiAction
- the action to run after the slow task- Returns:
- this for chaining
-
setPostUiUpdate
Deprecated.usesetPostUiAction(Consumer)
instead- Parameters:
postUiUpdate
- the action to run after the slow task- Returns:
- this for chaining
-
setPreUiAction
Sets an action to update the UI before the actual slow actions is started. This is "run in the UI thread", meaning you don't need to synchronize with the UI using UI.access().- Parameters:
preUiAction
- the action to run before the slow task- Returns:
- this for chaining
-
setPreUiUpdate
Deprecated, for removal: This API element is subject to removal in a future version.usesetPreUiAction(Runnable)
instead -
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttach
in classcom.vaadin.flow.component.Component
-
getCompletableFuture
-
setText
-
setBusyText
Set the text of the button to show while the task is running (and button disabled).- Parameters:
text
- the text to show- Returns:
-
reEnableAfterAction
protected void reEnableAfterAction() -
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
Returns the underlying button component, for further configaration.- Returns:
- the underlying button component
-
isEnableAfterAction
public boolean isEnableAfterAction()- Returns:
- true if the button should be automatically enabled after the action is completed
-
setEnableAfterAction
- Parameters:
enableAfterAction
- true (default) if the button should be automatically enabled after the action is completed- Returns:
- this for chaining
-
setPostUiAction(Consumer)
instead