Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Key bindings in custom widgets(How to deal with Eclipse key bindings in custom widgets, i.e. how to "overwrite" them?)
Key bindings in custom widgets [message #496814] Wed, 11 November 2009 13:29 Go to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Hi,

I have a problem with my custom widget. A table-like widget listens to key events and handles the occurence of the enter-key. Unfortuanetly, one of my Eclipse commands has a binding to that key and therefore is invoked when enter-key is pressed in my widget. My widget can handle the key but it seems that there is no way to prevent the Eclipse command to be executed. Preventing is necessary for my application because the enter-key opens a cell editor in the table and my Eclipse command opens a dialog that obviously interrupts the user. Any ideas? It would be nice to have a key-binding "context" also in single widgets but as far as I know the context can only be set on workbench parts.

I thought that an action delegation like org.eclipse.ui.actions.TextActionHandler can solve the problem by redirecting the Eclipse command to the table but this does not ensure that any other Eclipse command is invoked on enter-key.

Best regards,
Steffen
Re: Key bindings in custom widgets [message #496831 is a reply to message #496814] Wed, 11 November 2009 14:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6559
Registered: July 2009
Senior Member
You can switch contexts based upon the focus control using the focus
service.

I showed how to use it in my EclipseCon [1] presentation but the code is
here [2]
Tom

[1]http://live.eclipse.org/node/742
[2] http://github.com/tomsontom/emf-databinding-example/blob/mas ter/org.eclipse.emf.examples.library.databinding/src/org/ecl ipse/emf/examples/library/databinding/editor/LibraryEditor.j ava

Steffen Harbich schrieb:
> Hi,
>
> I have a problem with my custom widget. A table-like widget listens to
> key events and handles the occurence of the enter-key. Unfortuanetly,
> one of my Eclipse commands has a binding to that key and therefore is
> invoked when enter-key is pressed in my widget. My widget can handle the
> key but it seems that there is no way to prevent the Eclipse command to
> be executed. Preventing is necessary for my application because the
> enter-key opens a cell editor in the table and my Eclipse command opens
> a dialog that obviously interrupts the user. Any ideas? It would be nice
> to have a key-binding "context" also in single widgets but as far as I
> know the context can only be set on workbench parts.
>
> I thought that an action delegation like
> org.eclipse.ui.actions.TextActionHandler can solve the problem by
> redirecting the Eclipse command to the table but this does not ensure
> that any other Eclipse command is invoked on enter-key.
>
> Best regards,
> Steffen
Re: Key bindings in custom widgets [message #496854 is a reply to message #496814] Wed, 11 November 2009 14:46 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Steffan, Tom has provide a good example of tying a context to a specific control (the same expression could be used to enable a handler for a specific control as well).

The eclipse keybindings work by installing an SWT.KeyDown filter. As long as that is on, keybinding matches will be consumed long before a control (custom or otherwise) can see them.

PW


Re: Key bindings in custom widgets [message #496879 is a reply to message #496814] Wed, 11 November 2009 16:02 Go to previous messageGo to next message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Thank you for your replies!

Quote:
You can switch contexts based upon the focus control using the focus service.


I'm not certain if i understand what the focus service does related to the problem: it provides the variable for focused control and the copy/cut/... command handlers use this variable to delegate to e.g. focused text widget's cut/copy/... methods?

If so, there is another problem: any command can be associated with the enter-key as shortcut (using preferences), not only the one I contribute (that maybe delegate to my custom widget if focused control is considered). How do I ensure that other Eclipse commands do not disturb the cell editing?

By the way, my company is using Eclipse 3.2 and therefore the focus service is not available.

I think a widget should have the possibility to handle keys before any Eclipse shortcuts are handled. As you said, Paul, this is not possible. I will have to find another solution.

Thanks again,
Steffen
Re: Key bindings in custom widgets [message #496886 is a reply to message #496879] Wed, 11 November 2009 16:06 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6559
Registered: July 2009
Senior Member
You can enabled/disable a special context and the closest one wins when
it comes to keybindings.

tom

Steffen Harbich schrieb:
> Thank you for your replies!
>
> Quote:
>> You can switch contexts based upon the focus control using the focus
>> service.
>
>
> I'm not certain if i understand what the focus service does related to
> the problem: it provides the variable for focused control and the
> copy/cut/... command handlers use this variable to delegate to e.g.
> focused text widget's cut/copy/... methods?
>
> If so, there is another problem: any command can be associated with the
> enter-key as shortcut (using preferences), not only the one I contribute
> (that maybe delegate to my custom widget if focused control is
> considered). How do I ensure that other Eclipse commands do not disturb
> the cell editing?
>
> By the way, my company is using Eclipse 3.2 and therefore the focus
> service is not available.
>
> I think a widget should have the possibility to handle keys before any
> Eclipse shortcuts are handled. As you said, Paul, this is not possible.
> I will have to find another solution.
>
> Thanks again,
> Steffen
Re: Key bindings in custom widgets [message #496887 is a reply to message #496886] Wed, 11 November 2009 16:07 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6559
Registered: July 2009
Senior Member
Probably you can cancle the event in a keylistener?

Tom

Tom Schindl schrieb:
> You can enabled/disable a special context and the closest one wins when
> it comes to keybindings.
>
> tom
>
> Steffen Harbich schrieb:
>> Thank you for your replies!
>>
>> Quote:
>>> You can switch contexts based upon the focus control using the focus
>>> service.
>>
>> I'm not certain if i understand what the focus service does related to
>> the problem: it provides the variable for focused control and the
>> copy/cut/... command handlers use this variable to delegate to e.g.
>> focused text widget's cut/copy/... methods?
>>
>> If so, there is another problem: any command can be associated with the
>> enter-key as shortcut (using preferences), not only the one I contribute
>> (that maybe delegate to my custom widget if focused control is
>> considered). How do I ensure that other Eclipse commands do not disturb
>> the cell editing?
>>
>> By the way, my company is using Eclipse 3.2 and therefore the focus
>> service is not available.
>>
>> I think a widget should have the possibility to handle keys before any
>> Eclipse shortcuts are handled. As you said, Paul, this is not possible.
>> I will have to find another solution.
>>
>> Thanks again,
>> Steffen
icon5.gif  Re: Key bindings in custom widgets [message #498353 is a reply to message #496887] Mon, 16 November 2009 14:47 Go to previous message
Eclipse GuestFriend
Messages: 93
Registered: February 2013
Location: Vienna
Member
Cancle the event is not desired because the cell editor should open on ENTER.

Quote:
You can enabled/disable a special context and the closest one wins when
it comes to keybindings.


Did you mean the "activateContext(String contextId, Expression expression, boolean global)" method on a IContextService retrieved from the workbench which I can call on focus lost / gained events (I haven't tried out yet but focus event seems to be appropriate because I need it only when in the widget)? So, defining my own context (maybe by code) can overwrite the keybinding of ENTER to my command? Would that be a "nice" solution?

Thanks for reply,
Steffen
Previous Topic:Wrong location of ToolTip for some circumstances
Next Topic:applet in swt browser policy file affect
Goto Forum:
  


Current Time: Sun Jul 05 11:33:21 GMT 2020

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

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

Back to the top