Permalink
Browse files

Non-sprint task: Fixing problems with contextmenus under Mac/SWT and …

…Swing-Tables
  • Loading branch information...
1 parent 5e418d6 commit 2bd02cc59f3b308c11db2592694db40335217c8d Marvin Mueller committed Dec 17, 2012
View
13 org.eclipse.jubula.rc.swing/src/org/eclipse/jubula/rc/swing/swing/caps/JMenuBarCAPs.java
@@ -158,8 +158,11 @@ protected void closeMenu(IMenuAdapter menuBar, String[] textPath,
String operator) {
if (menuBar.getRealComponent() instanceof JPopupMenu) {
for (int i = 0; i < textPath.length; i++) {
- getRobot().keyType(menuBar.getRealComponent(),
- KeyEvent.VK_ESCAPE);
+ if (((JPopupMenu)menuBar.getRealComponent()).isVisible()) {
+ getRobot().keyType(menuBar.getRealComponent(),
+ KeyEvent.VK_ESCAPE);
+ }
+
}
return;
}
@@ -173,8 +176,10 @@ protected void closeMenu(IMenuAdapter menuBar, String[] textPath,
protected void closeMenu(IMenuAdapter menuBar, int[] path) {
if (menuBar.getRealComponent() instanceof JPopupMenu) {
for (int i = 0; i < path.length; i++) {
- getRobot().keyType(menuBar.getRealComponent(),
- KeyEvent.VK_ESCAPE);
+ if (((JPopupMenu)menuBar.getRealComponent()).isVisible()) {
+ getRobot().keyType(menuBar.getRealComponent(),
+ KeyEvent.VK_ESCAPE);
+ }
}
return;
}
View
26 org.eclipse.jubula.rc.swt/src/org/eclipse/jubula/rc/swt/uiadapter/MenuItemAdapter.java
@@ -33,6 +33,7 @@
import org.eclipse.jubula.tools.constants.TimeoutConstants;
import org.eclipse.jubula.tools.i18n.I18n;
import org.eclipse.jubula.tools.objects.event.EventFactory;
+import org.eclipse.jubula.tools.utils.EnvironmentUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
@@ -485,7 +486,8 @@ public void selectProgramatically() {
event.widget = menuItem;
event.display = menuItem.getDisplay();
event.type = SWT.Selection;
-
+ closeUnderMac();
+
getEventThreadQueuer().invokeLater(
"selectProgramatically", new Runnable() { //$NON-NLS-1$
public void run() {
@@ -527,6 +529,28 @@ public Object run()
}
}
+ /**
+ * "close" (hide) the context menu. this is necessary because if you
+ * select programatically the contextmenu is not closed.
+ */
+ private void closeUnderMac() {
+ if (EnvironmentUtils.isMacOS()) {
+ // "close" (hide) the context menu. this is necessary because
+ // the selection event will not close the context menu.
+ // we do this before firing the selection event so that the menu
+ // disappears before the effects of the selection event (e.g.
+ // showing a dialog) are presented.
+ m_menuItem.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ Menu parentMenu = m_menuItem.getParent();
+ while (parentMenu.getParentMenu() != null) {
+ parentMenu = parentMenu.getParentMenu();
+ }
+ parentMenu.setVisible(false);
+ }
+ });
+ }
+ }
}

0 comments on commit 2bd02cc

Please sign in to comment.