Search code examples
eclipsepluginsprogressmonitor

how do I use progress monitor in eclipse plugin code?


In my eclipse plugin, I created an utility class that does some work when I create my files, with my wizard.

I´d like to show to user some text, warning him about what´s happening, in the progress bar.

How could I do this? Thanks a lot.

UPDATE: my wizard calls my utility class, that unzips 2 ZIP files and import 2 projects into workspace. So, I´d like to show a message after each operation, like:

Unzipping file1... Unzipping file2... Importing project1... Importing project2...


Solution

  • In your Wizard class enable the progress monitor by calling

    setNeedsProgressMonitor(true);
    

    in the constructor.

    You can then run your IRunnableWithProgress class with:

    IRunnableWithProgress runnable = new MyRunnable();
    
    getContainer().run(true, true, runnable);
    

    This can be in the Wizard or in a WizardPage.

    The IRunnableWithProgress class might look like:

    private class MyRunnable implements IRunnableWithProgress
    {
      @Override
      public void run(final IProgressMonitor monitor)
        throws InvocationTargetException, InterruptedException
      {
        monitor.beginTask("title", progress count);
    
        try
         {
           ... your work
         }
        finally
         {
           monitor.done();
         }
      }
    }