changeset 1250:60301b7fd01f

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/2.2/scrum/controls/jfx/rt
author jgiles
date Thu, 07 Jun 2012 13:43:46 +1200
parents c03a7b34ec86 9897f5b8a23d
children defcb2e3aa77 f848576e5df0
files
diffstat 7 files changed, 167 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Wed Jun 06 16:37:04 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Jun 07 13:43:46 2012 +1200
@@ -57,6 +57,14 @@
     // This may one day become a property on the ComboBox itself.
     private static final String COMBO_BOX_ROWS_TO_MEASURE_WIDTH_KEY = "comboBoxRowsToMeasureWidth";
     
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private fields                                                          *
+     *                                                                         *
+     **************************************************************************/    
+    
     private final ComboBox<T> comboBox;
     
     private ListCell<T> buttonCell;
@@ -67,6 +75,36 @@
     
     private ObservableList<T> listViewItems;
     
+    private boolean listSelectionLock = false;
+    private boolean listViewSelectionDirty = false;
+    
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Listeners                                                               *
+     *                                                                         *
+     **************************************************************************/
+    
+    private boolean itemCountDirty;
+    private final ListChangeListener listViewItemsListener = new ListChangeListener() {
+        @Override public void onChanged(ListChangeListener.Change c) {
+            itemCountDirty = true;
+            requestLayout();
+        }
+    };
+    
+    private final WeakListChangeListener weakListViewItemsListener =
+            new WeakListChangeListener(listViewItemsListener);
+    
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Constructors                                                            *
+     *                                                                         *
+     **************************************************************************/   
+    
     public ComboBoxListViewSkin(final ComboBox<T> comboBox) {
         super(comboBox, new ComboBoxListViewBehavior<T>(comboBox));
         this.comboBox = comboBox;
@@ -117,24 +155,10 @@
         });
         
         // Fix for RT-19431 (also tested via ComboBoxListViewSkinTest)
+        updateValue(comboBox.getValue());
         comboBox.valueProperty().addListener(new ChangeListener<T>() {
             @Override public void changed(ObservableValue<? extends T> ov, T oldValue, T newValue) {
-                if (newValue == null) {
-                    listView.getSelectionModel().clearSelection();
-                } else {
-                    int index = comboBox.getSelectionModel().getSelectedIndex();
-                    if (index >= 0 && index < comboBox.getItems().size()) {
-                        T itemsObj = comboBox.getItems().get(index);
-                        if (itemsObj != null && itemsObj.equals(newValue)) {
-                            listView.getSelectionModel().select(index);
-                        } else {
-                            listView.getSelectionModel().select(newValue);
-                        }
-                    } else {
-                        // just select the first instance of newValue in the list
-                        listView.getSelectionModel().select(newValue);
-                    }
-                }
+                updateValue(newValue);
             }
         });
         
@@ -147,34 +171,15 @@
         registerChangeListener(comboBox.buttonCellProperty(), "BUTTON_CELL");
     }
     
-    public void updateListViewItems() {
-        if (listViewItems != null) {
-            listViewItems.removeListener(weakListViewItemsListener);
-        }
-
-        this.listViewItems = comboBox.getItems();
-        listView.setItems(null);
-        listView.setItems(listViewItems);
-
-        if (listViewItems != null) {
-            listViewItems.addListener(weakListViewItemsListener);
-        }
-        
-        itemCountDirty = true;
-        requestLayout();
-    }
     
-    private boolean itemCountDirty;
-    private final ListChangeListener listViewItemsListener = new ListChangeListener() {
-        @Override public void onChanged(ListChangeListener.Change c) {
-            itemCountDirty = true;
-            requestLayout();
-        }
-    };
     
-    private final WeakListChangeListener weakListViewItemsListener =
-            new WeakListChangeListener(listViewItemsListener);
+    /***************************************************************************
+     *                                                                         *
+     * Public API                                                              *
+     *                                                                         *
+     **************************************************************************/  
     
+    /** {@inheritDoc} */
     @Override protected void handleControlPropertyChanged(String p) {
         // Fix for RT-21207
         if (p == "SHOWING") {
@@ -206,6 +211,7 @@
         }
     }
     
