You can view the progress of a running process with an XdevProgressBar. The progress is specified with the help of a value between 0.0 and 1.0. To view the current progress of a process, you must first determine its complete scope. In many cases, it is sufficient to display a progress wheel, which simply lets the user know that a process of unspecified duration is currently running. This option is easy to implement.
However, if you want to display the progress in real time, want to update further UI components next to XdevProgressBar, or do not want to block the interface during a background process, you must execute the process in a separate, parallel running thread and must update the interface in the browser after each change.
Opening a pop-up window for displaying the progress. The pop-up window blocks the entire user interface and closes automatically, as soon as the process closes in the background.
Create another view, insert an XdevButton, define a buttonClick event and open the ProgressView view as PopupWindow in it, which closes automatically as soon as the process ends:
Progress wheel during process - Only displays a progress wheel that shows the current progress in the XdevProgressBar.
private void button_buttonClick(Button.ClickEvent event) { Window popup = PopupWindow.For(new ProgressView()).closable(false).draggable(false).resizable(false).modal(true).show(); UI.getCurrent().push(); // Start your process here popup.close(); } |
Select XdevProgressBar > Properties > Indeterminate in the ProgressView.
Dynamically update XdevProgressBar - Shows the current progress in the XdevProgressBar. The entire process must run in a separate thread. Since the thread runs on the server and the XdevProgressBar in the browser does not get any information about it, a server push must be executed for every update of the XdevProgressBar through the invoking of getUI().access(()→progressBar.setValue(value)); method.
private void progressBar_attach(ClientConnector.AttachEvent event) { // Find out the lenght of your process in total. The value is 1.0. // Starts a new thread on the serverside Runnable task = ()->{ // Start your process. Find out the current progress and store it in 'value'. Value must be between 0.1 and 1.0. // Server Push to update in the ProgressBar in the Browser getUI().access(()->progressBar.setValue(value)); }; new Thread(new RunnableAccessWrapper(task)).start(); } |