从插件中关闭eclipse RCP应用程序的正确方法?

时间:2012-03-13 02:08:36

标签: eclipse rpc application-shutdown

我正在尝试从命令行运行eclipse RCP应用程序。 最合适的部分是可以的,我可以解析cmdline参数并做我想要的。 但之后我想关闭应用程序。 实现这一目标的正确方法是什么?

我在尝试这个:     PlatformUI.getWorkbench()关闭();

但得到了这个:

org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
    at org.eclipse.swt.SWT.error(SWT.java:4282)
    at org.eclipse.swt.SWT.error(SWT.java:4197)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
    at org.eclipse.swt.widgets.Display.release(Display.java:3263)
    at org.eclipse.swt.graphics.Device.dispose(Device.java:249)
    at uk.ac.bolton.archimate.editor.Application.start(Application.java:65)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
    Caused by: org.eclipse.swt.SWTException: Widget is disposed
    at org.eclipse.swt.SWT.error(SWT.java:4282)
    at org.eclipse.swt.SWT.error(SWT.java:4197)
    at org.eclipse.swt.SWT.error(SWT.java:4168)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
    at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:403)
    at org.eclipse.swt.browser.Browser.checkWidget(Browser.java:195)
    at org.eclipse.swt.browser.Browser.addProgressListener(Browser.java:386)
    at org.rulez.magwas.styledhtml.EventLog$1.run(EventLog.java:80)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    ... 18 more

这就是我在创业时的行为:

protected void refreshPluginActions() {
 if (!PlatformUI.isWorkbenchRunning()) {
        return;
    }
 Display.getDefault().asyncExec(new Runnable() {
    public void run() {
        runcmd();
    }
 });
}

1 个答案:

答案 0 :(得分:1)

您正在使用正确的API来实现此目的。根据您的堆栈跟踪,看起来org.rulez.magwas.styledhtml.EventLog类中存在一个错误,导致它在关机期间尝试更新UI中的某些内容。一个典型的解决方案是确保有问题的代码在尝试操作UI之前执行Widget.isDisposed()调用,并在有问题的小部件已经被处理时安全地拯救。