简体   繁体   English

在JFace ErrorDialog中使用换行符

[英]Using newline in JFace ErrorDialog

Has anybody managed to show a detail error message in the JFace ErrorDialog using newline (\\n, \\r) character? 是否有人设法使用换行符(\\ n,\\ r)在JFace ErrorDialog中显示详细的错误消息?

I'm trying to display the StackTrace as a detail message, but it is only shown in one line 我正在尝试将StackTrace显示为详细信息,但只显示在一行中

StringBuffer sbStackTrace = new StringBuffer();
for (StackTraceElement ste : throwable.getStackTrace()) {
  sbStackTrace.append(ste.toString()).append('\n');
}

final IStatus status = new Status(IStatus.ERROR, pluginId, statusMsg, new Throwable(sbStackTrace.toString(), throwable));
ErrorDialog dialog = new ErrorDialog(shell, "Error", customMessage, status, IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR)

On open the ErrorDialog shows eveything I want, except that the detail message is not properly formatted. 打开时,ErrorDialog会显示我想要的内容,只是详细消息的格式不正确。

Any ideas? 有任何想法吗?

Looking at the ErrorDialog.populateList(List, IStatus, int, boolean) method in the source for ErrorDialog.java , it looks like the dialog only includes one IStatus per line, but if that IStatus has children, it will include them on subsequent lines. ErrorDialog.populateList(List, IStatus, int, boolean)源代码中查看 ErrorDialog.populateList(List, IStatus, int, boolean)方法,看起来对话框每行仅包含一个IStatus ,但是如果IStatus有子级,则它将在后续行中包含子级。 So you'll need to either build a MultiStatus object or create your own implementation of IStatus . 因此,您将需要构建MultiStatus对象或创建自己的IStatus实现。

Wrap the Exception with a new that contains the stacktrace as message. 用包含栈跟踪作为消息的新内容包装异常。

The code is here https://stackoverflow.com/a/19703255/2064294 代码在这里https://stackoverflow.com/a/19703255/2064294

I seem to remember this working with just '\\n' but I was also using: 我似乎记得仅使用'\\ n'进行此操作,但我也在使用:

ExceptionUtils.getStackTrace( ex );

From Apache Commons-Lang. 来自Apache Commons-Lang。

To achieve the same it is also possible to build MultiStatus. 为了达到相同的目的,还可以构建MultiStatus。 MultiStatus can have next IStatus(es) as children and because ErrorDialog in detail area is showing one IStatus per line, you will get the same result. MultiStatus可以将下一个IStatus作为子级,并且由于ErrorDialog在详细信息区域中每行显示一个IStatus,因此您将获得相同的结果。

Please see the trick in action in my other reply https://stackoverflow.com/a/9404081/915931 请在我的其他回复https://stackoverflow.com/a/9404081/915931中查看操作技巧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM