日食标记是不可见的

发布于 2024-09-19 19:38:17 字数 1688 浏览 4 评论 0原文

我在添加自定义 Eclipse 标记时遇到一个奇怪的问题。场景是,在添加标记时,当资源(我需要添加标记)打开时,标记图标可见。但是,如果资源未打开,则会添加标记,但图标不可见。

这是我正在使用的代码片段

<extension
         id="HighPriority"
         name="High Priority problem"
         point="org.eclipse.core.resources.markers">
      <persistent value="true">
      </persistent>
      <super type="org.eclipse.core.resources.problemmarker"/>
      <super type="org.eclipse.core.resources.textmarker"/>
 </extension>

 <extension point="org.eclipse.ui.editors.annotationTypes">
      <type
         name="X.X.X.HighPriorityAnnotation"
         super="org.eclipse.ui.workbench.texteditor.warning"
         markerType="X.X.X.HighPriority"/>

 </extension>
 <extension point="X.X.X.markerAnnotationSpecification">
      <specification
            annotationType="X.X.X.HighPriorityAnnotation"
            icon="icons\img.gif"
       />

 </extension>

,用于创建标记的代码是

IMarker marker = markerNode.getTargetFile().createMarker(markerNode.getPriority().getMarkerName());

Map<String, Object> attributes = new HashMap<String,Object>();
attributes.put(IMarker.LINE_NUMBER, markerNode.getLineNumber());
attributes.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_WARNING));
attributes.put(IMarker.MESSAGE, markerNode.getMessage());
attributes.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_HIGH));
marker.setAttributes(attributes);

打开编辑器,我使用以下代码,

IDE.openEditor(this.getSite().getPage(), marker, OpenStrategy.activateOnOpen());

打开编辑器时我还需要执行其他操作吗?

有什么建议...???

I am facing a strange problem while adding custom eclipse marker. The scenario is that while adding marker, when a resource(To which I need to add marker) is open then Marker icon is visible. But if the resource is not open then marker is added but icon is not visible.

Here is a snippet of code I am using

<extension
         id="HighPriority"
         name="High Priority problem"
         point="org.eclipse.core.resources.markers">
      <persistent value="true">
      </persistent>
      <super type="org.eclipse.core.resources.problemmarker"/>
      <super type="org.eclipse.core.resources.textmarker"/>
 </extension>

 <extension point="org.eclipse.ui.editors.annotationTypes">
      <type
         name="X.X.X.HighPriorityAnnotation"
         super="org.eclipse.ui.workbench.texteditor.warning"
         markerType="X.X.X.HighPriority"/>

 </extension>
 <extension point="X.X.X.markerAnnotationSpecification">
      <specification
            annotationType="X.X.X.HighPriorityAnnotation"
            icon="icons\img.gif"
       />

 </extension>

And code for creating marker is

IMarker marker = markerNode.getTargetFile().createMarker(markerNode.getPriority().getMarkerName());

Map<String, Object> attributes = new HashMap<String,Object>();
attributes.put(IMarker.LINE_NUMBER, markerNode.getLineNumber());
attributes.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_WARNING));
attributes.put(IMarker.MESSAGE, markerNode.getMessage());
attributes.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_HIGH));
marker.setAttributes(attributes);

To open editor I using following code

IDE.openEditor(this.getSite().getPage(), marker, OpenStrategy.activateOnOpen());

Do I need to do anything else while opening editor??

Any Suggestions...???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疧_╮線 2024-09-26 19:38:17

您可以将您的代码与应该正常工作的代码进行比较,如 中发布的错误 73420
那个旧错误(eclipse 3.1)的上下文与您的不同,但可以为您提供一些关于尝试什么的线索或想法。
您使用的 Eclipse 和 Java 版本是什么?

该错误报告摘录:

这段代码也可以正常工作

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

IMarker[] markers = root.findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO);

for (int i = 0; i < markers.length; i++) {
  String message = (String) markers[i].getAttribute(IMarker.MESSAGE);

  if (message != null && message.startsWith("this is a test")) {
    markers[i].delete();
  }
}

//IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Map attribs = new HashMap();
for (int i = 0; i < 8; i++) {
  attribs.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
  attribs.put(IMarker.MESSAGE, "this is a test " + i);
  attribs.put("bogus field", "some text");
  MarkerUtilities.createMarker(root, attribs, IMarker.PROBLEM);
}

You can compare your code with ones supposed to work fine, as posted in bug 73420.
The context of that old bug (eclipse 3.1) is not the same than yours, but can give you some clue or idea about what to try.
What Eclipse and Java version are you using?

Extract from that bug report:

This code also works fine

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

IMarker[] markers = root.findMarkers(IMarker.PROBLEM, false, IResource.DEPTH_ZERO);

for (int i = 0; i < markers.length; i++) {
  String message = (String) markers[i].getAttribute(IMarker.MESSAGE);

  if (message != null && message.startsWith("this is a test")) {
    markers[i].delete();
  }
}

//IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
Map attribs = new HashMap();
for (int i = 0; i < 8; i++) {
  attribs.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
  attribs.put(IMarker.MESSAGE, "this is a test " + i);
  attribs.put("bogus field", "some text");
  MarkerUtilities.createMarker(root, attribs, IMarker.PROBLEM);
}
高速公鹿 2024-09-26 19:38:17

早些时候我已经将我的代码付诸行动。但是在我用项目构建器替换它之后,它开始工作......

我不知道出了什么问题......:)

Earlier I have dumped my code into action. But after I have replaced it with a project builder it started working...

I dont have clue what went wrong.. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文