changeset 1140:7a3adedc3491

fix RT-21750 Impossible to remove a menu from MenuBar & added unit test
author Paru Somashekar <paru.somashekar@oracle.com>
date Thu, 24 May 2012 12:33:40 -0700
parents 76674fd1bc7e
children cc4e078e637c b96b6a7b5bad
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/MenuBarSkin.java javafx-ui-controls/test/javafx/scene/control/MenuBarTest.java
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Thu May 24 17:36:51 2012 +0100
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Thu May 24 12:33:40 2012 -0700
@@ -387,6 +387,10 @@
     
     private void rebuildUI() {
         int index = 0;
+        for (Menu m : getSkinnable().getMenus()) {
+            // remove action listeners 
+            updateActionListeners(getSkinnable().getMenus().get(index), false);
+        }
         for(Node n : container.getChildren()) {
             //Stop observing menu's showing & disable property for changes.
             //Need to unbind before clearing container's children.
@@ -397,7 +401,6 @@
             menuButton.textProperty().unbind();
             menuButton.graphicProperty().unbind();
             menuButton.styleProperty().unbind();
-            updateActionListeners(getSkinnable().getMenus().get(index), false);
             index++;
         }
         container.getChildren().clear();
--- a/javafx-ui-controls/test/javafx/scene/control/MenuBarTest.java	Thu May 24 17:36:51 2012 +0100
+++ b/javafx-ui-controls/test/javafx/scene/control/MenuBarTest.java	Thu May 24 12:33:40 2012 -0700
@@ -74,6 +74,13 @@
         assertEquals(0, menuBar.getMenus().size());
     }
     
+     @Test public void getMenusIsRemovable() {
+           menuBar.getMenus().add(new Menu("blah"));
+           menuBar.getMenus().add(new Menu("foo"));
+           menuBar.getMenus().remove(0);
+           assertEquals(1, menuBar.getMenus().size());
+     }
+     
     @Test public void testMenuShowHideWithMenuBarWithXYTranslation() {
         final MouseEventGenerator generator = new MouseEventGenerator();
         AnchorPane root = new AnchorPane();