Progress Indicator Module

I have created and attached a simple module that lets you easily display a progress bar during lengthy processes. Just place a single function call from anywhere within the main loop that is performing your lengthy process. Provides optional cancel button and optional status message to display on the progress indicator.

[attachment=1]progress.JPG[/attachment]

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:

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:

globals.hideProgress()

Example 1:

// 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:

// 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.

progress.servoy (4.82 KB)

Thanks Adrian,

Would it be possible to have a version compatible with Servoy 3.5 ?

Would it be possible to have a version compatible with Servoy 3.5 ?

I see no reason why this wouldn’t work in 3.5 with some minor modifications but it’s not something I can fit into my ‘spare time’, if you know what I mean. If you want to try converting it to 3.5 yourself, the only change I think you’ll need to make is to use global vars instead of the format vars I use in the progress form itself.

If you’d like to have me convert it for you drop me a Private Message and we can discuss. Thanks.

OK, Thanks Adrian,

I will give it a go

I just uploaded a new version of this module - attached it to the original posting that started this thread. New version corrects some minor bugs I found. Thanks.

I know this is kind of old, but I tried using the progress indicator and I think I found a small problem. The line:

if (percentAdvanceSinceLastUIUpdate < .05)

should be something like:

if (percentAdvanceSinceLastUIUpdate < .05 && total>n)

otherwise the bar stops before getting to 100%

It works really well though, thanks Adrian!

Glad you are finding my Progress Indicator Module of use. I haven’t run into the problem you describe, but I have attached a newer version of the module in which I’ve simplified the parameters that you send to the progress bar. It includes a global method called demoProgress with demo code.

This version of the module is called progressV2 but you can rename it back to just “progress” if you want, either by doing a ‘clean import’ or by using the ‘rename solution’ command in the Solution Explorer (works on non-active solutions)

progressV2.servoy (5.53 KB)

Hi Adrian,

Is this an unlocked (Open Source) module? Why not host it on ServoyForge ?

I was going to say that. - But once again Robert was quicker ;)
Hosting it on ServoyForge will give you all the tools you need to maintain the module and for others to easily get access and maybe enhance it.
Just drop us an email and we will open the project for you.