2009-05-21 12 views
1

私はいくつかの具体的な言葉のために私自身のテキストのホバーをEclipseで表示したいですか?私にいくつかの例を教えてくださいEclipse 3.3 Europa JDT TextHover

+0

3.3 Europaを使用している特別な理由はありますか? 3.4 Ganymedeはほぼ一歳で、3.5 Galileoのリリースに近づいています。 – Powerlord

答えて

1

Koder examplesから見ることができます。

など。このあなたがこのGasSourceViewerConfigurationまたはそれを超えて、このCalcSourceViewerConfiguration

package com.example.calc.ui.editors; 

import org.eclipse.jface.text.ITextHover; 
import org.eclipse.jface.text.reconciler.IReconciler; 
import org.eclipse.jface.text.reconciler.MonoReconciler; 
import org.eclipse.jface.text.source.ISourceViewer; 
import org.eclipse.jface.text.source.SourceViewerConfiguration; 

/** 
* @author cdaly 
* 
* To change the template for this generated type comment go to 
* Window>Preferences>Java>Code Generation>Code and Comments 
*/ 
public class CalcSourceViewerConfiguration extends SourceViewerConfiguration { 

    private CalcEditor _editor; 

    public CalcSourceViewerConfiguration(CalcEditor editor){ 
     _editor = editor; 
    } 



    /* (non-Javadoc) 
    * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer) 
    */ 
    public IReconciler getReconciler(ISourceViewer sourceViewer) { 
     return new MonoReconciler(_editor.getReconcilingStrategy(), false); 
    } 

    /* (non-Javadoc) 
    * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTextHover(org.eclipse.jface.text.source.ISourceViewer, java.lang.String) 
    */ 
    public ITextHover getTextHover(
     ISourceViewer sourceViewer, 
     String contentType) { 
     ITextHover hover; 
     if (_editor != null && _editor instanceof CalcEditor) { 
      hover = new CalcTextHover((CalcEditor)_editor); 
     } else { 
      hover = null; 
     } 
     return hover; 
    } 

} 

ようSourceViewerConfigurationにTextHoverを設定しますCEditorTextHoverDispatcherまたはこのUCTextHover

package com.ut2003.uceditor; 

import org.eclipse.jface.text.BadLocationException; 
import org.eclipse.jface.text.IRegion; 
import org.eclipse.jface.text.ITextHover; 
import org.eclipse.jface.text.ITextViewer; 
import org.eclipse.jface.text.Region; 
import org.eclipse.swt.graphics.Point; 

public class UCTextHover implements ITextHover 
{ 

    /* (non-Javadoc) 
    * Method declared on ITextHover 
    */ 
    public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) 
    { 
     if (hoverRegion != null) 
     { 
      try 
      { 
       if (hoverRegion.getLength() > -1) 
        return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength()); 
      } 
      catch (BadLocationException x) 
      { 
      } 
     } 
     return "Empty Selection"; 
    } 

    /* (non-Javadoc) 
    * Method declared on ITextHover 
    */ 
    public IRegion getHoverRegion(ITextViewer textViewer, int offset) 
    { 
     Point selection = textViewer.getSelectedRange(); 
     if (selection.x <= offset && offset < selection.x + selection.y) 
      return new Region(selection.x, selection.y); 
     return new Region(offset, 0); 
    } 
} 

、私はあまり多くの情報を持っています:私が見つけた例は宣言型(すなわち "plugin.xml")よりプログラム的であるため、いくつかのコードが追加されました。

もう一つの良い例:Eclipse: Rich Hovers Redux(それはしかしeclipse3.4のためですが、完全な例では、カスタムITextHoverは現在のエディタに追加されたどのようにあなたに別のヒントを与えることができます)

+0

お返事ありがとうございました。このウィザードをJavaEditorに追加するには、どのプラグイン開発環境でどのウィザードを使用する必要がありますか? JavaEditorでこれを取得するには、どの拡張ポイントをplugin.xmlに追加する必要がありますか –

1

最高のものが使用することですEclipseエディタと一緒にJavaエディタプラグイン。 Eclipseヘルプ - >ようこそ - >サンプル - > Java Editorプラグイン

関連する問題