Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » looking for suggesting to locate/interact with the context menu of a source editor
looking for suggesting to locate/interact with the context menu of a source editor [message #22843] Wed, 18 February 2009 15:47 Go to next message
Joe Luebker is currently offline Joe Luebker
Messages: 36
Registered: July 2009
Member
Hello,

I am trying to interact with a context menu of a vertical ruler in a
source editor in Eclipse. I have discovered one way to open the context
menu but haven't yet successfully been able to interact with it. Below
is the snippet of code that actually opens the context menu.

SWTBotEclipseEditor actMainEditor = bot.editor("act_main.c");
actMainEditor.setFocus();
actMainEditor.navigateTo(64, 0);

// Open the context menu of the vertical ruler in the editor
actMainEditor.notifyKeyboardEvent(SWT.CTRL, (char)0, SWT.F10);


I have tried interacting with the focused widget which didn't work and
haven't been able to find the menu using SWTBot yet. Any suggestions?

Thanks,
Joe
Re: looking for suggesting to locate/interact with the context menu of a source editor [message #22974 is a reply to message #22843] Wed, 18 February 2009 19:57 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan Patel
Messages: 68
Registered: July 2009
Member
you have two options...

1) Find the control for the vertical ruler and use ContextMenuFinder class.
2) Use org.eclipse.swtbot.swt.finder.finders.EventContextMenuFinder class,
which registers a filter for SWT.Show and SWT.Hide with display.

