Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » SWTBot and context menus
SWTBot and context menus [message #38116] Mon, 01 June 2009 04:13 Go to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Hi All,

Recently we've seen a lot of issues regarding cascaded menus and context
menus getting disposed before being able to click on them. Almost every
user new to swtbot has faced this issue.

This unfortunately is because of the way menus are searched for by
swtbot and disposed of by eclipse.

Different versions of eclipse perform the dispose differently, and
unfortunately there's no one-size-fits-all approach to this problem.

Given this rather bad situation, what would the community prefer:

- Provide alternative API for finding nested menus. The existing api may
or may not work depending on what version of eclipse you are on, or if
you just decide to upgrade the eclipse version one fine day.

- Break existing API. This has the normal caveats. This should be simple
to fix using a global search and replace in the workspace. Also prevents
new users from being "locked down" into an API not guaranteed to work.

What would you prefer, do you have any ideas that'd make things work
without breaking compatibility ?

-- Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr
Re: SWTBot and context menus [message #41774 is a reply to message #38116] Fri, 03 July 2009 20:19 Go to previous messageGo to next message
Jens  übler is currently offline Jens üblerFriend
Messages: 17
Registered: July 2009
Junior Member
Ketan Padegaonkar schrieb:
> Hi All,
>
> Recently we've seen a lot of issues regarding cascaded menus and context
> menus getting disposed before being able to click on them. Almost every
> user new to swtbot has faced this issue.
>
> This unfortunately is because of the way menus are searched for by
> swtbot and disposed of by eclipse.
>
> Different versions of eclipse perform the dispose differently, and
> unfortunately there's no one-size-fits-all approach to this problem.
>
> Given this rather bad situation, what would the community prefer:
>
> - Provide alternative API for finding nested menus. The existing api may
> or may not work depending on what version of eclipse you are on, or if
> you just decide to upgrade the eclipse version one fine day.
>
> - Break existing API. This has the normal caveats. This should be simple
> to fix using a global search and replace in the workspace. Also prevents
> new users from being "locked down" into an API not guaranteed to work.
>
> What would you prefer, do you have any ideas that'd make things work
> without breaking compatibility ?
>
> -- Ketan
> http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr

My thoughts to this: Although SWTBot has now version 2.0 it is obvious
it is currently maturing as users start to use it. Therefor I think it's
favourable to break the API at this point in time than rather stick to a
crumpy workaround implementation.

Jens
Re: SWTBot and context menus [message #41927 is a reply to message #38116] Tue, 07 July 2009 00:27 Go to previous messageGo to next message
Derek  is currently offline Derek Friend
Messages: 30
Registered: July 2009
Member
Ketan Padegaonkar wrote:

> Given this rather bad situation, what would the community prefer:

> - Provide alternative API for finding nested menus. The existing api may
> or may not work depending on what version of eclipse you are on, or if
> you just decide to upgrade the eclipse version one fine day.

> - Break existing API. This has the normal caveats. This should be simple
> to fix using a global search and replace in the workspace. Also prevents
> new users from being "locked down" into an API not guaranteed to work.

> What would you prefer, do you have any ideas that'd make things work
> without breaking compatibility ?

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


Break existing API. If the other way will have dependency issues on the
Eclipse version you're on, I would rather take the "Break existing API"
route.

~Derek
Re: SWTBot and context menus [message #44550 is a reply to message #38116] Tue, 21 July 2009 20:20 Go to previous messageGo to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
I don't know if this is related to the redesign effort, but is there a
reason why there is no wrapper for a Menu? SWTBotMenu wraps MenuItem, not
Menu.

Especially with context menus, it is necessary to test certain things about
the menu, like the number of menu items it contains. Currently, my approach
is to get a SWTBotMenu, then do something like:

assertThat(menu.widget.getParent().getItemCount(), is(i));

But another thing I would like to be able to test is that no context menu
shows up under certain conditions. In this case, so the above approach
doesn't work. A Menu is a real widget, so why not have a wrapper for it?
It's trivial to do (some code below), but maybe I'm missing some reasons why
not?

Sample code:

Matcher<Tree> matcher = widgetOfType(Tree.class);
final EnhancedSWTBotTree tree = new EnhancedSWTBotTree((Tree)
bot.widget(matcher), matcher);
SWTBotMenuMenu menu = tree.contextMenu(0, 1); // select items 0 and 1
assertThat(menu.getItemCount(), is(0));

Classes used:

public class EnhancedSWTBotTree extends SWTBotTree {

// constructors omitted...

public SWTBotMenuMenu contextMenu(int... indices)
throws WidgetNotFoundException {
select(indices);
notify(SWT.MenuDetect);
return new SWTBotMenuMenu(syncExec(new Result<Menu>() {
public Menu run() {
return widget.getMenu();
}
}));
}
}

public class SWTBotMenuMenu extends AbstractSWTBot<Menu> {

// constructors omitted...

public int getItemCount() {
return syncExec(new IntResult() {
public Integer run() {
return widget.getItemCount();
}
});
}
}
Re: SWTBot and context menus [message #44581 is a reply to message #44550] Tue, 21 July 2009 20:59 Go to previous message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
> But another thing I would like to be able to test is that no context menu
> shows up under certain conditions.

A much easier way is this:

SWTBotTree tree = bot.tree();
tree.select(0, 1)
assertThat(getMenuItems(tree), is(0));

private SWTBotMenu[] getMenuItems(AbstractSWTBot<? extends Control> bot)
{
List<MenuItem> menuItems = new
ContextMenuFinder(bot.widget).findMenus(anything());
SWTBotMenu[] menus = new SWTBotMenu[menuItems.size()];
int i = 0;
for (MenuItem menuItem : menuItems) {
menus[i++] = new SWTBotMenu(menuItem);
}
return menus;
}

So maybe a wrapper for Menu is not that useful. But it would be useful to
have the above getMenuItems part of AbstractSWTBot!
Previous Topic:Testing RCP Applications
Next Topic:select a tree node and its child
Goto Forum:
  


Current Time: Thu Apr 25 05:17:08 GMT 2024

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

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

Back to the top