changeset 10907:930274ac06c5

Merge
author kcr
date Wed, 18 Apr 2018 08:04:15 -0700
parents 1bb20f9ff029 57bfd4bea083
children 6f724f7a84e6
files
diffstat 4 files changed, 80 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/TabPaneSkin.java	Tue Apr 17 18:40:14 2018 -0700
+++ b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/TabPaneSkin.java	Wed Apr 18 08:04:15 2018 -0700
@@ -477,24 +477,6 @@
                 tabRegion.removeListeners(tab);
                 removeTabContent(tab);
 
-                // remove the menu item from the popup menu
-                ContextMenu popupMenu = tabHeaderArea.controlButtons.popup;
-                TabMenuItem tabItem = null;
-                if (popupMenu != null) {
-                    for (MenuItem item : popupMenu.getItems()) {
-                        tabItem = (TabMenuItem) item;
-                        if (tab == tabItem.getTab()) {
-                            break;
-                        }
-                        tabItem = null;
-                    }
-                }
-                if (tabItem != null) {
-                    tabItem.dispose();
-                    popupMenu.getItems().remove(tabItem);
-                }
-                // end of removing menu item
-
                 EventHandler<ActionEvent> cleanup = ae -> {
                     tabRegion.animationState = TabAnimationState.NONE;
 
@@ -1817,7 +1799,7 @@
                 showControlButtons = true;
             } else {
                 setVisible(false);
-                popup.getItems().clear();
+                clearPopupMenu();
                 popup = null;
             }
 
@@ -1831,7 +1813,7 @@
             if (popup == null) {
                 popup = new ContextMenu();
             }
-            popup.getItems().clear();
+            clearPopupMenu();
             ToggleGroup group = new ToggleGroup();
             ObservableList<RadioMenuItem> menuitems = FXCollections.<RadioMenuItem>observableArrayList();
             for (final Tab tab : getSkinnable().getTabs()) {
@@ -1843,6 +1825,13 @@
             popup.getItems().addAll(menuitems);
         }
 
+        private void clearPopupMenu() {
+            for (MenuItem item : popup.getItems()) {
+                ((TabMenuItem) item).dispose();
+            }
+            popup.getItems().clear();
+        }
+
         private void showPopupMenu() {
             for (MenuItem mi: popup.getItems()) {
                 TabMenuItem tmi = (TabMenuItem)mi;
@@ -1880,7 +1869,9 @@
         }
 
         public void dispose() {
+            textProperty().unbind();
             tab.disableProperty().removeListener(weakDisableListener);
+            tab = null;
         }
     }
 
@@ -2234,4 +2225,9 @@
             anim.stop();
         }
     }
+
+    // For testing purpose.
+    ContextMenu test_getTabsMenu() {
+        return tabHeaderArea.controlButtons.popup;
+    }
 }
--- a/modules/javafx.controls/src/shims/java/javafx/scene/control/TabPaneShim.java	Tue Apr 17 18:40:14 2018 -0700
+++ b/modules/javafx.controls/src/shims/java/javafx/scene/control/TabPaneShim.java	Wed Apr 18 08:04:15 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,7 @@
 
 public class TabPaneShim {
 
-    public static SingleSelectionModel<Tab> getTabPane_abPaneSelectionModel(TabPane tp) {
+    public static SingleSelectionModel<Tab> getTabPaneSelectionModel(TabPane tp) {
         return new TabPane.TabPaneSelectionModel(tp);
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.controls/src/shims/java/javafx/scene/control/skin/TabPaneSkinShim.java	Wed Apr 18 08:04:15 2018 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javafx.scene.control.skin;
+
+import javafx.scene.control.ContextMenu;
+
+public class TabPaneSkinShim {
+
+    public static ContextMenu getTabsMenu(TabPaneSkin tpSkin) {
+        return tpSkin.test_getTabsMenu();
+    }
+
+}
--- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/TabPaneTest.java	Tue Apr 17 18:40:14 2018 -0700
+++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/TabPaneTest.java	Wed Apr 18 08:04:15 2018 -0700
@@ -66,7 +66,6 @@
 import test.com.sun.javafx.pgstub.StubToolkit;
 import test.com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
 import test.com.sun.javafx.scene.control.infrastructure.MouseEventGenerator;
-import javafx.scene.control.skin.TabPaneSkin;
 import com.sun.javafx.scene.input.KeyCodeMap;
 import com.sun.javafx.tk.Toolkit;
 
@@ -76,9 +75,12 @@
 import java.util.List;
 import java.util.Map;
 import javafx.scene.control.Button;
+import javafx.scene.control.ContextMenu;
 import javafx.scene.control.ScrollPane;
 import javafx.scene.control.SingleSelectionModel;
 import javafx.scene.control.SingleSelectionModelShim;
+import javafx.scene.control.skin.TabPaneSkin;
+import javafx.scene.control.skin.TabPaneSkinShim;
 import javafx.scene.control.SplitPane;
 import javafx.scene.control.Tab;
 import javafx.scene.control.TabPane;
@@ -103,7 +105,7 @@
         tab1 = new Tab("one");
         tab2 = new Tab("two");
         tab3 = new Tab("three");
-        sm = TabPaneShim.getTabPane_abPaneSelectionModel(tabPane);
+        sm = TabPaneShim.getTabPaneSelectionModel(tabPane);
         root = new StackPane();
         scene = new Scene(root);
         stage = new Stage();
@@ -1162,4 +1164,26 @@
             }
         }
     }
+
+    // Test for JDK-8157690
+    @Test public void testPopupItemsOnSortingTabs() {
+        tabPane.setMaxSize(20, 20);
+        root.getChildren().add(tabPane);
+        tabPane.getTabs().addAll(tab1, tab2, tab3);
+        show();
+        tk.firePulse();
+        TabPaneSkin tbSkin = (TabPaneSkin) tabPane.getSkin();
+        assertNotNull(tbSkin);
+        ContextMenu tabsMenu = TabPaneSkinShim.getTabsMenu(tbSkin);
+        assertNotNull(tabsMenu);
+        assertEquals("ContextMenu should contain 3 items.", 3, tabsMenu.getItems().size());
+
+        tabPane.getTabs().sort((o1, o2) -> sortCompare(o1, o2));
+        tk.firePulse();
+        assertEquals("ContextMenu should contain 3 items.", 3, tabsMenu.getItems().size());
+    }
+
+    private int sortCompare(Tab t1, Tab t2) {
+        return t2.getText().compareTo(t1.getText());
+    }
 }