Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » How to set the focus on a specific field?
How to set the focus on a specific field? [message #932602] Thu, 04 October 2012 08:59 Go to next message
A. Del. is currently offline A. Del.Friend
Messages: 6
Registered: July 2009
Junior Member
Is there a way to set the focus on a specific field?
For instance, when a validation returns an error, I would like to set the focus on the field the user has to correct, so the user could start typing right away.
I use the SWT UI rendering technology

Thanks for your help.

Re: How to set the focus on a specific field? [message #932648 is a reply to message #932602] Thu, 04 October 2012 09:43 Go to previous messageGo to next message
Stephan Merkli is currently offline Stephan MerkliFriend
Messages: 40
Registered: April 2012
Member
There is a method requestFocus on IFormField which should be what you need.

Regards
Stephan

[Updated on: Thu, 04 October 2012 09:44]

Report message to a moderator

Re: How to set the focus on a specific field? [message #939128 is a reply to message #932602] Wed, 10 October 2012 13:00 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
A. Del. wrote on Thu, 04 October 2012 04:59
Is there a way to set the focus on a specific field?
For instance, when a validation returns an error, I would like to set the focus on the field the user has to correct, so the user could start typing right away.


Check out the method AbstractForm.validateForm(). There is already code that displays an error message when a field is invalid and sets the focus to the first field with a validation error. Use the various execValidate... methods to throw a VetoException or use setErrorStatus() to set a processing status. Maybe this mechanism could help you in your application.

Beat
Re: How to set the focus on a specific field? [message #947588 is a reply to message #932602] Wed, 17 October 2012 08:13 Go to previous messageGo to next message
A. Del. is currently offline A. Del.Friend
Messages: 6
Registered: July 2009
Junior Member
Thanks for your input.

I tried to use the method requestFocus() on IFormField. Sometimes it works and somtimes it doesn't.
I also tried the mechanism used in the AbstractForm.validateForm() method. It uses an IValidateContentDescriptor
and in the method activateProblemLocation() it basically calls field.requestFocus().
Here again. Sometimes the focus is set and sometimes the focus is not set.

Does anybody have an idea why the method requestFocus() is not always succsessful?

Re: How to set the focus on a specific field? [message #947640 is a reply to message #947588] Wed, 17 October 2012 09:19 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
A. Del. wrote on Wed, 17 October 2012 04:13
I tried to use the method requestFocus() on IFormField. Sometimes it works and somtimes it doesn't.


Like the name states, the method requestFocus() does not _set_ the focus. It's a _request_ to the UI layer to set the focus. This request may be denied or ignored by the UI layer for several reasons. The field has to be ready and visible on screen. Or, for example, while a message box is shown, the focus cannot be set to a field on a dialog in the background.

The Scout UI layer delegates the request to the underlying UI field (e.g. a JTextField in Swing). Note that this does still not guarantee that the focus is now on the desired field, because the UI itself may deny the request for some reason.

If the behaviour is "random", then you see to have run into a race condition (sometimes the UI is ready, sometimes it's not). Try to synchronize your focus request, e.g. by wrapping it into a ClientSyncJob.

Regards,
Beat
Re: How to set the focus on a specific field? [message #948044 is a reply to message #947640] Wed, 17 October 2012 17:54 Go to previous messageGo to next message
A. Del. is currently offline A. Del.Friend
Messages: 6
Registered: July 2009
Junior Member
Thanks for your reply, Beat

Sorry I explained it wrong. I meant that the method requestFocus() works on some fields and doesn't on other fields.

In my code the method requestFocus() doesn't work on fields of type AbstractIntegerField.
But it works for AbstractStringField or also AbstractSmartField (I use the swt ui.)
Could this be a bug or am I missing something?

Thanx
Re: How to set the focus on a specific field? [message #948057 is a reply to message #948044] Wed, 17 October 2012 18:12 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
A. Del. wrote on Wed, 17 October 2012 13:54
In my code the method requestFocus() doesn't work on fields of type AbstractIntegerField.
But it works for AbstractStringField or also AbstractSmartField (I use the swt ui.)
Could this be a bug or am I missing something?


This is a bug, indeed! I could reproduce the problem exactly as you describe it.

A short analysis showed that it is a SWT only problem. While string fields are rendered als "StyledTextEx" components, integer fields are rendered as "TextEx" components. The class TextEx overrides the method requestFocus() like this:

  @Override
  public boolean setFocus() {
    return getEditable();
  }


This does not seem correct to me, so I would encourage you to file a bug (https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Scout).

Thank you very much for reporting the issue!

Regards,
Beat
Re: How to set the focus on a specific field? [message #948571 is a reply to message #948057] Thu, 18 October 2012 06:38 Go to previous message
A. Del. is currently offline A. Del.Friend
Messages: 6
Registered: July 2009
Junior Member
Thank you for your feedback.
I reported the bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=392288
Previous Topic:A page with master detail
Next Topic:jdbc connection bundle SqlServer Jtds Drive
Goto Forum:
  


Current Time: Wed Apr 24 18:52:32 GMT 2024

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

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

Back to the top