开发者

Plug-in Development: Creating Problem Marker for a Given Resource

I seem to be having a problem with associating a problem marker with a resource; in my case, I'm trying to create a problem marker for the editor.

To achieve this, I've tried to do the following:

public class MyEditor extends TextEditor{

private ColorManager colorManager;

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

         IResource resource = (IResource) g开发者_运维知识库etEditorInput().getAdapter(IResource.class);

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

However, the problem is getEditorInput() keeps returning null. I assume I am not calling it at the right location. I thought it would be ideal to create the marker once I'm setting up the editor, but this proves otherwise.

Does anyone have any advice to obtaining the proper resource I want so that I may create the problem marker? I would like to show errors and such within the editor.

I've looked at samples online for creating the marker, but most just show methods that pass the ITextEditor object without showing where the method call is. (for example: Creating Error Marker for Compiler -- see reportError method)

Thank you. Paul

Edit: I have also viewed the following link regarding problem markers, but again, it calls createMarker from a resource(res, in this case), but does not show the setup for it. See Show Syntax Errors in An Eclipse Editor Plugin


EditorInput is initialize in init method You can override init or

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


I create a marker (including a call to getEditorInput()) from the run() method of an Action object.

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

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

Addition (Following Paul's comment) How to get an Editor?

Well, In my app I am subclassing AbstractRulerActionDelegate, by overriding the createAction(ITextEditor e, IVerticalRulerInfo ri) method (which, BTW, Is a must - this method is abstract) my app can get the relevant ITextEditor object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