Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Why doesn't this EditorCloses condition class work?
Why doesn't this EditorCloses condition class work? [message #507576] Wed, 13 January 2010 21:24 Go to next message
Robert M. Fuhrer is currently offline Robert M. FuhrerFriend
Messages: 294
Registered: July 2009
Senior Member
Hi there,

One of my first little exercises in SWTBot was writing an ICondition
class that waits until a specified editor is closed. I tried the
following, but it doesn't work (always times out and claims the
editor wasn't closed, even though the editor has been closed):

class EditorCloses extends DefaultCondition {
private final SWTBotEditor fEditor;

private EditorCloses(SWTBotEditor editor) {
this.fEditor = editor;
}

public String getFailureMessage() {
return "The editor " + fEditor + " did not close.";
}

public boolean test() throws Exception {
return UIThreadRunnable.syncExec(new BoolResult() {
public Boolean run() {
return fEditor.getWidget() == null || fEditor.getWidget().isDisposed();
}
});
}
}

Any idea why this doesn't work? Looks innocent enough... :-)

[FWIW, this is basically a tweaked version of ShellCloses.]

--
Cheers,
-- Bob

--------------------------------
Robert M. Fuhrer
Research Staff Member
Programming Technologies Dept.
IBM T.J. Watson Research Center

IDE Meta-tooling Platform Project Lead (http://www.eclipse.org/imp)
X10: Productive High-Performance Parallel Programming (http://x10.sf.net)
Re: Why doesn't this EditorCloses condition class work? [message #507583 is a reply to message #507576] Wed, 13 January 2010 22:05 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Robert M. Fuhrer wrote:
> Hi there,
>
> One of my first little exercises in SWTBot was writing an ICondition
> class that waits until a specified editor is closed. I tried the
> following, but it doesn't work (always times out and claims the
> editor wasn't closed, even though the editor has been closed):
>
> class EditorCloses extends DefaultCondition {
> private final SWTBotEditor fEditor;
>
> private EditorCloses(SWTBotEditor editor) {
> this.fEditor = editor;
> }
>
> public String getFailureMessage() {
> return "The editor " + fEditor + " did not close.";
> }
>
> public boolean test() throws Exception {
> return UIThreadRunnable.syncExec(new BoolResult() {
> public Boolean run() {
> return fEditor.getWidget() == null ||
> fEditor.getWidget().isDisposed();
> }
> });
> }
> }
>
> Any idea why this doesn't work? Looks innocent enough... :-)
>
> [FWIW, this is basically a tweaked version of ShellCloses.]
>

You basically don't need a Condition for that, since
SWTBotEditor#close() is a blocking call. Also, I don't see the
getWidget() method for SWTBotEditor... what is the version you are using?

--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Why doesn't this EditorCloses condition class work? [message #507585 is a reply to message #507583] Wed, 13 January 2010 22:29 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Pascal Gelinas wrote:
> Also, I don't see the getWidget() method for SWTBotEditor... what is the version you are using?

Seems like I'm searching with my eyes closed... I found it, and found
the answer at the same time: getWidget() calls the show() method, which
re-opens the editor. You could log a bug against this if you want.

I was planning to do some fixes in SWTBot tomorrow, might do yours ;)
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Why doesn't this EditorCloses condition class work? [message #507605 is a reply to message #507576] Thu, 14 January 2010 03:16 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
I'd not recommend a test based on the editor.getWidget(). It will show
the editor if it's not already closed.

You may try bot.editors() and see if you have the editor with the same
filename open as the one you're looking for.

-- Ketan

On 1/13/10 1:24 PM, Robert M. Fuhrer wrote:
> Hi there,
>
> One of my first little exercises in SWTBot was writing an ICondition
> class that waits until a specified editor is closed. I tried the
> following, but it doesn't work (always times out and claims the
> editor wasn't closed, even though the editor has been closed):
>
> class EditorCloses extends DefaultCondition {
> private final SWTBotEditor fEditor;
>
> private EditorCloses(SWTBotEditor editor) {
> this.fEditor = editor;
> }
>
> public String getFailureMessage() {
> return "The editor " + fEditor + " did not close.";
> }
>
> public boolean test() throws Exception {
> return UIThreadRunnable.syncExec(new BoolResult() {
> public Boolean run() {
> return fEditor.getWidget() == null || fEditor.getWidget().isDisposed();
> }
> });
> }
> }
>
> Any idea why this doesn't work? Looks innocent enough... :-)
>
> [FWIW, this is basically a tweaked version of ShellCloses.]
>
Re: Why doesn't this EditorCloses condition class work? [message #507867 is a reply to message #507585] Thu, 14 January 2010 22:27 Go to previous messageGo to next message
Robert M. Fuhrer is currently offline Robert M. FuhrerFriend
Messages: 294
Registered: July 2009
Senior Member
Pascal Gelinas wrote:
> Pascal Gelinas wrote:
>> Also, I don't see the getWidget() method for SWTBotEditor... what is
>> the version you are using?
>
> Seems like I'm searching with my eyes closed... I found it, and found
> the answer at the same time: getWidget() calls the show() method, which
> re-opens the editor. You could log a bug against this if you want.
>
> I was planning to do some fixes in SWTBot tomorrow, might do yours ;)

