| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package org.eclipse.swtbot.swt.finder.widgets; |
| 12 | |
|
| 13 | |
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic; |
| 14 | |
|
| 15 | |
import java.util.List; |
| 16 | |
|
| 17 | |
import org.eclipse.swt.SWT; |
| 18 | |
import org.eclipse.swt.widgets.MenuItem; |
| 19 | |
import org.eclipse.swt.widgets.TrayItem; |
| 20 | |
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
| 21 | |
import org.eclipse.swtbot.swt.finder.finders.EventContextMenuFinder; |
| 22 | |
import org.hamcrest.Matcher; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
public class SWTBotTrayItem extends AbstractSWTBot<TrayItem> { |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public SWTBotTrayItem(TrayItem widget) throws WidgetNotFoundException { |
| 39 | 18 | super(widget); |
| 40 | 18 | } |
| 41 | |
|
| 42 | |
public SWTBotMenu contextMenu(String label) throws WidgetNotFoundException { |
| 43 | 1 | EventContextMenuFinder finder = new EventContextMenuFinder(); |
| 44 | |
try { |
| 45 | 1 | finder.register(); |
| 46 | 1 | notify(SWT.MenuDetect); |
| 47 | 1 | Matcher<MenuItem> withMnemonic = withMnemonic(label); |
| 48 | 1 | List<MenuItem> menus = finder.findMenus(withMnemonic); |
| 49 | 1 | if (menus.isEmpty()) |
| 50 | 0 | throw new WidgetNotFoundException("Could not find a menu item"); |
| 51 | 2 | return new SWTBotMenu(menus.get(0)); |
| 52 | 0 | } finally { |
| 53 | 1 | finder.unregister(); |
| 54 | 0 | } |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public SWTBotMenu menu(String label) { |
| 61 | 1 | return contextMenu(label); |
| 62 | |
} |
| 63 | |
} |