Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SWTBotTrayItem |
|
| 2.0;2 |
1 | /******************************************************************************* | |
2 | * Copyright (c) 2009 SWTBot Committers and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Toby Weston - initial API and implementation (Bug 259860) | |
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 | * Represents a tray item. | |
26 | * | |
27 | * @author Toby Weston (Bug 259860) | |
28 | * @version $Id$ | |
29 | */ | |
30 | public class SWTBotTrayItem extends AbstractSWTBot<TrayItem> { | |
31 | ||
32 | /** | |
33 | * Constructs a new instance with the given widget. | |
34 | * | |
35 | * @param widget the tray item. | |
36 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
37 | */ | |
38 | public SWTBotTrayItem(TrayItem widget) throws WidgetNotFoundException { | |
39 | 15 | super(widget); |
40 | 15 | } |
41 | ||
42 | public SWTBotMenu contextMenu(String label) throws WidgetNotFoundException { | |
43 | 0 | EventContextMenuFinder finder = new EventContextMenuFinder(); |
44 | try { | |
45 | 0 | finder.register(); |
46 | 0 | notify(SWT.MenuDetect); |
47 | 0 | Matcher<MenuItem> withMnemonic = withMnemonic(label); |
48 | 0 | List<MenuItem> menus = finder.findMenus(withMnemonic); |
49 | 0 | if (menus.isEmpty()) |
50 | 0 | throw new WidgetNotFoundException("Could not find a menu item"); |
51 | 0 | return new SWTBotMenu(menus.get(0)); |
52 | 0 | } finally { |
53 | 0 | finder.unregister(); |
54 | 0 | } |
55 | } | |
56 | ||
57 | /** | |
58 | * Convenience API for {@link #contextMenu(String)} | |
59 | */ | |
60 | public SWTBotMenu menu(String label) { | |
61 | 0 | return contextMenu(label); |
62 | } | |
63 | } |