Eclipse plug-in: how to update a view once a Job is complete

情到浓时终转凉″ 提交于 2020-04-16 07:07:30

问题


The run method in my Job class, does some stuff (the details are irrelevant) and outputs 2 arrays of doubles.

I want to display these arrays in a results view which I have created with a Table and 2 columns, one for each array.

How can I reference the view and display these arrays in it at the end of the run method (in the Job class)?

Even if you cannot help me with the answer, I would be happy if someone can point me in some direction because I have no idea. The only thing I could think of was event handling but I don't know very much about that either.

class RunnerJob extends Job {
     protected IStatus run(IProgressMonitor monitor) {
          //does some stuff
          double[] col1 = someStuff1();
          double[] col2 = someStuff2();

          //display in results view?
  }
}

Based on Suraj Chandran's answer, this is the code I used to reference a view's static method,

display.syncExec(
    new Runnable() {
       public void run(){
           try { 
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ResultsView.ID);
           } catch (PartInitException e) {
                e.printStackTrace();
             }
                 ResultsView.update(<object with values>);
             }
     });

回答1:


In your view class have a static method something like getInstance() that would return reference to you view object. Once you have the object you can set the arrays in it.




回答2:


Use observer pattern (see example):

  1. Make your View implement Observer
  2. Make your Job implement Observable
  3. Register your View to Observable in createPartControl() (or in constructor), and don't forget to unregister it in dispose().
  4. Notify Observers when the Job is done.


来源:https://stackoverflow.com/questions/6292523/eclipse-plug-in-how-to-update-a-view-once-a-job-is-complete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!