Ah, I didn't realize getWidget() was anything more than a field accessor.
Hence my surprise when I saw the field was null, yet 'getWidget() == null'
didn't evaluate to 'true'.

I can't say whether I think having getWidget() call show() is a good idea,
being a complete SWTBot newbie - I'll bow to your greater wisdom. :-)

--
Cheers,
-- Bob

--------------------------------
Robert M. Fuhrer
Research Staff Member
Programming Technologies Dept.
IBM T.J. Watson Research Center

IDE Meta-tooling Platform Project Lead (http://www.eclipse.org/imp)
X10: Productive High-Performance Parallel Programming (http://x10.sf.net)
Re: Why doesn't this EditorCloses condition class work? [message #507868 is a reply to message #507605] Thu, 14 January 2010 22:29 Go to previous messageGo to next message
Robert M. Fuhrer is currently offline Robert M. FuhrerFriend
Messages: 294
Registered: July 2009
Senior Member
Using editors() seems a bit indirect, given that I already have the
appropriate SWTBotEditor in hand.

Does it make sense to add an isDisposed() method instead?

Ketan Padegaonkar wrote:
> I'd not recommend a test based on the editor.getWidget(). It will show
> the editor if it's not already closed.
>
> You may try bot.editors() and see if you have the editor with the same
> filename open as the one you're looking for.
>
> -- Ketan
>
> On 1/13/10 1:24 PM, Robert M. Fuhrer wrote:
>> Hi there,
>>
>> One of my first little exercises in SWTBot was writing an ICondition
>> class that waits until a specified editor is closed. I tried the
>> following, but it doesn't work (always times out and claims the
>> editor wasn't closed, even though the editor has been closed):
>>
>> class EditorCloses extends DefaultCondition {
>> private final SWTBotEditor fEditor;
>>
>> private EditorCloses(SWTBotEditor editor) {
>> this.fEditor = editor;
>> }
>>
>> public String getFailureMessage() {
>> return "The editor " + fEditor + " did not close.";
>> }
>>
>> public boolean test() throws Exception {
>> return UIThreadRunnable.syncExec(new BoolResult() {
>> public Boolean run() {
>> return fEditor.getWidget() == null || fEditor.getWidget().isDisposed();
>> }
>> });
>> }
>> }
>>
>> Any idea why this doesn't work? Looks innocent enough... :-)
>>
>> [FWIW, this is basically a tweaked version of ShellCloses.]


--
Cheers,
-- Bob

--------------------------------
Robert M. Fuhrer
Research Staff Member
Programming Technologies Dept.
IBM T.J. Watson Research Center

IDE Meta-tooling Platform Project Lead (http://www.eclipse.org/imp)
X10: Productive High-Performance Parallel Programming (http://x10.sf.net)
Re: Why doesn't this EditorCloses condition class work? [message #507884 is a reply to message #507868] Fri, 15 January 2010 00:38 Go to previous message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
On 1/14/10 2:29 PM, Robert M. Fuhrer wrote:
> Using editors() seems a bit indirect, given that I already have the
> appropriate SWTBotEditor in hand.
>
> Does it make sense to add an isDisposed() method instead?

That's what I'd prefer as well. But I'm unable to find any eclipse api
that tells me if an editor is closed or not.

-- Ketan
Previous Topic:How to get the TextHover control of bot.activeEditor().getSelection() in SWTBot
Next Topic:Drag & drop
Goto Forum:
  


Current Time: Fri Mar 29 13:46:35 GMT 2024

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

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

Back to the top