0

I am doing a project using GEF. I need to open a popup window when double click the model in the canvas.

I create a SWT window and let GEF to open it. But the problem is it casue an exception:

Exception in thread "Thread-5" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Invalid thread access)

when running following code.

     while(!shell.isDisposed()){ 
        **if(!display.readAndDispatch()){** 
        display.sleep(); 
        }
        }

What i did in my project is create the SWT window, then make a thread to run it, and call the thread in my model's editpart like this:

public void performRequest(Request req)
{
            swtthread aa = new swtthread();
            aa.start();
    }

Do possible a GEF can use SWT window as a popup window or is there any other way to do this?

Thank you

4

1 回答 1

2

听起来很奇怪,但我没有使用 GEF 的经验。根据这个 SWT FAQ你从非 UI 线程调用 UI 方法,尝试用

display.syncExec(
  new Runnable() {
    public void run(){
      ... // your code
  }
});

您也可以使用 asyncExec,具体取决于您的需要。

于 2011-07-06T07:06:35.710 回答