Eclipse 3.3 Europa JDT TextHover - PullRequest
1 голос
/ 21 мая 2009

Я хочу показать свое собственное наведение текста в затмении для некоторых конкретных слов? Пожалуйста, предоставьте мне несколько примеров

Ответы [ 2 ]

1 голос
/ 12 июня 2009

Лучше всего сначала использовать плагин java editor вместе с eclipse. Воспользуйтесь помощью eclipse -> welcome-> Samples-> Java Editor plugin

1 голос
/ 21 мая 2009

Вы можете начать с просмотра примеров кодера .

например. это 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);
    }
}

Вы должны установить TextHover в SourceViewerConfiguration, например 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&gt;Preferences&gt;Java&gt;Code Generation&gt;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;
    }

}

Кроме того, у меня немного больше информации: примеры, которые я нашел, являются скорее программными, чем декларативными (то есть "plugin.xml"), так что вы можете захотеть изучить еще немного кода.

Другой хороший пример: Eclipse: Rich Hovers Redux (хотя и для eclipse3.4, но полный пример может дать вам еще один совет о том, как пользовательский ITextHover добавляется в текущий редактор)

...