Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 21:11 Go to next message
Alex Cozzi is currently offline Alex CozziFriend
Messages: 27
Registered: July 2009
Junior Member
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 21:44 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
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 22:43 Go to previous messageGo to next message
Alex Cozzi is currently offline Alex CozziFriend
Messages: 27
Registered: July 2009
Junior Member
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 05: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 06:55 Go to previous message
Alex Cozzi is currently offline Alex CozziFriend
Messages: 27
Registered: July 2009
Junior Member
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 Dec 26 15:12:13 GMT 2024

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

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

Back to the top