java - Eclipse 插件 : Custom icon for a Marker

标签 java eclipse eclipse-plugin

我想为标记指定自定义图标。遗憾的是,我选择的图标没有显示。

以下是 plugin.xml 文件的相关部分(项目 ID“x”):

<extension
      id="xmlProblem"
      name="XML Problem"
      point="org.eclipse.core.resources.markers">
   <super type="org.eclipse.core.resources.problemmarker"/>
   <persistent
         value="true">
   </persistent>
</extension>

<extension
      point="org.eclipse.ui.ide.markerImageProviders">
   <imageprovider
         markertype="x.xmlProblem"
         icon="icons/marker.png"
         id="xmlProblemImageProvider">
   </imageprovider>
</extension>

我还尝试指定一个类(实现 IMarkerImageProvider)而不是图标,但是没有调用该类的 getImagePath() 方法。

对如何使自定义标记图标起作用有什么想法吗?

绝望地,你的。

-意大利

更新

VonC 的解决方案非常正确,除了您必须指定 org.eclipse.core.resources.problemmarker 作为标记的父类(super class)型。它仅在我将 org.eclipse.core.resources.textmarker 用作唯一父类(super class)型时起作用。

最佳答案

参见 bug 260909 “markerImageProviders扩展点不起作用”(阅读后发现this thread)

Tod Creasey 2009-01-21 07:32:38 EST

We have never had the push to make this API because it has some inflexibility that made it generally not consumable - it was written early on to enable the first marker views for the 3 severities we use and as a result was not used by the markerSupport as it was not API.

It is confusing that we have an internal extension point (we don't generally do that) but removing it would likely break someone without warning.

[由 Itay 编辑]

根据 Vonc 的指示,我最终成功地使这件事成功了。 以下是我的 plugin.xml 中的相关片段(假设插件名称是 a.b.c)

  <extension point="org.eclipse.core.resources.markers"   
        id="myMarker">
     <super type="org.eclipse.core.resources.textmarker"/>         
     <persistent value="true"/>
  </extension>

  <extension point="org.eclipse.ui.editors.annotationTypes">
     <type
        super="org.eclipse.ui.workbench.texteditor.warning"
        markerType="a.b.c.myMarker"
        name="a.b.c.myAnnotation"
        markerSeverity="1"/>
  </extension>

  <extension point="org.eclipse.ui.editors.markerAnnotationSpecification">
     <specification
        annotationType="a.b.c.myAnnotation"
        icon="icons/marker.png"
        verticalRulerPreferenceKey="myMarkerIndicationInVerticalRuler"
        verticalRulerPreferenceValue="true"/>
  </extension>

陷阱

  • 标记的父类(super class)型必须设置为org.eclipse.core.resources.textmarker。任何其他值都会阻止使用您的自定义图标。
  • 当您在代码中创建标记时,确保其严重性与 org.eclipse.ui.editors.annotationTypes 扩展的 markerSeverity 属性中指定的严重性值相匹配观点。 1表示警告等
  • 确保在您的 build.properties 文件(或插件编辑器的“构建”选项卡)中指定了图标文件夹
  • 上面的声明只会指定一个自定义图标。如果您想自定义其他属性(概览标尺上的指示颜色等),请按照 here 中的示例进行操作此解决方案基于此。

关于java - Eclipse 插件 : Custom icon for a Marker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2888207/

相关文章:

java - Springboot 1.3.3 在 Jboss EAP 6.4.0GA 中给出 404

java - 如何从在 GKE 上运行的 Java 应用程序获取 GCP 错误报告(谷歌 kubernetes 引擎)

Java:图像未在 Eclipse 中加载

java - Eclipse 中 Android 中 onCreateOptionsMenu 的 inflate 方法出错

android - Eclipse Android 插件未列出自定义组件自动完成的属性

java - 如何从命令行使用 Eclipse 嵌入式 Maven 安装?

java.lang.NullPointerException 在 org.openqa.selenium.support.pagefactory.findElement(DefaultElementLocator.java :69)

java - 如何为所有 Android 应用程序设置 Holo 灯光主题

java - 从 java 项目转换为插件项目的选项在哪里?

java - 使用 ehcache 从 Spring Repository 获取 HashMap 而不是实体