The ProgressBar
component is used to display the progress of a long process.
XML name of the component: progressBar
The component is implemented for Web Client and Desktop Client.
Below is an example of the component usage together with the mechanism of background tasks:
<progressBar id="progressBar" width="100%"/>
@Inject protected ProgressBar progressBar; @Inject protected BackgroundWorker backgroundWorker; private static final int ITERATIONS = 5; @Override public void init(Map<String, Object> params) { BackgroundTask<Integer, Void> task = new BackgroundTask<Integer, Void>(300, this) { @Override public Void run(TaskLifeCycle<Integer> taskLifeCycle) throws Exception { for (int i = 1; i <= ITERATIONS; i++) { TimeUnit.SECONDS.sleep(2); // time consuming task taskLifeCycle.publish(i); } return null; } @Override public void progress(List<Integer> changes) { float lastValue = changes.get(changes.size() - 1); progressBar.setValue(lastValue / ITERATIONS); } }; BackgroundTaskHandler taskHandler = backgroundWorker.handle(task); taskHandler.execute(); }
Here in the BackgroundTask.progress()
method, which is executed in UI thread, the ProgressBar
component is set to the current value. The component value should be a float
number from 0.0
to 1.0
.
If a running process is unable to send information about the progress an indeterminate state of the indicator can be displayed
using the indeterminate
attribute. Indicator shows an indeterminate state if the attribute value is true
. Default is false
. For example:
<progressBar id="progressBar" width="100%" indeterminate="true"/>
progressBar
attributes: