changeset 2160:c610fbaec190

RT-27532: TableView - when a sorted column is dragged to a new position it loses its sorting order (fixed for 8.0)
author jgiles
date Tue, 08 Jan 2013 08:10:54 +1300
parents 81b9d4acd03e
children 0aecb8c1f453
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java javafx-ui-controls/src/javafx/scene/control/TableView.java javafx-ui-controls/src/javafx/scene/control/TreeTableView.java
diffstat 3 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Fri Jan 04 22:41:17 2013 +1300
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Tue Jan 08 08:10:54 2013 +1300
@@ -299,6 +299,7 @@
     private boolean isSortColumn;
     
     private boolean isSizeDirty = false;
+    private boolean sortOrderDotsDirty = false;
     
     boolean isLastVisibleColumn = false;
     private int columnIndex = -1;
@@ -465,7 +466,7 @@
                 GridPane.setHalignment(arrow, HPos.CENTER);
                 sortArrowGrid.add(sortOrderDots, 1, dotsRow);
 
-                updateSortOrderDots(sortPos);
+                sortOrderDotsDirty = true;
             } else {
                 // only show the arrow
                 sortArrowGrid.add(arrow, 1, 1);
@@ -620,6 +621,9 @@
         if (isSizeDirty) {
             resize(getTableColumn().getWidth(), getHeight());
             isSizeDirty = false;
+        } else if (sortOrderDotsDirty) {
+            updateSortOrderDots(sortPos);
+            sortOrderDotsDirty = false;
         }
         
         double sortWidth = 0;
@@ -780,7 +784,7 @@
     protected void columnReorderingComplete(MouseEvent me) {
         // Move col from where it is now to the new position.
         moveColumn(getTableColumn(), newColumnPos);
-
+        
         // cleanup
         getTableHeaderRow().getColumnReorderLine().setTranslateX(0.0F);
         getTableHeaderRow().getColumnReorderLine().setLayoutX(0.0F);
--- a/javafx-ui-controls/src/javafx/scene/control/TableView.java	Fri Jan 04 22:41:17 2013 +1300
+++ b/javafx-ui-controls/src/javafx/scene/control/TableView.java	Tue Jan 08 08:10:54 2013 +1300
@@ -455,16 +455,21 @@
             
             // Fix for RT-15194: Need to remove removed columns from the 
             // sortOrder list.
+            List<TableColumn> toRemove = new ArrayList<TableColumn>();
             while (c.next()) {
                 TableUtil.removeColumnsListener(c.getRemoved(), weakColumnsObserver);
                 TableUtil.addColumnsListener(c.getAddedSubList(), weakColumnsObserver);
                 
                 if (c.wasRemoved()) {
-                    for (int i = 0; i < c.getRemovedSize(); i++) {
-                        getSortOrder().remove(c.getRemoved().get(i));
-                    }
+                    toRemove.addAll(c.getRemoved());
+                }
+                
+                if (c.wasAdded()) {
+                    toRemove.removeAll(c.getAddedSubList());
                 }
             }
+            
+            sortOrder.removeAll(toRemove);
         }
     };
     
--- a/javafx-ui-controls/src/javafx/scene/control/TreeTableView.java	Fri Jan 04 22:41:17 2013 +1300
+++ b/javafx-ui-controls/src/javafx/scene/control/TreeTableView.java	Tue Jan 08 08:10:54 2013 +1300
@@ -549,16 +549,21 @@
             
             // Fix for RT-15194: Need to remove removed columns from the 
             // sortOrder list.
+            List<TreeTableColumn> toRemove = new ArrayList<TreeTableColumn>();
             while (c.next()) {
                 TableUtil.removeColumnsListener(c.getRemoved(), weakColumnsObserver);
                 TableUtil.addColumnsListener(c.getAddedSubList(), weakColumnsObserver);
                 
                 if (c.wasRemoved()) {
-                    for (int i = 0; i < c.getRemovedSize(); i++) {
-                        getSortOrder().remove(c.getRemoved().get(i));
-                    }
+                    toRemove.addAll(c.getRemoved());
+                }
+                
+                if (c.wasAdded()) {
+                    toRemove.removeAll(c.getAddedSubList());
                 }
             }
+            
+            sortOrder.removeAll(toRemove);
         }
     };