changeset 2126:a2611f14ede8

RT-27167: [TreeTableView] autosizing for the first column is applied incorrectly: root arrows are not taken into account.
author jgiles
date Fri, 04 Jan 2013 10:07:03 +1300
parents bdd65f2577e8
children 39aa29468f43
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableCellSkinBase.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableCellSkin.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableViewSkin.java
diffstat 4 files changed, 52 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableCellSkinBase.java	Fri Jan 04 09:31:02 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableCellSkinBase.java	Fri Jan 04 10:07:03 2013 +1300
@@ -46,7 +46,7 @@
     // clicks result in the column being resized to fit the widest content in 
     // the column
     static final String DEFER_TO_PARENT_PREF_WIDTH = "deferToParentPrefWidth";
-    private boolean isDeferToParentForPrefWidth = false;
+    boolean isDeferToParentForPrefWidth = false;
     
     private InvalidationListener columnWidthListener = new InvalidationListener() {
         @Override public void invalidated(Observable valueModel) {
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Fri Jan 04 09:31:02 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Fri Jan 04 10:07:03 2013 +1300
@@ -644,8 +644,8 @@
                 R cell = cellsMap.get(col);
                 if (cell == null) continue;
 
+                updateCell(cell, skinnable);
                 cell.updateIndex(skinnableIndex);
-                updateCell(cell, skinnable);
                 cells.add(cell);
             }
 //        }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableCellSkin.java	Fri Jan 04 09:31:02 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableCellSkin.java	Fri Jan 04 10:07:03 2013 +1300
@@ -27,8 +27,12 @@
 import com.sun.javafx.scene.control.behavior.TreeTableCellBehavior;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.ReadOnlyDoubleProperty;
+import javafx.scene.Node;
+import javafx.scene.control.TreeItem;
 import javafx.scene.control.TreeTableCell;
 import javafx.scene.control.TreeTableColumn;
+import javafx.scene.control.TreeTableRow;
+import javafx.scene.control.TreeTableView;
 
 /**
  */
@@ -53,4 +57,39 @@
     @Override protected ReadOnlyDoubleProperty columnWidthProperty() {
         return tableColumn.widthProperty();
     }
+    
+    @Override protected double computePrefWidth(double height) {
+        if (isDeferToParentForPrefWidth) {
+            // RT-27167: we must take into account the disclosure node and the
+            // indentation (which is not taken into account by the LabeledSkinBase.
+            double ph = super.computePrefWidth(height);
+            
+            TreeTableRow treeTableRow = getSkinnable().getTreeTableRow();
+            if (treeTableRow != null) {
+                TreeItem treeItem = treeTableRow.getTreeItem();
+                if (treeItem != null) {
+                    int nodeLevel = TreeTableView.getNodeLevel(treeItem);
+                    if (!treeTableRow.getTreeTableView().isShowRoot()) nodeLevel--;
+                    
+                    // FIXME we're assuming an indent of 10px here, which is not
+                    // necessarily accurate as it is configurable via -fx-indent.
+                    // Unfortunately this value is stored in TreeTableRowSkin.
+                    ph += nodeLevel * 10;
+                    
+                    // Adding a little extra for padding
+                    ph += 10;
+
+                    // add in the width of the disclosure node, if one exists
+                    Node disclosureNode = treeTableRow.getDisclosureNode();
+                    if (disclosureNode != null) {
+                        double disclosureNodeWidth = disclosureNode.prefWidth(height);
+                        ph += disclosureNodeWidth;
+                    }
+                }
+            }
+            
+            return ph;
+        }
+        return columnWidthProperty().get();
+    }
 }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableViewSkin.java	Fri Jan 04 09:31:02 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableViewSkin.java	Fri Jan 04 10:07:03 2013 +1300
@@ -338,17 +338,27 @@
             padding = r.getInsets().getLeft() + r.getInsets().getRight();
         } 
         
+        TreeTableRow treeTableRow = new TreeTableRow();
+        treeTableRow.updateTreeTableView(treeTableView);
+        
         int rows = maxRows == -1 ? items.size() : Math.min(items.size(), maxRows);
         double maxWidth = 0;
         for (int row = 0; row < rows; row++) {
+            treeTableRow.updateIndex(row);
+            treeTableRow.updateTreeItem(treeTableView.getTreeItem(row));
+            
             cell.updateTreeTableColumn(col);
             cell.updateTreeTableView(treeTableView);
+            cell.updateTreeTableRow(treeTableRow);
             cell.updateIndex(row);
             
             if ((cell.getText() != null && !cell.getText().isEmpty()) || cell.getGraphic() != null) {
                 getChildren().add(cell);
                 cell.impl_processCSS(false);
-                maxWidth = Math.max(maxWidth, cell.prefWidth(-1));
+                
+                double w = cell.prefWidth(-1);
+                
+                maxWidth = Math.max(maxWidth, w);
                 getChildren().remove(cell);
             }
         }