Plugin development: creating a problem marker for this resource

It seems that I have a problem with binding the problem marker to the resource; in my case, I am trying to create a problem marker for the editor.

To achieve this, I tried to do the following:

public class MyEditor extends TextEditor{

private ColorManager colorManager;

public MyEditor() {
         super();
         ...

         IResource resource = (IResource) getEditorInput().getAdapter(IResource.class);

         try 
         {
             marker = resource.createMarker(IMarker.PROBLEM);            
         }
         catch (CoreException e) 
         {
             e.printStackTrace();
         }
    }

However, the problem is that getEditorInput () returns null. I guess I won’t call in the right place. I thought it would be ideal to create a marker when I create an editor, but this proves the opposite.

Does anyone have any tips on getting the required resource so that I can create a problem marker? I would like to show errors, etc. In the editor.

, , ITextEditor, , . (: - . ReportError)

.

: , , createMarker (res ), . . Eclipse

+1
2

EditorInput init init

public class MyEditor extends TextEditor{

private ColorManager colorManager;

public MyEditor() {
         super();
         ...
    }

public void init(IEditorSite site, IEditorInput input)
            throws PartInitException {
         super.init(site, input);
         IResource resource = (IResource) getEditorInput().getAdapter(IResource.class);

         try 
         {
             marker = resource.createMarker(IMarker.PROBLEM);            
         }
         catch (CoreException e) 
         {
             e.printStackTrace();
         }
}
+1

( getEditorInput()) run() Action.

public class MyAction extends Action {
   ...
   public void run() {
     ...

     int line = ...;
     IEditorInput ei = editor.getEditorInput()
     if (ei != null)
        createMarkerAt(line, ei);
   }    
}

( ) ?

, AbstractRulerActionDelegate, createAction(ITextEditor e, IVerticalRulerInfo ri) (, BTW, Is must - ), ITextEditor.

0

Source: https://habr.com/ru/post/1753681/


All Articles