|
|
|
Re: SWTBotText.setText(String) not notifying listeners [message #481380 is a reply to message #481371] |
Thu, 20 August 2009 17:10 |
Jay Norwood Messages: 155 Registered: July 2009 |
Senior Member |
|
|
Pascal Gelinas wrote:
> I think that method does what it is intended to do. If you want to
> notify listeners, I would suggest using the typeText(String) method.
> This one sends low-level event which make the text appear as if someone
> was typing it.
I tried substituting typeText for setText in my example, as below, and
that doesn't call the SelectionListener either, and doesn't even enter the
text.
//bot.text(0).setText("text0val");
bot.text(0).setFocus();
bot.text(0).selectAll();
bot.text(0).typeText("text0val");
I don't know which Text boxes have listeners, so setText as it is would be
practically useless. I think it is reasonable to expect setText to
provide an SWT.DefaultSelection notification, since this is exactly what
you get when you type text in a Text box, followed by ENTER. It is
apparent that typeText requires something in addition to what I used above
in order to get the text displayed in the text box, equivalent to the
single commented out line, so it seems to be too much entry for a general
solution. setText works just fine, except for the missing notification.
Maybe we should just add a setTextWithNotification(String) if there is
some reason for the current non-notified version.
|
|
|
Re: SWTBotText.setText(String) not notifying listeners [message #481383 is a reply to message #481380] |
Thu, 20 August 2009 17:37 |
Pascal G Messages: 157 Registered: July 2009 |
Senior Member |
|
|
Jay Norwood wrote:
> I think it is reasonable to expect setText to
> provide an SWT.DefaultSelection notification, since this is exactly what
> you get when you type text in a Text box, followed by ENTER.
SWT.DefaultSelection is sent only if the ENTER key is used in the text
box (and I'm not sure of all the mechanics behind that, maybe
SWT.Selection too). I do know that when you type a text, it is Events
such as SWT.KeyDown and SWT.KeyUp that are sent, not
SWT.DefaultSelection. All this processing is done internally by SWT and
if you use Display.post() to send your events, SWT does it for you. The
typeText(String) method does exactly that, because it sends low-level
events. If it's not working for you, review your configuration: you need
a keyboard layout (SWTBotPreferences#KEYBOARD_LAYOUT) of EN_US and a
native keyboard layout of US standard or it won't work (see Bug 280562).
Moreover, you don't want to send the SWT.DefaultSelection every time you
set the text of a text box, it just doesn't make sense because you don't
always hit enter. If you want that event to be sent, by using setText
and without the hassle of configuring the keyboard strategy (still need
SWTBotPreferences#KEYBOARD_LAYOUT to be EN_US though), use
SWTBotText#pressShortcut() methods with a carriage return or line feed
(depends on your system). For example:
bot.text().pressShortcut(Keystrokes.CR)
or
bot.text().pressShortcut(Keystrokes.LF)
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/
*Because performance matters.*
|
|
|
|
Re: SWTBotText.setText(String) not notifying listeners [message #481398 is a reply to message #481391] |
Thu, 20 August 2009 19:18 |
Pascal G Messages: 157 Registered: July 2009 |
Senior Member |
|
|
Jay Norwood wrote:
> If the Text widgets have a SelectionListener, then it would work, and if
> they don't have a SelectionListener, then no harm done, so I don't see
> what is the big danger of providing the notification.
Sometimes the SelectionListener will be notified for no real reason,
since you don't always want to hit enter, whatever the reason might be.
Hitting enter after setting the text might do something in the UI and by
always sending the SWT.DefaultSelection you can't test what happens if
the user doesn't hit enter.
> I already suggested just adding it to a new
> setTextWithNotification(String) if there is some problem with making it
> the default for setText(String).
>
On that level, it is more a personal taste then anything else. I think
setting some text in a text box and the SWT.DefaultSelection are two
separate concept and should not be mixed together, and so such method
should not exist. But I am not a commiter on this project and Ketan
might feel otherwise. I also believe that
text.setTextWithNotification("MyText");
is less clear on what it does then
text.setText("MyText").pressShortcut(Keystrokes.CR);
But, as I said, these are personal views on design and ease of use.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/
*Because performance matters.*
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04198 seconds