StatusManager不显示详细信息

StatusManager不显示详细信息

本文介绍了Eclipse StatusManager不显示详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

Job job = new Job("Connect to Database") {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                // 即使是在正常的情况下,某些版本的DB2的连接建立时间也比较长。。。
                monitor.beginTask("正在建立到数据库的连接 ...", 100);
                try {
                    Thread.sleep(3000);
                    database = new Database(cp.getName(),  cp.getConnection());
                } catch (Exception e) {
                    e.printStackTrace();
                    IStatus sqlErrorStatus = new Status(IStatus.ERROR, "amarsoft.dbmp", e.getMessage(), null);
                    StatusManager.getManager().handle(sqlErrorStatus, StatusManager.SHOW);
                }
                monitor.done();
                return Status.OK_STATUS;
            }
        };

当用户单击详细信息按钮时,如何使其显示异常的堆栈跟踪?

How can I make it display the exception's stack trace when user click the 'Details' button?

推荐答案

状态对话框的默认详细信息区域不会显示异常堆栈跟踪。

Default details area of status dialog does not display exception stack trace.

如果您有自己的Eclipse ,然后您可以使用扩展点。您将需要扩展并覆盖 configureStatusDialog(...)方法:

If you have your own Eclipse product then you can customize details and support areas of the status dialog using org.eclipse.ui.statusHandlers extension point. You will need to extend WorkbenchErrorHandler and override configureStatusDialog(...) method:

void configureStatusDialog(WorkbenchStatusDialogManager statusDialog) {
    statusDialog.enableDefaultSupportArea(true);
    statusDialog.setDetailsAreaProvider(new CustomStatusAreaProvider());
}

class CustomStatusAreaProvider extends AbstractStatusAreaProvider {
    Control createSupportArea(Composite parent, StatusAdapter statusAdapter) {
        //Create and return details area
    }
}


通过将异常传递给状态,而不是使堆栈跟踪可用于错误日志视图的详细信息对话框。

By passing the exception to Status instead of null you make the stack trace available for details dialog of error log view.

这篇关于Eclipse StatusManager不显示详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:30