Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » focus on hover info
focus on hover info [message #176063] Tue, 06 January 2004 04:00 Go to next message
Geoff Howard is currently offline Geoff Howard
Messages: 9
Registered: July 2009
Junior Member
I have an editor plugin in 3.0M5 which is providing a text hover
behavior with a class which implements ITextHover, ITextHoverExtension.
I'm trying to get F2 to give focus (and a scroll bar) to the hover info
when the text is long. I've looked over the JDT code and can't see what
they're doing to set this up any different than what I've done.

my getInformationControlCreator method is:

return new IInformationControlCreator() {
public IInformationControl
createInformationControl(Shell parent) {
DefaultInformationControl ic =
new DefaultInformationControl(parent, SWT.NONE,
null,"Press F2 to focus");
return ic;
}
};

I see the statusFieldText Correctly, but F2 simply closes the hover
info. As a long shot, I also tried passing in a trivial
IImplementationPresenter instead of null to the
DefaultInformationControl constructor but that had no effect.

At this point, I'm not sure if I've failed to implement some other step
(for example is F2 automatically bound to this behavior or do I need to
configure that?) or if I have some event listener which is intercepting
that event and fouling it up.

Thanks,
Geoff
Re: focus on hover info [message #177079 is a reply to message #176063] Thu, 08 January 2004 10:08 Go to previous messageGo to next message
Eclipse User
Originally posted by: daniel.megert.gmx.net

Geoff Howard wrote:

> I have an editor plugin in 3.0M5 which is providing a text hover
> behavior with a class which implements ITextHover, ITextHoverExtension.
> I'm trying to get F2 to give focus (and a scroll bar) to the hover
> info when the text is long. I've looked over the JDT code and can't
> see what they're doing to set this up any different than what I've done.
>
> my getInformationControlCreator method is:
>
> return new IInformationControlCreator() {
> public IInformationControl
> createInformationControl(Shell parent) {
> DefaultInformationControl ic =
> new DefaultInformationControl(parent, SWT.NONE,
> null,"Press F2 to focus");
> return ic;
> }
> };
>
> I see the statusFieldText Correctly, but F2 simply closes the hover
> info. As a long shot, I also tried passing in a trivial
> IImplementationPresenter instead of null to the
> DefaultInformationControl constructor but that had no effect.
>
> At this point, I'm not sure if I've failed to implement some other
> step (for example is F2 automatically bound to this behavior or do I
> need to configure that?) or if I have some event listener which is
> intercepting that event and fouling it up.

For a start see IInformationPresenter and
SourceViewerConfiguration.getInformationControlCreator

Dani

>
> Thanks,
> Geoff
>
Re: focus on hover info [message #177555 is a reply to message #177079] Fri, 09 January 2004 02:50 Go to previous messageGo to next message
Geoff Howard is currently offline Geoff Howard
Messages: 9
Registered: July 2009
Junior Member
Daniel Megert wrote:

> Geoff Howard wrote:
>
>> I have an editor plugin in 3.0M5 which is providing a text hover
>> behavior with a class which implements ITextHover, ITextHoverExtension.
>> I'm trying to get F2 to give focus (and a scroll bar) to the hover
>> info when the text is long. I've looked over the JDT code and can't
>> see what they're doing to set this up any different than what I've done.
>>
>> my getInformationControlCreator method is:
>>
>> return new IInformationControlCreator() {
>> public IInformationControl
>> createInformationControl(Shell parent) {
>> DefaultInformationControl ic =
>> new DefaultInformationControl(parent, SWT.NONE,
>> null,"Press F2 to focus");
>> return ic;
>> }
>> };
>>
>> I see the statusFieldText Correctly, but F2 simply closes the hover
>> info. As a long shot, I also tried passing in a trivial
>> IImplementationPresenter instead of null to the
>> DefaultInformationControl constructor but that had no effect.
>>
>> At this point, I'm not sure if I've failed to implement some other
>> step (for example is F2 automatically bound to this behavior or do I
>> need to configure that?) or if I have some event listener which is
>> intercepting that event and fouling it up.
>
> For a start see IInformationPresenter and
> SourceViewerConfiguration.getInformationControlCreator

That's what I've been trying to do - as far as I can tell there is no
significant difference between the jdt implementation of those
interfaces and mine. I don't think I need to do anything with
IInformationPresenter because the content of my hover text is just text
(for now). I don't see any appreciable difference between my
getInformationControlCreator implementation above and the one in the jdt .

Sorry for being dull, but I see nothing in any of the code or docs I've
gone through indicating what causes the "focus" behavior to bind to F2,
and what in the IInformationControl, editor configuration, etc. which
causes the hover window to respond to this event and change state.

I did find in one jdt implementation:
IInformationProviderExtension2#getInformationPresenterContro lCreator
which created an IInformationControl which creates a Control with
SWT.RESIZE, SWT.V_SCROLL and SWT.H_SCROLL styles. I see no indication
that this is related to the "sticky" behavior, but I implemented this
anyway.

The only remaining thing is to go very carefully through the differences
between DefaultInformationControl and SourceViewerInformationControl but
I just don't see anything which is logically connected to the
focus/sticky behavior.

So, either I've missed it in this section of interfaces or I'm totally
barking up the wrong tree and there is some editor configuration which
enables the sticky behavior on F2.

I could try tracking through with the debugger but I'd need to know
where to set the breakpoint that would let me both fire the hover event
and capture the handling of the F2 keypress. Setting the breakpoint in
the code which creates/fills the hover so far hasn't worked because of
switching between the editors.

Any more hints anyone?

Geoff
Re: focus on hover info [message #177771 is a reply to message #177555] Fri, 09 January 2004 15:58 Go to previous messageGo to next message
Eclipse User
Originally posted by: daniel.megert.gmx.net

Geoff Howard wrote:

> Daniel Megert wrote:
>
>> Geoff Howard wrote:
>>
>>> I have an editor plugin in 3.0M5 which is providing a text hover
>>> behavior with a class which implements ITextHover, ITextHoverExtension.
>>> I'm trying to get F2 to give focus (and a scroll bar) to the hover
>>> info when the text is long. I've looked over the JDT code and can't
>>> see what they're doing to set this up any different than what I've
>>> done.
>>>
>>> my getInformationControlCreator method is:
>>>
>>> return new IInformationControlCreator() {
>>> public IInformationControl
>>> createInformationControl(Shell parent) {
>>> DefaultInformationControl ic =
>>> new DefaultInformationControl(parent, SWT.NONE,
>>> null,"Press F2 to focus");
>>> return ic;
>>> }
>>> };
>>>
>>> I see the statusFieldText Correctly, but F2 simply closes the hover
>>> info. As a long shot, I also tried passing in a trivial
>>> IImplementationPresenter instead of null to the
>>> DefaultInformationControl constructor but that had no effect.
>>>
>>> At this point, I'm not sure if I've failed to implement some other
>>> step (for example is F2 automatically bound to this behavior or do I
>>> need to configure that?) or if I have some event listener which is
>>> intercepting that event and fouling it up.
>>
>>
>> For a start see IInformationPresenter and
>> SourceViewerConfiguration.getInformationControlCreator
>
>
> That's what I've been trying to do - as far as I can tell there is no
> significant difference between the jdt implementation of those
> interfaces and mine. I don't think I need to do anything with
> IInformationPresenter because the content of my hover text is just
> text (for now). I don't see any appreciable difference between my
> getInformationControlCreator implementation above and the one in the
> jdt .
>
> Sorry for being dull, but I see nothing in any of the code or docs
> I've gone through indicating what causes the "focus" behavior to bind
> to F2, and what in the IInformationControl, editor configuration, etc.
> which causes the hover window to respond to this event and change state.
>
> I did find in one jdt implementation:
> IInformationProviderExtension2#getInformationPresenterContro lCreator
> which created an IInformationControl which creates a Control with
> SWT.RESIZE, SWT.V_SCROLL and SWT.H_SCROLL styles. I see no indication
> that this is related to the "sticky" behavior, but I implemented this
> anyway.
>
> The only remaining thing is to go very carefully through the
> differences between DefaultInformationControl and
> SourceViewerInformationControl but I just don't see anything which is
> logically connected to the focus/sticky behavior.
>
> So, either I've missed it in this section of interfaces or I'm totally
> barking up the wrong tree and there is some editor configuration which
> enables the sticky behavior on F2.
>
> I could try tracking through with the debugger but I'd need to know
> where to set the breakpoint that would let me both fire the hover
> event and capture the handling of the F2 keypress. Setting the
> breakpoint in the code which creates/fills the hover so far hasn't
> worked because of switching between the editors.
>
> Any more hints anyone?

Did you bind the action? See InformationDispatchAction on how it is done
for the Java editor.

Dani

>
> Geoff
>
Re: focus on hover info [message #180276 is a reply to message #177771] Thu, 15 January 2004 05:45 Go to previous messageGo to next message
Geoff Howard is currently offline Geoff Howard
Messages: 9
Registered: July 2009
Junior Member
Daniel Megert wrote:
> Geoff Howard wrote:
>
>> Daniel Megert wrote:
>>
>>> Geoff Howard wrote:
>>>
>>>> I have an editor plugin in 3.0M5 which is providing a text hover
>>>> behavior with a class which implements ITextHover, ITextHoverExtension.
>>>> I'm trying to get F2 to give focus (and a scroll bar) to the hover
>>>> info when the text is long. I've looked over the JDT code and can't
>>>> see what they're doing to set this up any different than what I've
>>>> done.
>>>>
>>>> my getInformationControlCreator method is:
>>>>
>>>> return new IInformationControlCreator() {
>>>> public IInformationControl
>>>> createInformationControl(Shell parent) {
>>>> DefaultInformationControl ic =
>>>> new DefaultInformationControl(parent, SWT.NONE,
>>>> null,"Press F2 to focus");
>>>> return ic;
>>>> }
>>>> };
>>>>
>>>> I see the statusFieldText Correctly, but F2 simply closes the hover
>>>> info. As a long shot, I also tried passing in a trivial
>>>> IImplementationPresenter instead of null to the
>>>> DefaultInformationControl constructor but that had no effect.
>>>>
>>>> At this point, I'm not sure if I've failed to implement some other
>>>> step (for example is F2 automatically bound to this behavior or do I
>>>> need to configure that?) or if I have some event listener which is
>>>> intercepting that event and fouling it up.
>>>
>>>
>>>
>>> For a start see IInformationPresenter and
>>> SourceViewerConfiguration.getInformationControlCreator
>>
>>
>>
>> That's what I've been trying to do - as far as I can tell there is no
>> significant difference between the jdt implementation of those
>> interfaces and mine. I don't think I need to do anything with
>> IInformationPresenter because the content of my hover text is just
>> text (for now). I don't see any appreciable difference between my
>> getInformationControlCreator implementation above and the one in the
>> jdt .
>>
>> Sorry for being dull, but I see nothing in any of the code or docs
>> I've gone through indicating what causes the "focus" behavior to bind
>> to F2, and what in the IInformationControl, editor configuration, etc.
>> which causes the hover window to respond to this event and change state.
>>
>> I did find in one jdt implementation:
>> IInformationProviderExtension2#getInformationPresenterContro lCreator
>> which created an IInformationControl which creates a Control with
>> SWT.RESIZE, SWT.V_SCROLL and SWT.H_SCROLL styles. I see no indication
>> that this is related to the "sticky" behavior, but I implemented this
>> anyway.
>>
>> The only remaining thing is to go very carefully through the
>> differences between DefaultInformationControl and
>> SourceViewerInformationControl but I just don't see anything which is
>> logically connected to the focus/sticky behavior.
>>
>> So, either I've missed it in this section of interfaces or I'm totally
>> barking up the wrong tree and there is some editor configuration which
>> enables the sticky behavior on F2.
>>
>> I could try tracking through with the debugger but I'd need to know
>> where to set the breakpoint that would let me both fire the hover
>> event and capture the handling of the F2 keypress. Setting the
>> breakpoint in the code which creates/fills the hover so far hasn't
>> worked because of switching between the editors.
>>
>> Any more hints anyone?
>
> Did you bind the action? See InformationDispatchAction on how it is done
> for the Java editor.

Thank you. I had not bound the action (note below in case others are
looking for the same clues) and I had a problem with the
InformationPresenter because I had mixed up what contentType to use. I
haven't fully tracked down why yet, but I think I get the basic idea. I
think using SourceViewerInformationControl (from one of the several java
hovers) was what made this more complicated than it needed to be in my
case - my hover text is just unstyled text with no partitions.

Thanks again,
Geoff

For other newbies:

I had not bound the action because I was assuming it was already bound
to an existing command in TextEditor or family. I didn't yet
understand the concepts enough to ask that question but went back and
had a little "RTFM again" session and got that piece sorted out quickly.
I created a new command (show info) and keybinding in the
org.eclipse.ui.commands extension point in my plugin.xml. The only code
bit for binding in this case (since I didn't need/want it in any menus
at this point) was to bind the action in
AbstractTextEditor.createActions. For now I used the global scope for
the keybinding, but later I'll go back and set up a scope for my file
types and use that.

Another key piece I was missing is that (unless I'm really confused)
there does not seem to be any magic to "focus" on the hover. The effect
observed appears to be actually replacing the hover with a new widget -
an InformationPresenter with resize and scroll controls whose content is
taken out of the hover and so is identical.
Re: focus on hover info [message #1006633 is a reply to message #180276] Fri, 01 February 2013 09:34 Go to previous message
Shyamala Gowri is currently offline Shyamala Gowri
Messages: 3
Registered: September 2012
Junior Member
Hi,

I am looking for a similar piece of code that could give F2 focus for a TextHover information.

From this thread 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:How to monitor changes to properties managed by project PropertyPages?
Next Topic:F2 focus for a TextHover comment
Goto Forum:
  


Current Time: Tue Sep 23 16:38:03 GMT 2014

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

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