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;
}
}
Aggregations