+    /** {@inheritDoc} */
     @Override public Node getDisplayNode() {
         Node displayNode;
         if (comboBox.isEditable()) {
@@ -222,6 +228,88 @@
         return displayNode;
     }
     
+    /**
+     * 
+     */
+    public void updateListViewItems() {
+        if (listViewItems != null) {
+            listViewItems.removeListener(weakListViewItemsListener);
+        }
+
+        this.listViewItems = comboBox.getItems();
+        listView.setItems(null);
+        listView.setItems(listViewItems);
+
+        if (listViewItems != null) {
+            listViewItems.addListener(weakListViewItemsListener);
+        }
+        
+        itemCountDirty = true;
+        requestLayout();
+    }
+    
+    @Override public Node getPopupContent() {
+        return listView;
+    }
+    
+    @Override protected double computePrefWidth(double height) {
+        return listView.prefWidth(height);
+    }
+    
+    @Override protected double computeMinWidth(double height) {
+        return 50;
+    }
+    
+    @Override protected void layoutChildren() {
+        if (listViewSelectionDirty) {
+            try {
+                listSelectionLock = true;
+                T item = comboBox.getSelectionModel().getSelectedItem();
+                listView.getSelectionModel().clearSelection();
+                listView.getSelectionModel().select(item);
+            } finally {
+                listSelectionLock = false;
+                listViewSelectionDirty = false;
+            }
+        }
+        
+        super.layoutChildren();
+    }
+    
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private methods                                                         *
+     *                                                                         *
+     **************************************************************************/    
+    
+    private void updateValue(T newValue) {
+        if (newValue == null) {
+            listView.getSelectionModel().clearSelection();
+        } else {
+            int index = comboBox.getSelectionModel().getSelectedIndex();
+            if (index >= 0 && index < comboBox.getItems().size()) {
+                T itemsObj = comboBox.getItems().get(index);
+                if (itemsObj != null && itemsObj.equals(newValue)) {
+                    listView.getSelectionModel().select(index);
+                } else {
+                    listView.getSelectionModel().select(newValue);
+                }
+            } else {
+                // just select the first instance of newValue in the list
+                int listViewIndex = listView.getItems().indexOf(newValue);
+                if (listViewIndex == -1) {
+                    // RT-21336 Show the ComboBox value even though it doesn't
+                    // exist in the ComboBox items list (part one of fix)
+                    updateDisplayNode();
+                } else {
+                    listView.getSelectionModel().select(listViewIndex);
+                }
+            }
+        }
+    }
+    
     private TextField getEditableInputNode() {
         if (textField != null) return textField;
         
@@ -253,9 +341,9 @@
     private void updateDisplayNode() {
         StringConverter<T> c = comboBox.getConverter();
         if (c == null) return;
-                        
+              
+        T value = comboBox.getValue();
         if (comboBox.isEditable()) {
-            T value = comboBox.getValue();
             String stringValue = c.toString(value);
             if (value == null || stringValue == null) {
                 textField.setText("");
@@ -264,8 +352,14 @@
             }
         } else {
             int index = getSelectedIndex();
-            buttonCell.updateListView(listView);
-            buttonCell.updateIndex(index);
+            if (index > -1) {
+                buttonCell.updateListView(listView);
+                buttonCell.updateIndex(index);
+            } else {
+                // RT-21336 Show the ComboBox value even though it doesn't
+                // exist in the ComboBox items list (part two of fix)
+                updateDisplayText(buttonCell, value, false);
+            }
         }
     }
     
@@ -317,10 +411,6 @@
         buttonCell.setMouseTransparent(true);
     }
 
-    @Override public Node getPopupContent() {
-        return listView;
-    }
-    
     private void updateCellFactory() {
         Callback<ListView<T>, ListCell<T>> cf = comboBox.getCellFactory();
         cellFactory = cf != null ? cf : getDefaultCellFactory();
@@ -340,10 +430,9 @@
         };
     }
     
