1

we need to get the the current display object in RAP 2.3 from inside a job for updating the UI. what is the suggested way to do that?

4

1 回答 1

1

RAP 中的线程文章对线程和会话在 RAP 中的相互关系进行了详尽的解释。

要从 Job 访问 Display,Job 需要知道它被分配到哪个 Display。因此,您需要将 Displya 传递给 Job。如果 Job 是从 UI 线程调度的,典型的代码可能如下所示:

  static class DisplayJob extends Job {
    private final Display display;

    private DisplayJob( Display display ) {
      super( "Job with UI Access" );
      this.display = display;
    }

    @Override
    protected IStatus run( IProgressMonitor monitor ) {
      display.asyncExec( new Runnable() {
        @Override
        public void run() {
        }
      } );
      return Status.OK_STATUS;
    }
  }


  Button button = new Button( ...
  button.addListener( SWT.Selection, new Listener() {
    @Override
    public void handleEvent( Event event ) {
      new DisplayJob( event.display ).schedule();;
    }
} );

run()在使用给定的方法访问它们之前不要忘记检查小部件是否未处理asyncExec()- 或因此使用帮助器。

请注意,线程/会话关系并非特定于 RAP,而是适用于所有具有会话概念的多用户环境。

于 2015-02-10T09:17:59.753 回答