changeset 1248:29dd9c8675ec

RT-21341: TableView: Moving column to the left of next column moves it to the right of the next column
author jgiles
date Thu, 07 Jun 2012 11:13:11 +1200
parents 0f911a5c52bb
children 9897f5b8a23d
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableViewSkin.java
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Wed Jun 06 13:09:31 2012 +1200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Thu Jun 07 11:13:11 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/TableViewSkin.java	Wed Jun 06 13:09:31 2012 +1200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableViewSkin.java	Thu Jun 07 11:13:11 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;
                 }