Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2015-06-15 22:49:22 +0000
committerPatrick Tasse2015-06-16 16:32:57 +0000
commit127fc7e80f7fd0db9a2a740c1663c60fdc6b476f (patch)
treeae488961b080ec99dcfc497b7a96fb26d045fbcc
parent1a8a2c77f26fe626758029568db0d1fef904561f (diff)
downloadorg.eclipse.swtbot-127fc7e80f7fd0db9a2a740c1663c60fdc6b476f.tar.gz
org.eclipse.swtbot-127fc7e80f7fd0db9a2a740c1663c60fdc6b476f.tar.xz
org.eclipse.swtbot-127fc7e80f7fd0db9a2a740c1663c60fdc6b476f.zip
Bug 458975: Fix ContextMenuFinder returns disposed menu items
The method findMenus() should not iterate through the shells of the display when trying to find menu items. Doing so may dispose the previous menu and its items at each iteration if the context menu is a dynamic menu (e.g. MenuManager.setRemoveAllWhenShown(true)). In the scope of a ContextMenuFinder there is only one menu associated with the control, it should be queried directly. Change-Id: Icfc5e05bf083626304e5a77054535352788b7f4b Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/finders/ContextMenuFinder.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/finders/ContextMenuFinder.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/finders/ContextMenuFinder.java
index e6c1f4ea..57d017f9 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/finders/ContextMenuFinder.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/finders/ContextMenuFinder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Ketan Padegaonkar and others.
+ * Copyright (c) 2008, 2015 Ketan Padegaonkar and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,16 +7,19 @@
*
* Contributors:
* Ketan Padegaonkar - initial API and implementation
+ * Patrick Tasse - Fix ContextMenuFinder returns disposed menu items (Bug 458975)
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.finders;
-
+import java.util.List;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swtbot.swt.finder.results.WidgetResult;
import org.eclipse.swtbot.swt.finder.utils.internal.Assert;
+import org.hamcrest.Matcher;
/**
* Finds context menus for a given control.
@@ -43,13 +46,11 @@ public class ContextMenuFinder extends MenuFinder {
this.control = control;
}
- /**
- * Gets the menubar for the given shell.
- *
- * @see org.eclipse.swtbot.swt.finder.finders.MenuFinder#menuBar(org.eclipse.swt.widgets.Shell)
- * @param shell The shell to find the menu bar for.
- * @return The menu bar found.
- */
+ @Override
+ public List<MenuItem> findMenus(Matcher<MenuItem> matcher) {
+ return findMenus(menuBar(null), matcher, true);
+ }
+
@Override
protected Menu menuBar(final Shell shell) {
return UIThreadRunnable.syncExec(display, new WidgetResult<Menu>() {

Back to the top