Search in sources :

Example 1 with IInformationProviderExtension2

use of org.eclipse.jface.text.information.IInformationProviderExtension2 in project eclipse.platform.text by eclipse.

the class FocusedInformationPresenter method openFocusedAnnotationHover.

/**
 * Tries show a focused ("sticky") annotation hover.
 *
 * @param annotationHover the annotation hover to show
 * @param line the line for which to show the hover
 * @return <code>true</code> if successful, <code>false</code> otherwise
 */
public boolean openFocusedAnnotationHover(IAnnotationHover annotationHover, int line) {
    try {
        // compute the hover information
        Object hoverInfo;
        if (annotationHover instanceof IAnnotationHoverExtension) {
            IAnnotationHoverExtension extension = (IAnnotationHoverExtension) annotationHover;
            ILineRange hoverLineRange = extension.getHoverLineRange(fSourceViewer, line);
            if (hoverLineRange == null)
                return false;
            // allow any number of lines being displayed, as we support scrolling
            final int maxVisibleLines = Integer.MAX_VALUE;
            hoverInfo = extension.getHoverInfo(fSourceViewer, hoverLineRange, maxVisibleLines);
        } else {
            hoverInfo = annotationHover.getHoverInfo(fSourceViewer, line);
        }
        // hover region: the beginning of the concerned line to place the control right over the line
        IDocument document = fSourceViewer.getDocument();
        int offset = document.getLineOffset(line);
        String contentType = TextUtilities.getContentType(document, fSourceViewerConfiguration.getConfiguredDocumentPartitioning(fSourceViewer), offset, true);
        IInformationControlCreator controlCreator = null;
        if (// this is undocumented, but left here for backwards compatibility
        annotationHover instanceof IInformationProviderExtension2)
            controlCreator = ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
        else if (annotationHover instanceof IAnnotationHoverExtension)
            controlCreator = ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
        IInformationProvider informationProvider = new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
        setOffset(offset);
        setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT);
        // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1
        setMargins(4, 0);
        setInformationProvider(informationProvider, contentType);
        showInformation();
        return true;
    } catch (BadLocationException e) {
        return false;
    }
}
Also used : IInformationControlCreator(org.eclipse.jface.text.IInformationControlCreator) IInformationProviderExtension2(org.eclipse.jface.text.information.IInformationProviderExtension2) ILineRange(org.eclipse.jface.text.source.ILineRange) IInformationProvider(org.eclipse.jface.text.information.IInformationProvider) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IInformationProvider(org.eclipse.jface.text.information.IInformationProvider) IAnnotationHoverExtension(org.eclipse.jface.text.source.IAnnotationHoverExtension) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IInformationControlCreator (org.eclipse.jface.text.IInformationControlCreator)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 IInformationProvider (org.eclipse.jface.text.information.IInformationProvider)1 IInformationProviderExtension2 (org.eclipse.jface.text.information.IInformationProviderExtension2)1 IAnnotationHoverExtension (org.eclipse.jface.text.source.IAnnotationHoverExtension)1 ILineRange (org.eclipse.jface.text.source.ILineRange)1