changeset 2119:e250d9838c53

RT-26505: Allow for configurable treeColumn property on TreeTableView
author jgiles
date Thu, 03 Jan 2013 10:20:38 +1300
parents 5a8bfca33b50
children d59e349b4963
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableRowSkin.java javafx-ui-controls/src/javafx/scene/control/TreeTableView.java
diffstat 3 files changed, 76 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Thu Jan 03 09:45:55 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Thu Jan 03 10:20:38 2013 +1300
@@ -83,6 +83,10 @@
     protected boolean isIndentationRequired() {
         return false;
     }
+    
+    protected TableColumnBase getTreeColumn() {
+        return null;
+    }
 
     protected Node getDisclosureNode() {
         return null;
@@ -163,14 +167,9 @@
     
     private int fullRefreshCounter = DEFAULT_FULL_REFRESH_COUNTER;
 
-//    protected boolean showColumns = true;
-    
     protected boolean isDirty = false;
     protected boolean updateCells = false;
     
-//    private TableView<T> tableView;
-//    private TableViewSkin tableViewSkin;
-    
     private final double fixedCellLength;
     private final boolean fixedCellLengthEnabled;
     
@@ -182,9 +181,7 @@
     };
     
     // spanning support
-//    private CellSpanTableView<T> cellSpanTableView;
     protected SpanModel spanModel;
-//    private static final Map<TableView, SpanType[][]> spanMap = new WeakHashMap<TableView, SpanType[][]>();
     
     // supports variable row heights
     public static <C extends IndexedCell> double getTableRowHeight(int index, C tableRow) {
@@ -368,19 +365,6 @@
         }
     }
 
