title: SWT progress dialog while performing a long operation in the UI thread?
body: <p>I have a long operation that cannot be moved from the SWT UI thread. I know, it's gross, but that's how it is. I would like to display a progress bar of some sort for said long operation. I have tinkered around with org.eclipse.jface.dialogs.ProgressMonitorDialog. I'm not giving it an IRunnableWithProgress because, like I said, the long op is in the UI thread. And thus, we have something like...</p>
  
  <pre><code>Shell shell = new Shell();
  ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
  progressDialog.open();
  IProgressMonitor progressMonitor = progressDialog.getProgressMonitor();
  int workLoad = 10;
  progressMonitor.beginTask(message, workLoad);
  for(int i = 0; i &lt; workLoad; ++i) {
      progressMonitor.worked(1);
      progressMonitor.subTask("Subtask " + (i+1) + " of "+ workLoad + "...");
      if(progressMonitor.isCanceled()) {
          break;
      }
      // Do some work.
      try {
          Thread.sleep(2000);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  }
  progressMonitor.done();
  progressDialog.close();
  </code></pre>
  
  <p>This works, but obviously does not update smoothly and at times is laggy to moving and clicking cancel. I thought maybe I could manually update the UI in this instance by creating a thread containing the requisite...</p>
  
  <pre><code>while(!shell.isDisposed()) {
      if(!display.readAndDispatch()) {
          display.sleep();
      }
  }
  </code></pre>
  
  <p>...in the run method, but much to my chagrin I bumped into...</p>
  
  <pre><code>Exception in thread "Thread-16" org.eclipse.swt.SWTException: Invalid thread access
  </code></pre>
  
  <p>Turns out you can't do that in just any old thread, those calls have to originate in the UI thread. Back to square one.</p>
  
  <p>Does anyone know if I can trick the system? Like make my little thread appear to be the UI thread? Or just any other suggestions would be cool.</p>
  
  <p>Thanks,
  jb</p>