Vinay Lodha
Vinay Lodha

Reputation: 2223

Eclipse marker is Invisible

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

Upvotes: 4

Views: 1995

Answers (2)

Vinay Lodha
Vinay Lodha

Reputation: 2223

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

Upvotes: 0

VonC
VonC

Reputation: 1323313

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);
}

Upvotes: 2

Related Questions