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
Hi,

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

@Override
public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
return new IInformationControlCreator() {
@Override
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;
}



@Override
public IInformationControlCreator getInformationPresenterControlCreator ()
{
return fControlCreator;
}

@Override
public String getInformation (ITextViewer arg0, IRegion arg1)
{
return fHoverInfo;
}

@Override
public IRegion getSubject (ITextViewer arg0, int arg1)
{
return fHoverRegion;
}

}

And my plugin.xml contains the bindings as

<command
categoryId="aaa.editor.command.category"
id="aaa.editor.command.hover"
name="Doc Hover comment">
</command>
<key
commandId="aaa.editor.command.hover"
contextId="aaa.aEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F2">
</key>
<actionSet
label="Hover Actions"
description="Action set containing text hover actions"
visible="true"
id="aaa.editor.commands.HoverActionSets">
<action
definitionId="aaa.editor.command.hover"
class="org.eclipse.ui.texteditor.AbstractTextEditor.createActions" >
</action>
</actionSet>

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,

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


Current Time: Fri Apr 19 07:58:14 GMT 2024

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

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

Back to the top