Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9020925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:08:11+00:00 2026-06-16T05:08:11+00:00

I have a working ProgressMonitorDialog, but I want to make sure that I am

  • 0

I have a working ProgressMonitorDialog, but I want to make sure that I am setting it up correctly.

First the Code:

Method to create Dialog

 public void startProgressBar() {
  try {
     new ProgressMonitorDialog(getShell()).run(true, true,
        new ProgressBarThread());
  } 
  catch (InvocationTargetException e) {
     MessageDialog.openError(getShell(), "Error", e.getMessage());
  } 
  catch (InterruptedException e) {
     MessageDialog.openInformation(getShell(), "Cancelled", e.getMessage());
  }
}

Class File

 class ProgressBarThread implements IRunnableWithProgress {
  private static final int TOTAL_TIME = 1000;

  public ProgressBarThread() {

  }

  public void run(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException {
     monitor.beginTask("Creating PDF File(s): Please wait.....", IProgressMonitor.UNKNOWN);
     for (int total = 0; total < TOTAL_TIME ; total++) {
        Thread.sleep(total);
        monitor.worked(total);
        if (total == TOTAL_TIME / 2) monitor.subTask("Please be patient... Operation should finish soon.");
    }
    monitor.done();

  }
}

Method that calls the ProgressBar and runs a Pdf file creation Operation

private void startSavePdfOperation() {
  Display.getDefault().asyncExec(new Runnable() {
     public void run() {
        startProgressBar();
     }
  });
  saveOp = new AplotSaveOperation(appReg.getString("aplot.message.SAVETOPDF"), "PDF", session);
  saveOp.addOperationListener(new MyOperationListener(this) {

     public void endOperationImpl() {
        java.io.File zipFile = null;
        try {               
           AplotSaveResultsParser.SaveResult saveResults = saveOp.getSaveResults();
           if (saveResults != null) {
           ETC.....   ETC......  

Questions:

  1. Being the ProgressMonitorDialog is a GUI, it needs to be executed in a
    Display.getDefault().asyncExec?

  2. If the ProgressMonitorDialog is running in a separate thread, how does it know to close when the operation is finsihed?

  3. Is there any relationship between the progressbar and the operation?

  4. I am correct in assuming that the for loop in the ProgressBarThread class is basically the timer that keeps the monitor open?

  5. Is there a way to increase the speed of the ProgressMonitorDialog’s indicator, also can you remove the cancel button?

This is what I am thinking is happening currently.

  1. I am starting the progress bar just before I start the PDF Operation Listener
    See startSavePdfOperation() Above

  2. The progress bar is running as unknown, but using a for loop to keep the progress bar dialog open, while the operation is running on a thread in the background.
    See Class ProgressBarThread above

  3. When the PDF operation completes the listener operation class closes the base GUI dialog.

    public void endOperation() {
     try {
        endOperationImpl();
     }
     finally {
        Display.getDefault().asyncExec(new Runnable() {
           public void run() {
              w.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW));
              w.recursiveSetEnabled(getShell(), true);
              w.getShell().setEnabled(!getShell().getEnabled());
              w.close();
           }
        });
     }
    

    }

  4. I am not sure what is happening to the ProgressBarThread monitor?

Is this Possible?

  1. When the PDF Operation starts, the ProgressMonitorDialog opens and starts the indicator. OK with keeping it unknown.

  2. When the PDF Operation completes, the monitor closes, then the base Dialog

I am just wanting to open progress bar dialog that will inform the user that their request is working in the background.

As stated the above code works, but I am afraid by letting the closing of Base GUI, destroy my Progress Thread and Monitor is not good practice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:08:12+00:00Added an answer on June 16, 2026 at 5:08 am

    First of all, in your ProgressBarThread#run() you should use monitor.worked(1). You don’t need to set the total worked but increment it by the amount of work done, since the last time it was called.

    Q1. Yes it needs to be executed in the display thread
    Q2. Normally the work that needs to be done is actually performed in the runnable that is passed to the progress monitor dialog so that you can accurately report the amount of progress made. So your operation (if it is a synchronous call) should be called from within ProgressBarThread#run() so that you call monitor.worked(1) only when one file processing is complete.

    Q3. What kind of operation are you running, perhaps it already supports showing progress bar, and you just need to invoke the right API. Is it an IUndoableOperation?

    Q4. As I said this approach is problematic because you can never accurately report the progress and close the dialog only when the operation is completed. But if this is the only choice you have, then you can just save the monitor reference somewhere so that it is accessible to the other thread. Once monitor.done() is called, your ProgressBarThread#run() should return, the dialog will close.

    Q5. You can remove the cancel button by passing the correct parameter to ProgressMonitorDialog#run(..):

    new ProgressMonitorDialog(getShell()).run(true, false, new ProgressBarThread());
    

    For the rest of the questions I can better answer if I know what kind of operation (what API) you are using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have working code but it seems a bit strange that I have to
First Q. I have working code to make this move elsewhere in the file
I have working code: [self performSelector:@selector(doSomething) ]; but when I change this line to:
I currently have working code to save children to a parent entity. But I'm
I have working code that includes: $(document).ready(function() { $(#num1).click(function() { $(li.elementsA).addClass(alerty); return false });
I'm trying to reuse some script that I have working on another page, but
I have working code below for collision of two circles, but now I have
I have working code but don't like it, its very unruby like to me.
I currently have working code that inserts rows into a table. It looks like
Hi i have working code but i would like to print out the coordinates.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.