changeset 4841:3db94ad212b6

RT-29885: Regression: issue with ComboBox focusedProperty I've fixed this for both ComboBox and DatePicker, which is built on top of the same ComboBox base code and so had the same problem.
author jgiles
date Wed, 28 Aug 2013 16:35:23 +1200
parents 2285e786059a
children bf88b13087fd
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/DatePickerSkin.java modules/controls/src/main/java/javafx/scene/control/ComboBoxBase.java
diffstat 3 files changed, 26 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Tue Aug 27 10:26:58 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Wed Aug 28 16:35:23 2013 +1200
@@ -137,23 +137,10 @@
         
         updateButtonCell();
         
-        // move focus in to the textfield if the comboBox is editable
-        comboBox.focusedProperty().addListener(new ChangeListener<Boolean>() {
-            @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) {
-                if (comboBox.isEditable() && hasFocus) {
-                    Platform.runLater(new Runnable() {
-                        @Override public void run() {
-                            textField.requestFocus();
-                        }
-                    });
-                }
-            }
-        });
-        
         comboBox.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() {
             @Override public void handle(KeyEvent ke) {
                 if (textField == null) return;
-                
+
                 // When the user hits the enter or F4 keys, we respond before 
                 // ever giving the event to the TextField.
                 if (ke.getCode() == KeyCode.ENTER) {
@@ -368,11 +355,15 @@
         // Fix for RT-21406: ComboBox do not show initial text value
         initialTextFieldValue = textField.getText();
         // End of fix (see updateDisplayNode below for the related code)
-        
+
         textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
             @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) {
                 if (! comboBox.isEditable()) return;
-                
+
+                // Fix for RT-29885
+                comboBox.getProperties().put("FOCUSED", hasFocus);
+                // --- end of RT-29885
+
                 // RT-21454 starts here
                 if (! hasFocus) {
                     setTextFromTextFieldIntoComboBoxValue();
@@ -380,6 +371,7 @@
                 } else {
                     pseudoClassStateChanged(CONTAINS_FOCUS_PSEUDOCLASS_STATE, true);
                 }
+                // --- end of RT-21454
             }
         });
 
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/DatePickerSkin.java	Tue Aug 27 10:26:58 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/DatePickerSkin.java	Wed Aug 28 16:35:23 2013 +1200
@@ -77,19 +77,6 @@
             });
         }
 
-        // move focus in to the textfield if the comboBox is editable
-        datePicker.focusedProperty().addListener(new ChangeListener<Boolean>() {
-            @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) {
-                if (datePicker.isEditable() && hasFocus) {
-                    Platform.runLater(new Runnable() {
-                        @Override public void run() {
-                            textField.requestFocus();
-                        }
-                    });
-                }
-            }
-        });
-
         datePicker.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() {
             @Override public void handle(KeyEvent ke) {
                 if (textField == null) return;
@@ -243,6 +230,10 @@
             @Override public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) {
                 if (!datePicker.isEditable()) return;
 
+                // Fix for RT-29885
+                datePicker.getProperties().put("FOCUSED", hasFocus);
+                // --- end of RT-29885
+
                 // RT-21454 starts here
                 if (! hasFocus) {
                     setTextFromTextFieldIntoComboBoxValue();
--- a/modules/controls/src/main/java/javafx/scene/control/ComboBoxBase.java	Tue Aug 27 10:26:58 2013 -0700
+++ b/modules/controls/src/main/java/javafx/scene/control/ComboBoxBase.java	Wed Aug 28 16:35:23 2013 +1200
@@ -25,6 +25,7 @@
 
 package javafx.scene.control;
 
+import javafx.collections.MapChangeListener;
 import javafx.css.PseudoClass;
 import javafx.beans.property.*;
 import javafx.event.ActionEvent;
@@ -116,6 +117,19 @@
      */
     public ComboBoxBase() {
         getStyleClass().add(DEFAULT_STYLE_CLASS);
+
+        // Fix for RT-29885
+        getProperties().addListener(new MapChangeListener<Object, Object>() {
+            @Override public void onChanged(Change<?,?> change) {
+                if (change.wasAdded()) {
+                    if (change.getKey() == "FOCUSED") {
+                        setFocused((Boolean)change.getValueAdded());
+                        getProperties().remove("FOCUSED");
+                    }
+                }
+            }
+        });
+        // End of fix for RT-29885
     }
     
     void valueInvalidated() {