SWTBot and context menus [message #38116] |
Mon, 01 June 2009 00:13  |
Eclipse User |
|
|
|
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 #44550 is a reply to message #38116] |
Tue, 21 July 2009 16:20   |
Eclipse User |
|
|
|
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 16:59  |
Eclipse User |
|
|
|
> 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!
|
|
|
Powered by
FUDForum. Page generated in 0.06754 seconds