See javadocs to see how to use each class.
Re: looking for suggesting to locate/interact with the context menu of a source editor [message #23016 is a reply to message #22843] Wed, 18 February 2009 21:29 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
Hi Joe,

The vertical ruler is not supported in swtbot, please open a bug if
you're interested in this support.

Sending CTRL+F10 will definitely not help in finding the context menu
unless you hook in the EventContextMenuFinder *before* the menu pops up.

Note that at the moment chaining in context menus is not possible so you
cannot do:

editor.contextMenu("foo").menu("bar").click();

so you'll just need to do:

editor.contextMenu("bar").click();

instead.

-- Ketan

On 19/2/09 02:17, Joe Luebker wrote:
> Hello,
>
> I am trying to interact with a context menu of a vertical ruler in a
> source editor in Eclipse. I have discovered one way to open the context
> menu but haven't yet successfully been able to interact with it. Below
> is the snippet of code that actually opens the context menu.
>
> SWTBotEclipseEditor actMainEditor = bot.editor("act_main.c");
> actMainEditor.setFocus();
> actMainEditor.navigateTo(64, 0);
>
> // Open the context menu of the vertical ruler in the editor
> actMainEditor.notifyKeyboardEvent(SWT.CTRL, (char)0, SWT.F10);
>
>
> I have tried interacting with the focused widget which didn't work and
> haven't been able to find the menu using SWTBot yet. Any suggestions?
>
> Thanks,
> Joe
Re: looking for suggesting to locate/interact with the context menu of a source editor [message #23144 is a reply to message #23016] Thu, 19 February 2009 12:47 Go to previous messageGo to next message
Joe Luebker is currently offline Joe Luebker
Messages: 36
Registered: July 2009
Member
Thanks for the responses (both Ketans). I quickly tried to use the
EventContextMenuFinder as suggested in JavaDoc documentation. No success
yet.

Has something changed with the SWTBotMenu constructors since the snippet
was written.

Example usage:
EventContextMenuFinder eventContextMenuFinder = new
EventContextMenuFinder();
try {
eventContextMenuFinder.register();
button.click(); // a popup menu appears below the button
SWTBotMenu menu = new SWTBotMenu(new Finder(new
ControlFinder(), eventContextMenuFinder), "Menu Text");
menu.click();
} finally {
eventContextMenuFinder.unregister();
}

I didn't see where SWTBotMenu takes a Finder in a constructor.

Thanks,
Joe

Ketan Padegaonkar wrote:
> Hi Joe,
>
> The vertical ruler is not supported in swtbot, please open a bug if
> you're interested in this support.
>
> Sending CTRL+F10 will definitely not help in finding the context menu
> unless you hook in the EventContextMenuFinder *before* the menu pops up.
>
> Note that at the moment chaining in context menus is not possible so you
> cannot do:
>
> editor.contextMenu("foo").menu("bar").click();
>
> so you'll just need to do:
>
> editor.contextMenu("bar").click();
>
> instead.
>
> -- Ketan
>
> On 19/2/09 02:17, Joe Luebker wrote:
>> Hello,
>>
>> I am trying to interact with a context menu of a vertical ruler in a
>> source editor in Eclipse. I have discovered one way to open the context
>> menu but haven't yet successfully been able to interact with it. Below
>> is the snippet of code that actually opens the context menu.
>>
>> SWTBotEclipseEditor actMainEditor = bot.editor("act_main.c");
>> actMainEditor.setFocus();
>> actMainEditor.navigateTo(64, 0);
>>
>> // Open the context menu of the vertical ruler in the editor
>> actMainEditor.notifyKeyboardEvent(SWT.CTRL, (char)0, SWT.F10);
>>
>>
>> I have tried interacting with the focused widget which didn't work and
>> haven't been able to find the menu using SWTBot yet. Any suggestions?
>>
>> Thanks,
>> Joe
>
Re: looking for suggesting to locate/interact with the context menu of a source editor [message #23272 is a reply to message #23144] Thu, 19 February 2009 14:08 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
Hi Joe,

The usages I see for EventContextMenuFinder are in
SWTBotToolbarDropDownButton#menuItem and SWTBotTrayItem#contextMenu

-- Ketan

Joe Luebker wrote:
> Thanks for the responses (both Ketans). I quickly tried to use the
> EventContextMenuFinder as suggested in JavaDoc documentation. No success
> yet.
>
> Has something changed with the SWTBotMenu constructors since the snippet
> was written.
>
> Example usage:
> EventContextMenuFinder eventContextMenuFinder = new
> EventContextMenuFinder();
> try {
> eventContextMenuFinder.register();
> button.click(); // a popup menu appears below the button
> SWTBotMenu menu = new SWTBotMenu(new Finder(new ControlFinder(),
> eventContextMenuFinder), "Menu Text");
> menu.click();
> } finally {
> eventContextMenuFinder.unregister();
> }
>
> I didn't see where SWTBotMenu takes a Finder in a constructor.
>
> Thanks,
> Joe
>
> Ketan Padegaonkar wrote:
>> Hi Joe,
>>
>> The vertical ruler is not supported in swtbot, please open a bug if
>> you're interested in this support.
>>
>> Sending CTRL+F10 will definitely not help in finding the context menu
>> unless you hook in the EventContextMenuFinder *before* the menu pops up.
>>
>> Note that at the moment chaining in context menus is not possible so
>> you cannot do:
>>
>> editor.contextMenu("foo").menu("bar").click();
>>
>> so you'll just need to do:
>>
>> editor.contextMenu("bar").click();
>>
>> instead.
>>
>> -- Ketan
>>
>> On 19/2/09 02:17, Joe Luebker wrote:
>>> Hello,
>>>
>>> I am trying to interact with a context menu of a vertical ruler in a
>>> source editor in Eclipse. I have discovered one way to open the context
>>> menu but haven't yet successfully been able to interact with it. Below
>>> is the snippet of code that actually opens the context menu.
>>>
>>> SWTBotEclipseEditor actMainEditor = bot.editor("act_main.c");
>>> actMainEditor.setFocus();
>>> actMainEditor.navigateTo(64, 0);
>>>
>>> // Open the context menu of the vertical ruler in the editor
>>> actMainEditor.notifyKeyboardEvent(SWT.CTRL, (char)0, SWT.F10);
>>>
>>>
>>> I have tried interacting with the focused widget which didn't work and
>>> haven't been able to find the menu using SWTBot yet. Any suggestions?
>>>
>>> Thanks,
>>> Joe
>>
Re: looking for suggesting to locate/interact with the context menu of a source editor [message #23332 is a reply to message #23144] Thu, 19 February 2009 17:51 Go to previous messageGo to next message
Ketan Patel is currently offline Ketan Patel
Messages: 68
Registered: July 2009
Member
EventContextMenuFinder menuFinder = new EventContextMenuFinder();
try {
menuFinder.register();
// Invoke menu here
List<?> findMenus = menuFinder.findMenus(null, withMnemonic(menuItem), true);
if (findMenus.isEmpty())
throw new WidgetNotFoundException("Could not find a menu item");
return new SWTBotMenu((MenuItem) findMenus.get(0));
} finally {
menuFinder.unregister();
}
Re: looking for suggesting to locate/interact with the context menu of a source editor [message #23458 is a reply to message #23272] Fri, 20 February 2009 15:47 Go to previous message
Joe Luebker is currently offline Joe Luebker
Messages: 36
Registered: July 2009
Member
Thanks again to both Ketans for their suggestions. I did find a way find
and interact with a menu item on the context menu of a vertical ruler. I
do have a follow up question. When I performed a click on a found menu
item the context menu did not close as it would during user interaction.
Is this a bug in SWTBot? As a workaround a set the visibility of the
parent of the menu item to false. See below for the code that finally
worked for me:

// Open the source editor vertical ruler context menu and find the
// "Add Breakpoint" menu item
EventContextMenuFinder eventContextMenuFinder = new
EventContextMenuFinder();
SWTBotMenu addBreakpointMenu = null;
try {
eventContextMenuFinder.register();

// Open the context menu of the vertical ruler in the editor
actMainEditor.notifyKeyboardEvent(SWT.CTRL,(char) 0, SWT.F10);

List<MenuItem> foundMenus = eventContextMenuFinder
..findMenus(withMnemonic("Add Breakpoint"));
// We only expect to find one "Add Breakpoint" // Menu item
if (foundMenus.isEmpty()) { fail("Failed to find the 'Add
Breakpoint' menu item");
}
addBreakpointMenu = new SWTBotMenu((MenuItem) foundMenus.get(0));
} finally {
eventContextMenuFinder.unregister();
}

// Click the Add Breakpoint menu item
addBreakpointMenu.click();

// Close the vertical ruler context menu
final SWTBotMenu menu = addBreakpointMenu;
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
menu.widget.getParent().setVisible(false);
} catch (Exception e) {
// Ignore
}
}
});

Ketan Padegaonkar wrote:
> Hi Joe,
>
> The usages I see for EventContextMenuFinder are in
> SWTBotToolbarDropDownButton#menuItem and SWTBotTrayItem#contextMenu
>
> -- Ketan
>
> Joe Luebker wrote:
>> Thanks for the responses (both Ketans). I quickly tried to use the
>> EventContextMenuFinder as suggested in JavaDoc documentation. No success
>> yet.
>>
>> Has something changed with the SWTBotMenu constructors since the snippet
>> was written.
>>
>> Example usage:
>> EventContextMenuFinder eventContextMenuFinder = new
>> EventContextMenuFinder();
>> try {
>> eventContextMenuFinder.register();
>> button.click(); // a popup menu appears below the button
>> SWTBotMenu menu = new SWTBotMenu(new Finder(new ControlFinder(),
>> eventContextMenuFinder), "Menu Text");
>> menu.click();
>> } finally {
>> eventContextMenuFinder.unregister();
>> }
>>
>> I didn't see where SWTBotMenu takes a Finder in a constructor.
>>
>> Thanks,
>> Joe
>>
>> Ketan Padegaonkar wrote:
>>> Hi Joe,
>>>
>>> The vertical ruler is not supported in swtbot, please open a bug if
>>> you're interested in this support.
>>>
>>> Sending CTRL+F10 will definitely not help in finding the context menu
>>> unless you hook in the EventContextMenuFinder *before* the menu pops up.
>>>
>>> Note that at the moment chaining in context menus is not possible so
>>> you cannot do:
>>>
>>> editor.contextMenu("foo").menu("bar").click();
>>>
>>> so you'll just need to do:
>>>
>>> editor.contextMenu("bar").click();
>>>
>>> instead.
>>>
>>> -- Ketan
>>>
>>> On 19/2/09 02:17, Joe Luebker wrote:
>>>> Hello,
>>>>
>>>> I am trying to interact with a context menu of a vertical ruler in a
>>>> source editor in Eclipse. I have discovered one way to open the context
>>>> menu but haven't yet successfully been able to interact with it. Below
>>>> is the snippet of code that actually opens the context menu.
>>>>
>>>> SWTBotEclipseEditor actMainEditor = bot.editor("act_main.c");
>>>> actMainEditor.setFocus();
>>>> actMainEditor.navigateTo(64, 0);
>>>>
>>>> // Open the context menu of the vertical ruler in the editor
>>>> actMainEditor.notifyKeyboardEvent(SWT.CTRL, (char)0, SWT.F10);
>>>>
>>>>
>>>> I have tried interacting with the focused widget which didn't work and
>>>> haven't been able to find the menu using SWTBot yet. Any suggestions?
>>>>
>>>> Thanks,
>>>> Joe
Previous Topic:PROPERTIES OF COMPONENTS
Next Topic:can I both use and modify swtbot
Goto Forum:
  


Current Time: Wed Aug 27 09:12:46 EDT 2014

Powered by FUDForum. Page generated in 0.02195 seconds