user1074737
user1074737

Reputation: 11

How to add a marker on the ruler?

I am trying to add a marker/icon on the vertical ruler in Eclipse. I used the following code for it

     IEditorPart editor = PlatformUI.getWorkbench()
        .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
     IFileEditorInput input = (IFileEditorInput)editor.getEditorInput() ;
     IFile file = input.getFile();
     IProject activeProject = file.getProject();
     IResource res = (IResource) activeProject;

     IMarker m;
     try {
            m = res.createMarker("com.examples.problem");
            m.setAttribute(IMarker.LOCATION, offset);
            m.setAttribute(IMarker.MESSAGE, "Hello");
            m.setAttribute(IMarker.LINE_NUMBER, offset);
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

Where offset is the line number where I want the marker. This piece of code the a marker but not on the ruler, but on the Problems view next to Console and Error log. Any idea how I can fix it? Also if there is any other way of adding a toggle/icon/marker on the ruler, please advice.

Upvotes: 1

Views: 3308

Answers (2)

Zoltán Ujhelyi
Zoltán Ujhelyi

Reputation: 13858

You should use markerAnnotationSpecification extension point. This is used to define a mapping between markers and editor annotations automatically, with specified formatting.

See my blog post for more details about it: http://cubussapiens.hu/2011/05/custom-markers-and-annotations-the-bright-side-of-eclipse/

Upvotes: 3

Martti Käärik
Martti Käärik

Reputation: 3621

You should create the marker on the file that is open in the editor, not on the project.

Upvotes: 1

Related Questions