代码之家  ›  专栏  ›  技术社区  ›  Vinay Lodha

Eclipse标记不可见

  •  4
  • Vinay Lodha  · 技术社区  · 15 年前

    在添加自定义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());
    

    在打开编辑器时我还需要做什么吗??

    有什么建议吗…????

    2 回复  |  直到 15 年前
        1
  •  2
  •   VonC    15 年前

    bug 73420

    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);
    }
    
        2
  •  0
  •   Vinay Lodha    15 年前