views:

87

answers:

2

Hi,

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...???

A: 

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);
}
VonC
Hi I am using eclipse 3.5 and JDK 5. The code u provided will add marker to IWorkspaceRoot?? But I want to add marker to specific file. I tried that code but it didnt worked... I suspect I am missing something in Plugin.xml...
VinAy
@VinAy: the code I provided was just a copy of what I did found in the bug report, and not necessary adapted to your context. It was just to - hopefully - give you an idea about some element that could be missing. If you find other details, I am interested ;)
VonC
A: 

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.. :)

VinAy