Skip to main content



      Home
Home » Eclipse Projects » GEF » Who is eating my TAB key event?
Who is eating my TAB key event? [message #110428] Fri, 02 January 2004 16:11 Go to next message
Eclipse UserFriend
I am trying to detect when the user presses the TAB key by extending
org.eclipse.jface.viewers.TextCellEditor. But somewhere in the keyevent
handling chain the tab key gets eaten and my editor does not see it.
I am writing a GEF application, and this code is used in the same way as
the code that changes the labels's text in the logic editor example.


protected void keyReleaseOccured(KeyEvent keyEvent) {
System.out.println("keyEvent: " + keyEvent);
ctrlReturn = false;
tab = false;
shiftTab = false;
if (keyEvent.character == '\u001b') { // Escape
// character
fireCancelEditor();
} else if (keyEvent.character == '\r') { // Return key
if ((keyEvent.stateMask & SWT.CTRL) != 0) {
//System.out.println("CTRL RETURN pressed");
ctrlReturn = true;
}
fireApplyEditorValue();
deactivate();
} else if (keyEvent.character == '\t') { // Tab key
System.out.println("TAB pressed");
tab = true;

}
}
Re: Who is eating my TAB key event? [message #110440 is a reply to message #110428] Fri, 02 January 2004 16:44 Go to previous messageGo to next message
Eclipse UserFriend
What do you want to do when TAB is pressed?

What do you see happening when TAB is pressed? TAB is usually used for
traversal and hence might be sending the focus to the toolbar or whatever
the next focusable component is.

Also, this question is better suited for the eclipse.platform newsgroup. Do
a search on there and see if you find anything.

"Alex Cozzi" <cozzi@almaden.ibm.com> wrote in message
news:bt4mnq$qdp$1@eclipse.org...
> I am trying to detect when the user presses the TAB key by extending
> org.eclipse.jface.viewers.TextCellEditor. But somewhere in the keyevent
> handling chain the tab key gets eaten and my editor does not see it.
> I am writing a GEF application, and this code is used in the same way as
> the code that changes the labels's text in the logic editor example.
>
>
> protected void keyReleaseOccured(KeyEvent keyEvent) {
> System.out.println("keyEvent: " + keyEvent);
> ctrlReturn = false;
> tab = false;
> shiftTab = false;
> if (keyEvent.character == '\u001b') { // Escape
> // character
> fireCancelEditor();
> } else if (keyEvent.character == '\r') { // Return key
> if ((keyEvent.stateMask & SWT.CTRL) != 0) {
> //System.out.println("CTRL RETURN pressed");
> ctrlReturn = true;
> }
> fireApplyEditorValue();
> deactivate();
> } else if (keyEvent.character == '\t') { // Tab key
> System.out.println("TAB pressed");
> tab = true;
>
> }
> }
Re: Who is eating my TAB key event? [message #110452 is a reply to message #110440] Fri, 02 January 2004 17:43 Go to previous messageGo to next message
Eclipse UserFriend
Pratik Shah wrote:
> What do you want to do when TAB is pressed?
>
> What do you see happening when TAB is pressed? TAB is usually used for
> traversal and hence might be sending the focus to the toolbar or whatever
> the next focusable component is.
>
> Also, this question is better suited for the eclipse.platform newsgroup. Do
> a search on there and see if you find anything.
>

I am writing a kind of outline word-processor, and when i press tab I
want to indent the current item. What I observe is that the edit field
loses focus and closes.

I was wondering how could I block traversal or at least intercept it.
Thanks for the answer.
Alex
Re: Who is eating my TAB key event? [message #110481 is a reply to message #110428] Sat, 03 January 2004 00:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

The TAB key does not generate a key pressed if it results in focus
traversal. You need to prevent the focus traversal, in which case you will
get the TAB event. There is probably an SWT snippet showing how to do this.
See TraverseListener. You need to look for specific traversal events, and
set the doit = false.

"Alex Cozzi" <cozzi@almaden.ibm.com> wrote in message
news:bt4mnq$qdp$1@eclipse.org...
> I am trying to detect when the user presses the TAB key by extending
> org.eclipse.jface.viewers.TextCellEditor. But somewhere in the keyevent
> handling chain the tab key gets eaten and my editor does not see it.
> I am writing a GEF application, and this code is used in the same way as
> the code that changes the labels's text in the logic editor example.
>
>
> protected void keyReleaseOccured(KeyEvent keyEvent) {
> System.out.println("keyEvent: " + keyEvent);
> ctrlReturn = false;
> tab = false;
> shiftTab = false;
> if (keyEvent.character == '\u001b') { // Escape
> // character
> fireCancelEditor();
> } else if (keyEvent.character == '\r') { // Return key
> if ((keyEvent.stateMask & SWT.CTRL) != 0) {
> //System.out.println("CTRL RETURN pressed");
> ctrlReturn = true;
> }
> fireApplyEditorValue();
> deactivate();
> } else if (keyEvent.character == '\t') { // Tab key
> System.out.println("TAB pressed");
> tab = true;
>
> }
> }
Re: Who is eating my TAB key event? [message #110512 is a reply to message #110481] Mon, 05 January 2004 01:55 Go to previous message
Eclipse UserFriend
Randy Hudson wrote:
> The TAB key does not generate a key pressed if it results in focus
> traversal. You need to prevent the focus traversal, in which case you will
> get the TAB event. There is probably an SWT snippet showing how to do this.
> See TraverseListener. You need to look for specific traversal events, and
> set the doit = false.
>
> "Alex Cozzi" <cozzi@almaden.ibm.com> wrote in message
> news:bt4mnq$qdp$1@eclipse.org...
>
>>I am trying to detect when the user presses the TAB key by extending
>>org.eclipse.jface.viewers.TextCellEditor. But somewhere in the keyevent
>>handling chain the tab key gets eaten and my editor does not see it.
>>I am writing a GEF application, and this code is used in the same way as
>>the code that changes the labels's text in the logic editor example.
>>
>>

Thanks! that pointed me inthe right direction. This is the code that
solves the problem:

public void create(Composite parent) {
super.create(parent);
// disable traversing so that we can see the tab in the keyRelease
getControl().addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail ==
SWT.TRAVERSE_TAB_PREVIOUS) {
e.doit = false;
}
}
});
}
Previous Topic:How to scale font in only one direction?
Next Topic:double click events
Goto Forum:
  


Current Time: Thu May 08 07:27:08 EDT 2025

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

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

Back to the top