开发者

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

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 开发者_JAVA百科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>);
             }
     });


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