Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Can't access right-click menu items of project that have sub-menus
Can't access right-click menu items of project that have sub-menus [message #531083] Mon, 03 May 2010 12:23 Go to next message
Jeff Johnston is currently offline Jeff Johnston
Messages: 173
Registered: July 2009
Senior Member
I am trying to access some items from the right-click menu of a project in the Project Explorer view of the C/C++ Perspective.

I am able to successfully access "Open Project" and "Close Project" for my GnuProject3 project as follows:

SWTBotTreeItem node = view.bot().tree().getTreeItem("GnuProject3");
node.setFocus();
node.select().contextMenu("Close Project").click();
node.setFocus();
node.select().contextMenu("Open Project").click();

Unfortunately, I can't seem to use the same method to access two right-click items which have submenus. I can't access "Make Targets" and I also tried "Build Configurations" just to see if I could access another item with sub-menu. Both attempts resulted in a widget not found exception.

node.select().contextMenu("Make Targets").menu("Build...").click();

I also tried just referencing "Make Targets" context menu without its submenu and that failed as well. I verified the string is correct by actually looking at the plugin.properties file which is used to set the menu item in the plugin.xml extension.

There is no spybot in 536 which might make this a little easier. I realize it was omitted from the build, but it would be nice to provide it somewhere (anywhere) for manual downloading even though it is not part of the official build.

Any ideas on why this isn't working?
Re: Can't access right-click menu items of project that have sub-menus [message #531302 is a reply to message #531083] Tue, 04 May 2010 09:35 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Jeff Johnston wrote:
>
> There is no spybot in 536 which might make this a little easier. I
> realize it was omitted from the build, but it would be nice to provide
> it somewhere (anywhere) for manual downloading even though it is not
> part of the official build.
>

The spybot got removed by mistake. It should be available in the next
build, as Ketan said.

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

*Because performance matters.*
Re: Can't access right-click menu items of project that have sub-menus [message #532985 is a reply to message #531083] Tue, 11 May 2010 14:34 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff Johnston
Messages: 173
Registered: July 2009
Senior Member
Some further debugging. I took the contextMenu() code and wrote it myself to give me all the context menu items, not just the one I was looking for.

		node = view.bot().tree().getTreeItem("GnuProject3");
		node.setFocus();
		node.select();
		final org.hamcrest.Matcher<MenuItem> matcher = allOf(widgetOfType(MenuItem.class));
		final ContextMenuFinder menuFinder = new ContextMenuFinder((Control)view.bot().tree().widget);
		new SWTBot().waitUntil(new DefaultCondition() {
			public String getFailureMessage() {
				return "Could not find context menu items"; //$NON-NLS-1$
			}

			public boolean test() throws Exception {
				return !menuFinder.findMenus(matcher).isEmpty();
			}
		});
		List<MenuItem> list = menuFinder.findMenus(matcher);


I then ran up to the line after the list was created and stopped to look at the items in the list.

It seems some of the right-click menu items are there and some are missing, but it isn't entirely items with sub-menus. For example, Profile as... was there and it has sub-menus which I also found later in the list..

Interestingly enough, "New" was missing. The first item found was "Go Into" which should be the 2nd item after "New". Also missing were "Build Configurations", "Make Targets", and "Index" which are all C/C++ specific items that have visibility dependent on project nature. The list had 110 entries, but a vast majority of them had a toString of "MenuItem {*Disposed*}". The remainder were shown as "MenuItem {*Wrong thread*}". Those Wrong Thread items were the ones that expanded to meaningful items with text. Not sure if the toString info is helpful, but I included it just in case.

Is it possible the list is created too fast and doesn't allow the logic to finish calculating some of the items that have a visibility rule??
Re: Can't access right-click menu items of project that have sub-menus [message #533006 is a reply to message #532985] Tue, 11 May 2010 15:32 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
On 5/11/10 11:34 AM, Jeff Johnston wrote:

> Interestingly enough, "New" was missing. The first item found was "Go
> Into" which should be the 2nd item after "New". Also missing were "Build
> Configurations", "Make Targets", and "Index" which are all C/C++
> specific items that have visibility dependent on project nature. The
> list had 110 entries, but a vast majority of them had a toString of
> "MenuItem {*Disposed*}". The remainder were shown as "MenuItem {*Wrong
> thread*}". Those Wrong Thread items were the ones that expanded to
> meaningful items with text. Not sure if the toString info is helpful,
> but I included it just in case.

