1

にライフサイクル リスナーを登録していますplugin.xml。を定義するだけで問題なく動作しますShell
例えば

@PostContextCreate  
void postContextCreate(final IEventBroker eventBroker){  
     System.out.println("CALLED!");    
     final Shell shell = new Shell(SWT.TOOL | SWT.NO_TRIM);  
     shell.open();  
     eventBroker.subscribe(UIEvents.UILifeCycle.ACTIVATE, new EventHandler() {  

    @Override  
    public void handleEvent(Event event) {  
        System.out.println("Closing shell");  
        shell.close();  
        shell.dispose();  
        System.out.println("Closed");  
        eventBroker.unsubscribe(this);  
        }
     });

しかし、呼び出しを変更して a も使用する場合Display:

@PostContextCreate
void postContextCreate(final IEventBroker eventBroker){  
    System.out.println("CALLED!");  
    Display display = new Display();  
    final Shell shell = createSplashShell(display);  
    shell.open();  
    while (!shell.isDisposed ()) {  
    if (!display .readAndDispatch ()) display.sleep ();  
    }
    display.dispose ();  
   //etc  

次の例外が発生します。

org.eclipse.e4.core.di.InjectionException: org.eclipse.swt.SWTException: org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63) での
org.eclipseでの無効なスレッド アクセス.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:229) at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:206)

UIこの例外はスレッドで何かをしなければならないことを理解していますが、ここでどのように使用してDisplayこの例外が発生するのかわかりません。
何か助けはありますか?

4

2 に答える 2

5

Display.asyncExecメソッドを使用して、UI スレッドで Runnable を実行します。

ほとんどの UI フレームワークと同様に、SWT では UI コンポーネントに対してスレッドが動作することはありません。そのため、別のスレッドから何かを変更する必要がある場合は、それを UI スレッドで実行するこのユーティリティに渡さなければなりません。

于 2012-09-19T17:22:41.277 に答える
4

私の理解によると、イベントが発生したときにシェルをポップアップしたいことがわかりました。1 つのディスプレイ (メインの RCP アプリによって作成されたもの) で、新しいシェルと処理イベントを作成するのに十分です。

@PostContextCreate
    void postContextCreate(final IEventBroker eventBroker){  
        System.out.println("CALLED!");

        final Display display = Display.getDefault();
        Display.getDefault().asyncExec(new Runnable()
        {
          public void run()
        { 
         final Shell shell = createSplashShell(display);  
         shell.open();  
         while (!shell.isDisposed ()) {  
         if (!display .readAndDispatch ()) display.sleep ();  
        }
      }
    }
于 2012-09-19T18:36:09.537 に答える