5

I am working on Eclipse RCP application, I want to achieve the eclipse workspace job with a Dialog with the buttons like "Run in Background", "Cancel" and "Details". I tried all the options but all my efforts did not bear fruit. However I am able to create ProgressBar with ProgressMonitor dialog with cancel button. I want to achieve like the image given below. Please help me in this regard. I also went through the following link along with other links. I also tried with IProgressService but it did not work. Currently I am working in Eclipse Photon version.

https://www.eclipse.org/articles/Article-Concurrency/jobs-api.html

enter image description here

I provide below the code for workspace job

public void show11() {
Job job =
    new WorkspaceJob("name") {
      @Override
      public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

        for (int i = 0; i < 10; i++) {
          System.out.println("This is a MYJob");
          try {
            TimeUnit.SECONDS.sleep(1);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          monitor.subTask("Copying file " + (i + 1) + " of " + "workload" + "...");
        }

        return Status.OK_STATUS;
      }
    };

  job.setUser(true);
  job.schedule();

  try
   {
     job.join();
   }
  catch (InterruptedException e)
   {
     //
   }

}

Sambit
  • 7,625
  • 7
  • 34
  • 65
  • So why not just use a `Job` or `WorkspaceJob` with `setUser(true)` which will display this dialog – greg-449 Jul 23 '18 at 16:15
  • Hi Greg, I followed all your all posts in stackoverflow, but it is not working as per the image given.I want to achieve with the three buttons like "Run in Background", "Cancel" and "Details >>". – Sambit Jul 23 '18 at 16:22
  • Sorry but with setUser(true) Eclipse displays `org.eclipse.ui.internal.progress.ProgressMonitorFocusJobDialog` which has these three buttons. Show us the code you are trying. – greg-449 Jul 23 '18 at 16:26
  • Hi Greg, I have posted the code. – Sambit Jul 23 '18 at 16:39
  • With the above code, it does not pop up the dialog box. – Sambit Jul 23 '18 at 16:40
  • Calling `job.join()` blocks the UI thread so the dialog cannot be displayed - don't do this in the UI thread. – greg-449 Jul 23 '18 at 16:47
  • I tried by commenting out the code, still it does not pop up the dialog. It runs in my progressView view. – Sambit Jul 23 '18 at 16:52
  • Check you don't have 'Always run in background' selected in the General page of the Preferences. – greg-449 Jul 23 '18 at 16:54
  • I checked it, still it does not. – Sambit Jul 23 '18 at 16:58
  • I found a similar issue, the link is given below. https://www.eclipsezone.com/eclipse/forums/t30941.html. This is my exact problem in Photon. – Sambit Jul 23 '18 at 18:31

1 Answers1

7

Finally I solved this problem. It is assumed that "Run in Background" is set by default for eclipse RCP application. In my case I had to switch of this option from Eclipse, still it did not work. I have done manually to make it false in my eclipse rcp. I provide below. the code.

WorkbenchPlugin.getDefault().getPreferenceStore().setValue("RUN_IN_BACKGROUND", false);

Those who are facing this kind of problem, they can set this value programmatically while developing eclipse rcp application.

I would like to thank Greg Sir (greg-449) for providing some tips and information.

Sambit
  • 7,625
  • 7
  • 34
  • 65