changeset 1253:dfa7572ff039

RT-22027: Exception raised for a ComboBox in an Accordion.
author Kinsley Wong <kinsley.wong@oracle.com>
date Thu, 07 Jun 2012 12:47:59 -0700
parents 966cbfed8d62
children abbc696491cb
files javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/AccordionBehavior.java javafx-ui-controls/test/javafx/scene/control/AccordionTest.java
diffstat 2 files changed, 51 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/AccordionBehavior.java	Thu Jun 07 19:50:00 2012 +0100
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/AccordionBehavior.java	Thu Jun 07 12:47:59 2012 -0700
@@ -77,10 +77,10 @@
         return ACCORDION_BINDINGS;
     }
 
-    @Override protected void callAction(String name) {       
+    @Override protected void callAction(String name) {   
         Accordion accordion = getControl();
         if ("TraverseLeft".equals(name) || "TraverseUp".equals(name) || PAGE_UP.equals(name)) {
-            if (accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
+            if (focusModel.getFocusedIndex() != -1 && accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
                 focusModel.focusPrevious();
                 int next = focusModel.getFocusedIndex();
                 accordion.getPanes().get(next).requestFocus();
@@ -89,7 +89,7 @@
                 }
             }
         } else if ("TraverseRight".equals(name) || "TraverseDown".equals(name) || PAGE_DOWN.equals(name)) {
-            if (accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
+            if (focusModel.getFocusedIndex() != -1 && accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
                 focusModel.focusNext();
                 int next = focusModel.getFocusedIndex();
                 accordion.getPanes().get(next).requestFocus();
@@ -99,22 +99,26 @@
             }            
         } else if (CTRL_TAB.equals(name) || CTRL_PAGE_DOWN.equals(name)) {
             focusModel.focusNext();
-            int next = focusModel.getFocusedIndex();
-            accordion.getPanes().get(next).requestFocus();
-            accordion.getPanes().get(next).setExpanded(true);
+            if (focusModel.getFocusedIndex() != -1) {
+                int next = focusModel.getFocusedIndex();
+                accordion.getPanes().get(next).requestFocus();
+                accordion.getPanes().get(next).setExpanded(true);
+            }
         } else if (CTRL_SHIFT_TAB.equals(name) || CTRL_PAGE_UP.equals(name)) {
             focusModel.focusPrevious();
-            int next = focusModel.getFocusedIndex();
-            accordion.getPanes().get(next).requestFocus();
-            accordion.getPanes().get(next).setExpanded(true);
+            if (focusModel.getFocusedIndex() != -1) {
+                int next = focusModel.getFocusedIndex();            
+                accordion.getPanes().get(next).requestFocus();
+                accordion.getPanes().get(next).setExpanded(true);
+            }
         } else if (HOME.equals(name)) {
-            if (accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
+            if (focusModel.getFocusedIndex() != -1 && accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
                 TitledPane tp = accordion.getPanes().get(0);
                 tp.requestFocus();
                 tp.setExpanded(!tp.isExpanded());
             }
         } else if (END.equals(name)) {
-            if (accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
+            if (focusModel.getFocusedIndex() != -1 && accordion.getPanes().get(focusModel.getFocusedIndex()).isFocused()) {
                 TitledPane tp = accordion.getPanes().get(accordion.getPanes().size() - 1);
                 tp.requestFocus();
                 tp.setExpanded(!tp.isExpanded());
--- a/javafx-ui-controls/test/javafx/scene/control/AccordionTest.java	Thu Jun 07 19:50:00 2012 +0100
+++ b/javafx-ui-controls/test/javafx/scene/control/AccordionTest.java	Thu Jun 07 12:47:59 2012 -0700
@@ -3,11 +3,14 @@
  */
 package javafx.scene.control;
 
+import com.sun.javafx.pgstub.StubToolkit;
+import com.sun.javafx.tk.Toolkit;
 import javafx.scene.Scene;
 import javafx.scene.layout.StackPane;
 import javafx.stage.Stage;
 import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.value.ObservableValue;
+import javafx.scene.input.KeyCode;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -16,14 +19,15 @@
 
 /**
  */
-public class AccordionTest {
-
+public class AccordionTest {    
     private Accordion accordion;
+    private Toolkit tk;
     private Scene scene;
     private Stage stage;
     private StackPane root;    
     
     @Before public void setup() {
+        tk = (StubToolkit)Toolkit.getToolkit();//This step is not needed (Just to make sure StubToolkit is loaded into VM)
         accordion = new Accordion();
         root = new StackPane();
         scene = new Scene(root);
@@ -154,4 +158,34 @@
         assertEquals(54, accordion.prefWidth(-1), 1e-100);
         assertEquals(170, accordion.prefHeight(-1), 1e-100);
     }
+    
+    @Test public void aiobeWhenFocusIsOnAControlInsideTheAccordion_RT22027() {
+        Button b1 = new Button("A");
+        Button b2 = new Button("B");
+        
+        TitledPane a = new TitledPane("A", b1);
+        TitledPane b = new TitledPane("B", b2);
+        
+        accordion.getPanes().addAll(a, b);
+        accordion.setExpandedPane(a);
+        accordion.setLayoutX(200);
+        
+        root.setPrefSize(800, 800);
+        root.getChildren().add(accordion);
+        b1.requestFocus();
+        show();
+        
+        root.impl_reapplyCSS();
+        root.autosize();
+        root.layout();
+                
+        KeyEventFirer keyboard = new KeyEventFirer(b1);                
+
+        try {        
+            keyboard.doKeyPress(KeyCode.HOME);
+            tk.firePulse(); 
+        } catch (Exception e) {
+            fail();
+        }
+    }
 }