如何在 Eclipse 中的表单编辑器选项卡上显示错误标记图标?

How to display error marker icon on the form editor tab in Eclipse?

我在 Eclipse IDE 编程时看到,当 java 文件中出现编译错误时,Eclipse 在选项卡上显示错误图标。 (请参考图片)。同样,我已经创建了自定义表单编辑器,并且我想在出现验证错误时在编辑器选项卡上显示相同的错误图标。

您可以通过调用 WorkbenchPart

来设置编辑器图像
protected void setTitleImage(Image titleImage)

方法。您的主编辑器部分应该能够做到这一点(编辑器部分扩展 EditorPart 扩展 WorkbenchPart)。

何时显示错误指示器和构建图像由您决定。

JFace 提供了 DecorationOverlayIcon class 这有助于在基本图像上覆盖错误指示器。例如:

Image image = ... base image

ImageDescriptor overlay = ... image descriptor for overlay

DecorationOverlayIcon decoratedImageDesc = new DecorationOverlayIcon(image, overlay, IDecoration.BOTTOM_LEFT);

Image overlayedImage = decoratedImageDesc.createImage();