-//    private void updateShowColumns() {
-//        boolean newValue = (isIgnoreText() && isIgnoreGraphic());
-//        if (showColumns == newValue) return;
-//        
-//        showColumns = newValue;
-////        showColumns = true;
-//        
-//        System.out.println("showColumns is " + showColumns + " for row " + getSkinnable().getIndex());
-//
-//        updateCells = true;
-//        requestLayout();
-//    }
-    
     @Override protected void layoutChildren(double x, final double y,
             double w, final double h) {
         
@@ -395,7 +379,9 @@
         
         if (cellsMap.isEmpty()) return;
         
-        if (/*showColumns && */! getVisibleLeafColumns().isEmpty()) {
+        
+        ObservableList<? extends TableColumnBase> visibleLeafColumns = getVisibleLeafColumns();
+        if (! visibleLeafColumns.isEmpty()) {
             
             ///////////////////////////////////////////
             // indentation code starts here
@@ -404,14 +390,21 @@
             double disclosureWidth = 0;
             boolean indentationRequired = isIndentationRequired();
             boolean disclosureVisible = isDisclosureNodeVisible();
+            int indentationColumnIndex = 0;
+            Node disclosureNode = null;
             if (indentationRequired) {
+                // Determine the column in which we want to put the disclosure node.
+                // By default it is null, which means the 0th column should be
+                // where the indentation occurs.
+                TableColumnBase treeColumn = getTreeColumn();
+                indentationColumnIndex = treeColumn == null ? 0 : visibleLeafColumns.indexOf(treeColumn);
+                indentationColumnIndex = indentationColumnIndex < 0 ? 0 : indentationColumnIndex;
+                
                 int indentationLevel = getIndentationLevel(getSkinnable());
                 if (! isShowRoot()) indentationLevel--;
                 final double indentationPerLevel = getIndentationPerLevel();
                 leftMargin = indentationLevel * indentationPerLevel;
             
-                x += leftMargin;
-                
                 // position the disclosure node so that it is at the proper indent
                 Control c = getVirtualFlowOwner();
                 final double defaultDisclosureWidth = maxDisclosureWidthMap.containsKey(c) ?
@@ -419,25 +412,12 @@
                 disclosureWidth = defaultDisclosureWidth;
 
                 if (disclosureVisible) {
-                    Node disclosureNode = getDisclosureNode();
+                    disclosureNode = getDisclosureNode();
                     disclosureWidth = disclosureNode.prefWidth(-1);
                     if (disclosureWidth > defaultDisclosureWidth) {
                         maxDisclosureWidthMap.put(c, disclosureWidth);
                     }
-
-                    double ph = disclosureNode.prefHeight(-1);
-
-                    disclosureNode.resize(disclosureWidth, ph);
-                    positionInArea(disclosureNode, x, y,
-                            disclosureWidth, h, /*baseline ignored*/0,
-                            HPos.CENTER, VPos.CENTER);
                 }
-
-                // determine starting point of the graphic or cell node, and the
-                // remaining width available to them
-                final int padding = getGraphic() == null ? 0 : 3;
-                x += disclosureWidth + padding;
-                w -= (leftMargin + disclosureWidth + padding);
             }
             ///////////////////////////////////////////
             // indentation code ends here
@@ -488,6 +468,30 @@
                     }
                     
                     ///////////////////////////////////////////
+                    // further indentation code starts here
+                    ///////////////////////////////////////////
+                    if (indentationRequired && column == indentationColumnIndex) {
+                        x += leftMargin;
+                        
+                        if (disclosureVisible) {
+                            double ph = disclosureNode.prefHeight(-1);
+                            disclosureNode.resize(disclosureWidth, ph);
+                            positionInArea(disclosureNode, x, y,
+                                    disclosureWidth, h, /*baseline ignored*/0,
+                                    HPos.CENTER, VPos.CENTER);
+                        }
+                        
+                        // determine starting point of the graphic or cell node, and the
+                        // remaining width available to them
+                        final int padding = getGraphic() == null ? 0 : 3;
+                        x += disclosureWidth + padding;
+                        w -= (leftMargin + disclosureWidth + padding);
+                    }
+                    ///////////////////////////////////////////
+                    // further indentation code ends here
+                    ///////////////////////////////////////////
+                    
+                    ///////////////////////////////////////////
                     // cell spanning code starts here
                     ///////////////////////////////////////////
                     if (spanModel != null) {
@@ -540,12 +544,16 @@
                     ///////////////////////////////////////////
                     
                     // a little bit more special code for indentation purposes
-                    if (indentationRequired && column == 0) {
+                    if (indentationRequired && column == indentationColumnIndex) {
                         tableCell.resize(width - leftMargin - disclosureWidth, height);
-                        tableCell.relocate(x, insets.getTop());
                     } else {
                         tableCell.resize(width, height);
+                    }
+
+                    if (indentationRequired && column > indentationColumnIndex) {
                         tableCell.relocate(x - leftMargin - disclosureWidth, insets.getTop());
+                    } else {
+                        tableCell.relocate(x, insets.getTop());
                     }
                 } else {
                     if (fixedCellLengthEnabled) {
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableRowSkin.java	Thu Jan 03 09:45:55 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeTableRowSkin.java	Thu Jan 03 10:20:38 2013 +1300
@@ -176,6 +176,10 @@
     @Override protected boolean isIndentationRequired() {
         return true;
     }
+
+    @Override protected TableColumnBase getTreeColumn() {
+        return getSkinnable().getTreeTableView().getTreeColumn();
+    }
     
     @Override protected int getIndentationLevel(TreeTableRow<T> control) {
         return TreeTableView.getNodeLevel(control.getTreeItem());
--- a/javafx-ui-controls/src/javafx/scene/control/TreeTableView.java	Thu Jan 03 09:45:55 2013 +1300
+++ b/javafx-ui-controls/src/javafx/scene/control/TreeTableView.java	Thu Jan 03 10:20:38 2013 +1300
@@ -692,6 +692,31 @@
     }
     
     
+    
+    // --- Tree Column
+    private ObjectProperty<TreeTableColumn<S,?>> treeColumn;
+    /**
+     * Property that represents which column should have the disclosure node
+     * shown in it (that is, the column with the arrow). By default this will be
+     * the left-most column if this property is null, otherwise it will be the
+     * specified column assuming it is non-null and contained within the 
+     * {@link #getVisibleLeafColumns() visible leaf columns} list.
+     */
+    public final ObjectProperty<TreeTableColumn<S,?>> treeColumnProperty() {
+        if (treeColumn == null) {
+            treeColumn = new SimpleObjectProperty<TreeTableColumn<S,?>>(this, "treeColumn", null);
+        }
+        return treeColumn;
+    }
+    public final void setTreeColumn(TreeTableColumn<S,?> value) {
+        treeColumnProperty().set(value);
+    }
+    public final TreeTableColumn<S,?> getTreeColumn() {
+        return treeColumn == null ? null : treeColumn.get();
+    }
+    
+    
+    
     // --- Selection Model
     private ObjectProperty<TreeTableViewSelectionModel<S>> selectionModel;