Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » F2 focus for a TextHover comment(F2 support for ITextHover)
F2 focus for a TextHover comment [message #1006667] Fri, 01 February 2013 11:21
Shyamala Gowri is currently offline Shyamala GowriFriend
Messages: 3
Registered: September 2012
Junior Member

I am looking for a piece of code that could give F2 focus for a TextHover information.I understand that i should be using IinformationControlCreator and IInformationPresenter. Please let me the know the code that should go into getInformationControlCreator and getInformationPresenter. I have used these methods in the AAConfiguration class that extends SourceViewerConfiguration.

This is the code that i am using - @Override
public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {

InformationPresenter informationPresenter = (InformationPresenter) super.getInformationPresenter(sourceViewer);
ITextViewerExtension2 textViewerExtension2= (ITextViewerExtension2) sourceViewer;
ITextHover textHover= textViewerExtension2.getCurrentTextHover();
Point hoverEventLocation= textViewerExtension2.getHoverEventLocation();
int offset= computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
if (offset == -1) {

return null;
IRegion hoverRegion= textHover.getHoverRegion(sourceViewer, offset);
if (hoverRegion == null) {
return null;

String hoverInfo= textHover.getHoverInfo(sourceViewer, hoverRegion);
IInformationControlCreator controlCreator= null;
if (textHover instanceof IInformationProviderExtension2)
controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator();

IInformationProvider informationProvider= new InformationProvider(hoverRegion, hoverInfo, controlCreator);

informationPresenter.setInformationProvider(informationProvider, IDocument.DEFAULT_CONTENT_TYPE);
return informationPresenter;

public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent, false);

private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {

StyledText styledText= textViewer.getTextWidget();
IDocument document= textViewer.getDocument();

if (document == null) {
return -1;

try {
int widgetLocation= styledText.getOffsetAtLocation(new Point(x, y));
if (textViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer;
return extension.widgetOffset2ModelOffset(widgetLocation);
IRegion visibleRegion= textViewer.getVisibleRegion();
return widgetLocation + visibleRegion.getOffset();
} catch (IllegalArgumentException e) {
return -1;

class InformationProvider implements IInformationProvider, IInformationProviderExtension2 {
private IRegion fHoverRegion;
private String fHoverInfo;
private IInformationControlCreator fControlCreator;

InformationProvider(IRegion hoverRegion, String hoverInfo, IInformationControlCreator controlCreator) {
fHoverRegion= hoverRegion;
fHoverInfo= hoverInfo;
fControlCreator= controlCreator;

public IInformationControlCreator getInformationPresenterControlCreator ()
return fControlCreator;

public String getInformation (ITextViewer arg0, IRegion arg1)
return fHoverInfo;

public IRegion getSubject (ITextViewer arg0, int arg1)
return fHoverRegion;


And my plugin.xml contains the bindings as

name="Doc Hover comment">
label="Hover Actions"
description="Action set containing text hover actions"
class="org.eclipse.ui.texteditor.AbstractTextEditor.createActions" >

With the above code, i am not able to open any code in the editor. It throws NPE when attempted.
Please let me know the steps that i should follow to enable F2 support for the text hover.

Thanks in Advance,

Previous Topic:focus on hover info
Next Topic:Package Explorer sort
Goto Forum:

Current Time: Tue Oct 27 07:25:45 GMT 2020

Powered by FUDForum. Page generated in 0.01824 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top