org.eclipse.swtbot.swt.finder.finders
Class EventContextMenuFinder

java.lang.Object
  extended by org.eclipse.swtbot.swt.finder.finders.MenuFinder
      extended by org.eclipse.swtbot.swt.finder.finders.EventContextMenuFinder

public class EventContextMenuFinder
extends MenuFinder

Context menu finder that uses events to get the current context menu. It must be used instead of ContextMenuFinder when the context menu is not associated with a Widget. It must be registered before the context menu appears.

Here is a sample 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();
 }
 
This is not convenient to use but the need for this is not so frequent. In case you have better idea on the implementation or usage please add a comment to this bug.

Since:
1.0
Version:
$Id$
Author:
Cedric Chabanois <cchabanois [at] no-log [dot] org>

Constructor Summary
EventContextMenuFinder()
          Creates an event based context menu finder.
EventContextMenuFinder(Display display)
          Creates an event based context menu finder.
 
Method Summary
protected  Menu menuBar(Shell shell)
          Gets the menu bar that has been found.
 void register()
          Registers this finder so that it may start 'looking for' controls.
 void unregister()
          Unregisters this finder so that it may stop 'looking for' controls.
 
Methods inherited from class org.eclipse.swtbot.swt.finder.finders.MenuFinder
findMenus, findMenus, findMenus, findMenus, getShells
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventContextMenuFinder

public EventContextMenuFinder(Display display)
Creates an event based context menu finder.

Parameters:
display - the display
Throws:
NullPointerException - Thrown if the display is null.

EventContextMenuFinder

public EventContextMenuFinder()
Creates an event based context menu finder.

Method Detail

register

public void register()
Registers this finder so that it may start 'looking for' controls. It does so by listening for SWT.Show and SWT.Hide events on menus.


unregister

public void unregister()
Unregisters this finder so that it may stop 'looking for' controls. It does so by listening for SWT.Show and SWT.Hide events on menus.


menuBar

protected Menu menuBar(Shell shell)
Gets the menu bar that has been found. This may be null if one had not been found yet.

Overrides:
menuBar in class MenuFinder
Parameters:
shell - This is not used.
Returns:
The menu or null if not yet found.
See Also:
MenuFinder.menuBar(org.eclipse.swt.widgets.Shell)