-    private boolean listSelectionLock = false;
-    
     private ListView<T> createListView() {
         final ListView<T> listView = new ListView<T>() {
+            private boolean isFirstSizeCalculation = true;
             
             @Override protected double computeMinHeight(double width) {
                 return 30;
@@ -380,12 +469,14 @@
             }
             
             private void doCSSCheck() {
-                if (getSkin() == null) {
+                Parent parent = getPopup().getScene().getRoot();
+                if ((isFirstSizeCalculation || getSkin() == null) && parent.getScene() != null) {
                     // if the skin is null, it means that the css related to the
                     // listview skin hasn't been loaded yet, so we force it here.
                     // This ensures the combobox button is the correct width
                     // when it is first displayed, before the listview is shown.
-                    getPopup().getScene().getRoot().impl_processCSS(true);
+                    parent.impl_processCSS(true);
+                    isFirstSizeCalculation = false;
                 }
             }
         };
@@ -456,30 +547,6 @@
         return ph;
     }
 
-    @Override protected double computePrefWidth(double height) {
-        return listView.prefWidth(height);
-    }
-    
-    @Override protected double computeMinWidth(double height) {
-        return 50;
-    }
-    
-    private boolean listViewSelectionDirty = false;
-    @Override protected void layoutChildren() {
-        if (listViewSelectionDirty) {
-            try {
-                listSelectionLock = true;
-                T item = comboBox.getSelectionModel().getSelectedItem();
-                listView.getSelectionModel().clearSelection();
-                listView.getSelectionModel().select(item);
-            } finally {
-                listSelectionLock = false;
-                listViewSelectionDirty = false;
-            }
-        }
-        
-        super.layoutChildren();
-    }
 
     
     /**************************************************************************
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxPopupControl.java	Wed Jun 06 16:37:04 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxPopupControl.java	Thu Jun 07 13:43:46 2012 +1200
@@ -137,5 +137,6 @@
         };
         getSkinnable().layoutXProperty().addListener(layoutPosListener);
         getSkinnable().layoutYProperty().addListener(layoutPosListener);
+        getSkinnable().widthProperty().addListener(layoutPosListener);
     }
 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/NestedTableColumnHeader.java	Wed Jun 06 16:37:04 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/NestedTableColumnHeader.java	Thu Jun 07 13:43:46 2012 +1200
@@ -73,7 +73,6 @@
         } else if (getTableColumn() != null) {
             setColumns(getTableColumn().getColumns());
         }
-//        getColumns().addListener(weakColumnsListener);
     }
     
     
@@ -458,7 +457,7 @@
 
         newCol.setTableHeaderRow(getTableHeaderRow());
         newCol.setParentHeader(this);
-
+        
         return newCol;
     }
 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableCellSkin.java	Wed Jun 06 16:37:04 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableCellSkin.java	Thu Jun 07 13:43:46 2012 +1200
@@ -30,6 +30,7 @@
 import javafx.scene.control.TableCell;
 
 import com.sun.javafx.scene.control.behavior.TableCellBehavior;
+import javafx.scene.shape.Rectangle;
 
 /**
  */
@@ -51,10 +52,17 @@
     
     private WeakInvalidationListener weakColumnWidthListener =
             new WeakInvalidationListener(columnWidthListener);
-
+    
     public TableCellSkin(TableCell control) {
         super(control, new TableCellBehavior(control));
         
+        // RT-22038
+        Rectangle clip = new Rectangle();
+        clip.widthProperty().bind(widthProperty());
+        clip.heightProperty().bind(heightProperty());
+        setClip(clip);
+        // --- end of RT-22038
+        
         if (getSkinnable().getTableColumn() != null) {
             getSkinnable().getTableColumn().widthProperty().addListener(
                 new WeakInvalidationListener(weakColumnWidthListener));
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Wed Jun 06 16:37:04 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Thu Jun 07 13:43:46 2012 +1200
@@ -301,7 +301,7 @@
     private boolean isColumnReorderingEnabled() {
         // we only allow for column reordering if there are more than one column,
         // and if we are not on an embedded platform
-        return PlatformUtil.isEmbedded() && getTableView().getVisibleLeafColumns().size() > 1;
+        return ! PlatformUtil.isEmbedded() && getTableView().getVisibleLeafColumns().size() > 1;
     }
     
     private void initUI() {
@@ -763,7 +763,7 @@
 
         // Based on where the mouse actually is, we have to shuffle
         // where we want the column to end up. This code handles that.
-        int currentPos = getTableView().getVisibleLeafIndex(getTableColumn());
+        int currentPos = getIndex();
         newColumnPos += newColumnPos > currentPos && beforeMidPoint ?
             -1 : (newColumnPos < currentPos && !beforeMidPoint ? 1 : 0);
         
@@ -783,6 +783,13 @@
         getTableHeaderRow().setReordering(true);
     }
 
+    private int getIndex() {
+        ObservableList<TableColumn> columns = column.getParentColumn() == null ?
+            getTableView().getColumns() :
+            column.getParentColumn().getColumns();
+        return columns.indexOf(column);
+    }
+    
     protected void columnReorderingComplete(MouseEvent me) {
         // Move col from where it is now to the new position.
         moveColumn(getTableColumn(), newColumnPos);
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableHeaderRow.java	Wed Jun 06 16:37:04 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableHeaderRow.java	Thu Jun 07 13:43:46 2012 +1200
@@ -207,7 +207,6 @@
 
         updateTableWidth();
         table.widthProperty().addListener(weakTableWidthListener);
-        table.getVisibleLeafColumns().addListener(weakVisibleLeafColumnsListener);
 
         // --- popup menu for hiding/showing columns
         columnPopupMenu = new ContextMenu();
@@ -287,21 +286,12 @@
      *                                                                         *
      **************************************************************************/    
     
-    private boolean headerDirty = false;
-    
     private InvalidationListener tableWidthListener = new InvalidationListener() {
         @Override public void invalidated(Observable valueModel) {
             updateTableWidth();
         }
     };
     
-    private ListChangeListener visibleLeafColumnsListener = new ListChangeListener<TableColumn<?,?>>() {
-        @Override public void onChanged(Change<? extends TableColumn<?,?>> c) {
-            headerDirty = true;
-            requestLayout();
-        }
-    };
-    
     private final ListChangeListener tableColumnsListener = new ListChangeListener<TableColumn<?,?>>() {
         @Override public void onChanged(Change<? extends TableColumn<?,?>> c) {
             while (c.next()) {
@@ -313,9 +303,6 @@
     private final WeakInvalidationListener weakTableWidthListener = 
             new WeakInvalidationListener(tableWidthListener);
     
-    private final WeakListChangeListener weakVisibleLeafColumnsListener =
-            new WeakListChangeListener(visibleLeafColumnsListener);
-    
     private final WeakListChangeListener weakTableColumnsListener =
             new WeakListChangeListener(tableColumnsListener);
     
@@ -385,11 +372,6 @@
     }
 
     @Override protected void layoutChildren() {
-        if (headerDirty) {
-            header.setColumns(table.getColumns());
-            headerDirty = false;
-        }
-        
         double x = scrollX;
         double headerWidth = snapSize(header.prefWidth(-1));
         double prefHeight = getHeight() - getInsets().getTop() - getInsets().getBottom();
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableViewSkin.java	Wed Jun 06 16:37:04 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableViewSkin.java	Thu Jun 07 13:43:46 2012 +1200
@@ -451,7 +451,8 @@
         
         // painting the overlay over the column being reordered
         if (tableHeaderRow.getReorderingRegion() != null) {
-            TableColumn reorderingColumn = tableHeaderRow.getReorderingRegion().getTableColumn();
+            TableColumnHeader reorderingColumnHeader = tableHeaderRow.getReorderingRegion();
+            TableColumn reorderingColumn = reorderingColumnHeader.getTableColumn();
             if (reorderingColumn != null) {
                 Node n = tableHeaderRow.getReorderingRegion();
                 
@@ -460,7 +461,7 @@
                 // is off the left-side of the TableView (i.e. horizontal 
                 // scrolling has occured).
                 double minX = tableHeaderRow.sceneToLocal(n.localToScene(n.getBoundsInLocal())).getMinX();
-                double overlayWidth = reorderingColumn.getWidth();
+                double overlayWidth = reorderingColumnHeader.getWidth();
                 if (minX < 0) {
                     overlayWidth += minX;
                 }