Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Influence Focus as it was possible with setFocusTraversalPolicy and DefaultKeyboardFocusManager
Influence Focus as it was possible with setFocusTraversalPolicy and DefaultKeyboardFocusManager [message #1842723] Tue, 29 June 2021 16:04 Go to next message
Michael Frank is currently offline Michael FrankFriend
Messages: 13
Registered: February 2021
Junior Member
In AWT/Swing it was possible to call setFocusTraversalPolicy on your container to influence how Focus was handled in your application.
E.g. if I wanted a focuschange on ENTER and not only on TAB I could do something like
        HashSet<KeyStroke> forwardSet = new HashSet<KeyStroke>();
        forwardSet.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false));
        forwardSet.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0, false));
setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.unmodifiableSet(forwardSet));


Now for a Eclipse RCP Client I would need to do the same thing aka a way to globally enable focus change on ENTER throughout the application. So far I have found no way to do this so I'm asking, is there a way?
Re: Influence Focus as it was possible with setFocusTraversalPolicy and DefaultKeyboardFocusManager [message #1842776 is a reply to message #1842723] Thu, 01 July 2021 07:02 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
Eclipse is build on SWT, for SWT you can use a TraverseListener to a widget to change the traversal behavior, see https://stackoverflow.com/questions/52236928/how-to-set-traversal-order-by-enter-in-swt

Re: Influence Focus as it was possible with setFocusTraversalPolicy and DefaultKeyboardFocusManager [message #1842778 is a reply to message #1842776] Thu, 01 July 2021 07:53 Go to previous messageGo to next message
Michael Frank is currently offline Michael FrankFriend
Messages: 13
Registered: February 2021
Junior Member
Yes, I know that and I know that post but as I wrote I'm looking for a way to GLOBALLY do this. With the example you gave I would need to either roll my own components or add a TraverseListener to EVERY component I use in my parts, I'd like to avoid both.

Also the discussion on stackoverflow if anyone is interested https://stackoverflow.com/questions/68165078/focus-switch-using-enter-in-swt-eclipse-rcp-applikation

[Updated on: Thu, 01 July 2021 07:58]

Report message to a moderator

Re: Influence Focus as it was possible with setFocusTraversalPolicy and DefaultKeyboardFocusManager [message #1842798 is a reply to message #1842778] Thu, 01 July 2021 15:45 Go to previous messageGo to next message
Rolf Theunissen is currently offline Rolf TheunissenFriend
Messages: 260
Registered: April 2012
Senior Member
In that case, you will probably be interested in the Display.addFilter(...) call. Though that will register for any widget in the UI.

In Eclipse the PartRenderingEngine, that renders the full UI, also installs a filter, namely the KeyBindingDispatcher. This is used to do custom keybinding handling in Eclipse.
Re: Influence Focus as it was possible with setFocusTraversalPolicy and DefaultKeyboardFocusManager [message #1842891 is a reply to message #1842798] Mon, 05 July 2021 11:50 Go to previous messageGo to next message
Michael Frank is currently offline Michael FrankFriend
Messages: 13
Registered: February 2021
Junior Member
EDIT:
So I tried setting this up with a filter on Display. I used Display.getDefault() as well as injectiong the Display. This triggers the listener when I'm not in a (Popup)Dialog of some sorts. As soon as I'm in a Dialog created e.g. like this
		KorrekturDialog dialog = ContextInjectionFactory.make(KorrekturDialog.class, context);

my listener doesn't trigger anymore, instead the Dialogs Default Action gets triggered. This can be prevented by passing false for all buttons in createButton like
	createButton(parent, IDialogConstants.OK_ID, messages.button_speichern, false);


Also, any idea on how to trigger a focus change from a Listener? So far the only way I found is to specificially put the focus on a component using setFocus and forceFocus but as there is no "focusNextComponent" I'm not sure how to tackle this.

[Updated on: Mon, 05 July 2021 15:00]

Report message to a moderator

Re: Influence Focus as it was possible with setFocusTraversalPolicy and DefaultKeyboardFocusManager [message #1844559 is a reply to message #1842891] Thu, 16 September 2021 14:39 Go to previous message
Michael Frank is currently offline Michael FrankFriend
Messages: 13
Registered: February 2021
Junior Member
After messing around with this for a long time I have found NO viable working solution that wasn't breaking other things left and right, it just seem this is not possible in our RCP/SWT setup.
Previous Topic:Drag a part to a part stack in another monitor
Next Topic:how to use mybatis for database connection in e4 rcp ?
Goto Forum:
  


Current Time: Fri Apr 26 13:02:11 GMT 2024

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

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

Back to the top