2011-07-07 8 views
4

独自の注釈マーカーを使用するプラグインを作成しました。今私は特別なホバーアクションを追加したい、この特別なマーカーをマウスオーバーするとき。私はこの行動をどこに加えるべきか本当に分かりません。私はすでにIAnnotationHoverインターフェイスについて読んでいますが、AnnotationHoverを追加/変更するには、通常のワークベンチのテキストエディタの垂直ルーラにどのようにアクセスしますか?Eclipse上の自分の注釈上の操作(プラグイン)

p.s:もっと正確に言えば、私はEclipseの共通エディタを使用しています...自分のエディタではないので...私はSourceViewerConfigurationやIAnnotationHoverを上書きしないでください。 これまでのアイデアは?

答えて

0

a wayは、デフォルトのJavaエディタでカスタムホバーを作成します。

具体的な使用例についてのこの質問からの@ PKeidelのLangHoverクラスのカスタム実装は、custom script to detect java elementsと組み合わせてあります。 ANNOTATION_NAMEの値をカスタムAnnotationの値に、戻り値をgetHoverInfoに、カスタムホバーに含める値に変更する必要があります。

public class LangHover implements IJavaEditorTextHover 
{ 
    public static final String ANNOTATION_NAME = "YourCustomAnnotation"; 

    @SuppressWarnings("restriction") 
    public static ICodeAssist getCodeAssist(IEditorPart fEditor) 
    { 
     if (fEditor != null) { 
      IEditorInput input= fEditor.getEditorInput(); 
      if (input instanceof IClassFileEditorInput) { 
       IClassFileEditorInput cfeInput= (IClassFileEditorInput) input; 
       return cfeInput.getClassFile(); 
      } 

      WorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager(); 
      return manager.getWorkingCopy(input, false); 
     } 

     return null; 
    } 

    public static IEditorPart getActiveEditor() 
    { 
     IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 
     if (window != null) { 
      IWorkbenchPage page= window.getActivePage(); 
      if (page != null) { 
       return page.getActiveEditor(); 
      } 
     } 
     return null; 
    } 

    // When this returns true, the custom hover should be shown. 
    public static boolean elementIsCustomAnnotation(ITextViewer textViewer, IRegion hoverRegion) 
    { 
     IEditorPart activeEditor = getActiveEditor(); 
     ICodeAssist resolve = getCodeAssist(activeEditor); 
     IJavaElement[] detectedJavaElements = null; 

     if (resolve != null) 
     { 
      try 
      { 
       detectedJavaElements = resolve.codeSelect(hoverRegion.getOffset(), hoverRegion.getLength()); 
      } 
      catch (JavaModelException x) 
      { 
       System.out.println("JavaModelException occured"); 
      } 
     } 

     for (IJavaElement javaElement : detectedJavaElements) 
     { 
      // If I found an element of type IJavaElement.ANNOTATION 
      // and its name equals ANNOTATION_NAME, return true 
      if (javaElement.getElementType() == IJavaElement.ANNOTATION && javaElement.getElementName().equals(ANNOTATION_NAME)) 
      { 
       return true; 
      } 
     } 
     return false;   
    } 

    @Override 
    public String getHoverInfo(ITextViewer textviewer, IRegion region) 
    { 
     if(elementIsCustomAnnotation(textviewer, region)) 
     { 
      return "Your own hover text goes here""; 
     } 
     return null; // Shows the default Hover (Java Docs) 
    } 
} 

基本的には、どのようなここで起こっていることはelementIsCustomAnnotationdetectedJavaElements配列にそれらを置く、ユーザーがオーバーホバリングされたJava要素(複数可)をチェックし、その後に等しい名前の注釈を見つけるために、その配列を確認しているということですANNOTATION_NAME

関連する問題