Page 1 of 1

Progress Indicator Module

PostPosted: Mon Mar 09, 2009 11:45 am
by amcgilly
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.

progress.JPG
progress.JPG (14.26 KiB) Viewed 8623 times


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.

Re: Progress Indicator Module

PostPosted: Tue Mar 10, 2009 11:09 pm
by prj311
Thanks Adrian,

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

Re: Progress Indicator Module

PostPosted: Wed Mar 11, 2009 7:38 pm
by amcgilly
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.

Re: Progress Indicator Module

PostPosted: Wed Mar 11, 2009 10:30 pm
by prj311
OK, Thanks Adrian,

I will give it a go

Re: Progress Indicator Module

PostPosted: Fri Apr 03, 2009 12:57 am
by amcgilly
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.

Re: Progress Indicator Module

PostPosted: Fri Aug 13, 2010 7:50 pm
by msedita
I know this is kind of old, but I tried using the progress indicator and I think I found a small problem. The line:
Code: Select all
if (percentAdvanceSinceLastUIUpdate < .05)

should be something like:
Code: Select all
if (percentAdvanceSinceLastUIUpdate < .05 && total>n)

otherwise the bar stops before getting to 100%

It works really well though, thanks Adrian!

Re: Progress Indicator Module

PostPosted: Mon Aug 16, 2010 8:53 pm
by amcgilly
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)

Re: Progress Indicator Module

PostPosted: Mon Aug 16, 2010 9:07 pm
by ROCLASI
Hi Adrian,

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

Re: Progress Indicator Module

PostPosted: Tue Aug 17, 2010 12:47 am
by ptalbot
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.