Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » SWTBotText.setText(String) not notifying listeners
SWTBotText.setText(String) not notifying listeners [message #481369] Thu, 20 August 2009 16:20 Go to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Listeners on a Text widget are not being notified on
SWTBotText.setText(String).

I'm going to check in a bug and swtbot test case. The fix is below for
SWTBotText.setText(String). There may be listeners for other Text widget
events, but below just handles the general case



public void setText(final String text) {
assertEnabled();
syncExec(new VoidResult() {
public void run() {
widget.setText(text);
}
});
notify(SWT.DefaultSelection);

}
Re: SWTBotText.setText(String) not notifying listeners [message #481371 is a reply to message #481369] Thu, 20 August 2009 16:35 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Jay Norwood wrote:
> Listeners on a Text widget are not being notified on
> SWTBotText.setText(String).
>
> I'm going to check in a bug and swtbot test case. The fix is below for
> SWTBotText.setText(String). There may be listeners for other Text
> widget events, but below just handles the general case
>
>
>
> public void setText(final String text) {
> assertEnabled();
> syncExec(new VoidResult() {
> public void run() {
> widget.setText(text);
> }
> });
> notify(SWT.DefaultSelection);
>
> }
>
>

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. However, you might have some problem if using a fancy
keyboard layout. For it to work, I would suggest using a standard US
keyboard and setting SWTBotPreferences#KEYBOARD_STRATEGY to
"org.eclipse.swtbot.swt.finder.keyboard.SWTKeyboardStrategy".

Hope that helps.

--
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 #481372 is a reply to message #481369] Thu, 20 August 2009 16:38 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I checked in a proposed fix and test case.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=287210
Re: SWTBotText.setText(String) not notifying listeners [message #481380 is a reply to message #481371] Thu, 20 August 2009 17:10 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
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 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
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 #481391 is a reply to message #481383] Thu, 20 August 2009 18:30 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Pascal Gelinas wrote:
> 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 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.

I already suggested just adding it to a new
setTextWithNotification(String) if there is some problem with making it
the default for setText(String).
Re: SWTBotText.setText(String) not notifying listeners [message #481398 is a reply to message #481391] Thu, 20 August 2009 19:18 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
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.*
Re: SWTBotText.setText(String) not notifying listeners [message #481420 is a reply to message #481398] Thu, 20 August 2009 22:06 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Pascal Gelinas wrote:


> text.setText("MyText").pressShortcut(Keystrokes.CR);

> But, as I said, these are personal views on design and ease of use.

I'd prefer the less verbose setText("MyText"), handle the notification.
Maybe something equally short like pokeText("MyText") could be used for a
non-notifying version.

The pressShortcut chain thing would be painful, but something like
enter() would be ok.
Re: SWTBotText.setText(String) not notifying listeners [message #481442 is a reply to message #481369] Fri, 21 August 2009 03:31 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
This is by design. This api is useful for cases where no listeners are
hooked in into the text box, and validation happens when you click on a
next or finish button for e.g.

If you want to send notifications on every keystroke use #typeText
instead. This is useful when validations need to happen on every
keystroke -- like a textbox in a calculator for e.g.

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr

On 20/8/09 21:50, Jay Norwood wrote:
> Listeners on a Text widget are not being notified on
> SWTBotText.setText(String).
>
> I'm going to check in a bug and swtbot test case. The fix is below for
> SWTBotText.setText(String). There may be listeners for other Text widget
> events, but below just handles the general case
>
>
>
> public void setText(final String text) {
> assertEnabled();
> syncExec(new VoidResult() {
> public void run() {
> widget.setText(text);
> }
> });
> notify(SWT.DefaultSelection);
>
> }
>
>
Re: SWTBotText.setText(String) not notifying listeners [message #481571 is a reply to message #481442] Fri, 21 August 2009 15:26 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
Ketan Padegaonkar wrote:

> This is by design. This api is useful for cases where no listeners are
> hooked in into the text box, and validation happens when you click on a
> next or finish button for e.g.


If there are no listeners, no notifications would be sent, and if there
are listeners a notification would be sent, so I don't see the advantage
of not looking to see if there are listeners, and sending the notification
if there are listeners.


> If you want to send notifications on every keystroke use #typeText
> instead. This is useful when validations need to happen on every
> keystroke -- like a textbox in a calculator for e.g.


I want to test that the application handles the single notification that
occurs whenever the user presses ENTER in a Text widget. Can we just
have an enter() to chain onto setText(String).enter() which sends that
notification?
Re: SWTBotText.setText(String) not notifying listeners [message #481943 is a reply to message #481372] Mon, 24 August 2009 19:17 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
After the discussion, I modified the proposed changes in the attachment to
bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=287210


The proposal is to use:

enter(String), equivalent to setText(String).enter()

either of which will do the notification.


I also added chaining of several of the SWTBotText functions, which seems
appropriate, so you can do:

bot.text("Box1").selectAll().typeText("aaa").pressShortcut(whatever).typeText( "moreText").enter();

or

bot.text("Box1").setText("aaa").enter();

or

bot.text("Box1").enter("aaa");
Re: SWTBotText.setText(String) not notifying listeners [message #482206 is a reply to message #481442] Tue, 25 August 2009 17:00 Go to previous message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
I ran the test case attached to the bug report to compare the time of the
proposed enter(text) vs the use of typeText(text) in a loop of executions
of the statements.

The total time for a hundred loops of typeText(text) version was 5.8
seconds.
The total time for a thousand loops of the enter(text) version was 0.984
sec

I think that is sufficient justification for the availability of the
proposed enter(text) method.
Previous Topic:Widget not found exception
Next Topic:drag-and-drop operations with SWTBot?
Goto Forum:
  


Current Time: Fri Mar 29 08:54:23 GMT 2024

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

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

Back to the top