Try printing them as you find them. The menu traversal is depth first,
the menu is opened, traversed, and closed and traversal moves to the
next menu.

Closing the menu may (*cough*) dispose items within it depending on the
platform and version of eclipse you're on(*cough*).

SWTBot currently traverses the entire menu, grabs what the matcher
matches and performs click on them, but it may be too late because the
menu is disposed.

It's ugly but that was the cheap way to build it at the time when it was
built :(

The /right way/ would be to use with some ActionMatcher that uses a
ClickRunnableAction along with a real matcher to perform an action
before the menu is closed:

menuFinder.perform(action, matcher){
// keep traversing
if (matcher.matches(menuItem)){
action.perform();
}
//
}

--
Ketan
http://ketan.padegaonkar.name | http://eclipse.org/swtbot
Re: Can't access right-click menu items of project that have sub-menus [message #533446 is a reply to message #533006] Thu, 13 May 2010 18:42 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff Johnston
Messages: 173
Registered: July 2009
Senior Member
The code I included was just to see what menu items SWTBot thought it knew about. You mention try printing out menus when I find them; are you implying there might be a way I can modify the code to make a temporary hack so as to find the particular menu I am looking for?

I am running Linux x86 with latest Eclipse 3.6M7 if that is of any help with regards to menu disposal.

Should I open an RFE to fix this for a future version of SWTBot or do you already have a bug/feature opened for this?
Re: Can't access right-click menu items of project that have sub-menus [message #650238 is a reply to message #531083] Sun, 23 January 2011 10:41 Go to previous messageGo to next message
Kevin Yu is currently offline Kevin Yu
Messages: 2
Registered: January 2011
Junior Member
I want to know how to resolve it.
tks
Re: Can't access right-click menu items of project that have sub-menus [message #656944 is a reply to message #533006] Tue, 01 March 2011 01:57 Go to previous messageGo to next message
Nyna  is currently offline Nyna
Messages: 10
Registered: October 2010
Junior Member
No Message Body
Re: Can't access right-click menu items of project that have sub-menus [message #656946 is a reply to message #533006] Tue, 01 March 2011 01:58 Go to previous messageGo to next message
Nyna  is currently offline Nyna
Messages: 10
Registered: October 2010
Junior Member
Hi Ketan,
Can you please elaborate on this,


The /right way/ would be to use with some ActionMatcher that uses a
ClickRunnableAction along with a real matcher to perform an action
before the menu is closed:

menuFinder.perform(action, matcher){
// keep traversing
if (matcher.matches(menuItem)){
action.perform();
}
//
}

Thanks ,
Nyna
Re: Can't access right-click menu items of project that have sub-menus [message #657124 is a reply to message #533446] Tue, 01 March 2011 11:30 Go to previous message
Mariot Chauvin is currently offline Mariot Chauvin
Messages: 174
Registered: July 2009
Senior Member
Le 14/05/2010 00:42, Jeff Johnston a écrit :
> The code I included was just to see what menu items SWTBot thought it
> knew about. You mention try printing out menus when I find them; are you
> implying there might be a way I can modify the code to make a temporary
> hack so as to find the particular menu I am looking for?
>
> I am running Linux x86 with latest Eclipse 3.6M7 if that is of any help
> with regards to menu disposal.
>
> Should I open an RFE to fix this for a future version of SWTBot or do
> you already have a bug/feature opened for this?
>

Hello,

I did not read all the discussion, but I have some code which works
pretty well for problem of menu with sub-menus:

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

Hope it may help you.

Regards,

Mariot
--
Mariot Chauvin @ Obeo

Blog : http://mariot-thoughts.blogspot.com
Twitter :http://twitter.com/mchv
Professional support : http://obeo.fr/pages/maintenance-and-support/
Previous Topic:MAC: Missing Display leads to black screenshots
Next Topic:Future of SWTBot
Goto Forum:
  


Current Time: Thu Aug 21 00:34:27 EDT 2014

Powered by FUDForum. Page generated in 0.01729 seconds