Progress Indicator Module

Share business templates, ideas, experiences, etc with fellow Servoy developers here

Progress Indicator Module

Postby amcgilly » Mon Mar 09, 2009 11:45 am

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 8551 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.
Attachments
progress.servoy
Updated April 2/09
(4.82 KiB) Downloaded 539 times
Last edited by amcgilly on Fri Apr 03, 2009 12:54 am, edited 1 time in total.
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Progress Indicator Module

Postby prj311 » Tue Mar 10, 2009 11:09 pm

Thanks Adrian,

Would it be possible to have a version compatible with Servoy 3.5 ?
Regards,
Phil Routley

Servoy Developer
Worldview i.T.
NSW, Australia
User avatar
prj311
 
Posts: 137
Joined: Fri Sep 16, 2005 1:56 am

Re: Progress Indicator Module

Postby amcgilly » Wed Mar 11, 2009 7:38 pm

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.
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Progress Indicator Module

Postby prj311 » Wed Mar 11, 2009 10:30 pm

OK, Thanks Adrian,

I will give it a go
Regards,
Phil Routley

Servoy Developer
Worldview i.T.
NSW, Australia
User avatar
prj311
 
Posts: 137
Joined: Fri Sep 16, 2005 1:56 am

Re: Progress Indicator Module

Postby amcgilly » Fri Apr 03, 2009 12:57 am

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.
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Progress Indicator Module

Postby msedita » Fri Aug 13, 2010 7:50 pm

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!
Michael Sedita
MS Health Software Corp.
Developers of software solutions for behavioral healthcare and social service providers.
www.mshealth.com
User avatar
msedita
 
Posts: 224
Joined: Thu Dec 13, 2007 8:01 pm

Re: Progress Indicator Module

Postby amcgilly » Mon Aug 16, 2010 8:53 pm

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)
Attachments
progressV2.servoy
(5.53 KiB) Downloaded 412 times
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Progress Indicator Module

Postby ROCLASI » Mon Aug 16, 2010 9:07 pm

Hi Adrian,

Is this an unlocked (Open Source) module? Why not host it on ServoyForge ?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Progress Indicator Module

Postby ptalbot » Tue Aug 17, 2010 12:47 am

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.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC


Return to Sharing Central

Who is online

Users browsing this forum: No registered users and 6 guests