The progress indicator is displayed in a non-modal dialog, and it advances in 5% increments, displaying a '% complete' message on the bar itself. It uses the JProgressBar bean that ships with Servoy. When the process is complete, the status indicator goes away.
Usage:
Somewhere inside the loop that is performing your lengthy operation, place this call:
- Code: Select all
globals.showProgress(n, tot, msg, allowCancel)
where:
n = the number of iterations completed so far
tot = total number of iterations you expect to perform and
msg = (optional parameter) message (string) you want to have appear next to the '% Complete' indicator on the bar.
allowCancel = (optional parameter) boolean - true if you want a cancel button displayed beneath the progress bar
This will cause the progress bar to display, and update the progress indicator if it has advanced more than 5%. (I only update the bar at each 5% because each update requires a call to application.updateUI() which slows things down a lot if called too often).
If the 'allowCancel' parameter is set to true, and if the user has hit the cancel button, then globals.showProgress() returns false,
otherwise returns true
When processing is complete and n == tot, then the progress bar will show 100%, it will remain displayed for 1 second, then disappear all by itself.
If at any time during processing you want to hide the progress bar, simply make this call:
- Code: Select all
globals.hideProgress()
Example 1:
- Code: Select all
// Show progress while looping through a foundset of invoice records.
// Display 'Processing invoices' on the progress bar.
// Do NOT display a cancel button.
var totalRecords = databaseManager.getFoundSetCount(foundset)
for (var i = 1; i <= foundset.getSize(); i++)
{
foundset.setSelectedIndex(i)
// do processing work here
globals.showProgress(i, totalRecords ,'Processing Invoices.')
}
Example 2:
- Code: Select all
// Show progress while looping through a foundset of invoice records.
// Do NOT display a message next to the % Completion message.
// DO display a cancel button, and break out of loop if user hits cancel button
var totalRecords = databaseManager.getFoundSetCount(foundset)
for (var i = 1; i <= foundset.getSize(); i++)
{
foundset.setSelectedIndex(i)
// do processing work here
if (!globals.showProgress(i, totalRecords, null, true))
{
// display 'Processing cancelled by user' message
break;
}
}
Installation note:
When importing this module Servoy will look for the customers table in the example_data server because the progress form is based on that table. If it can't find that table and you are asked to specify a different table, pick any table you want - it doesn't matter what you pick - any table will do.
If you find any bugs or better ways of doing things please let me know and I'll update the module.