changeset 1415:e3ddeb5fe157

RT-23067: AIOOBE when expand one of selected nodes in TreeView
author jgiles
date Mon, 09 Jul 2012 10:12:44 +1200
parents 330911490952
children 2e3e8a90f8c0
files javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java
diffstat 1 files changed, 15 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java	Mon Jul 09 10:12:06 2012 +1200
+++ b/javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java	Mon Jul 09 10:12:44 2012 +1200
@@ -212,7 +212,6 @@
     protected abstract int getFocusedIndex();
     
     
-    // FIXME not optimal: each shift requires a whole new loop
     // package only
     void shiftSelection(int position, int shift) {
         // with no check here, we get RT-15024
@@ -228,26 +227,23 @@
         int idx = 0;
         
         if (shift > 0) {
-            for (int iter = 0; iter < shift; iter++) {
-                for (int i = selectedIndicesSize - 1; i >= position && i >= 0; i--) {
-                    boolean selected = selectedIndices.get(i);
-                    selectedIndices.set(i+1, selected);
-                    
-                    if (selected) {
-                        perm[idx++] = i + 1;
-                    }
+            for (int i = selectedIndicesSize - 1; i >= position && i >= 0; i--) {
+                boolean selected = selectedIndices.get(i);
+                selectedIndices.set(i + shift, selected);
+
+                if (selected) {
+                    perm[idx++] = i + 1;
                 }
-                selectedIndices.clear(position);
-             }
+            }
+            selectedIndices.clear(position);
         } else if (shift < 0) {
-            for (int iter = 0; iter < Math.abs(shift); iter++) {
-                for (int i = position; i < selectedIndicesSize; i++) {
-                    boolean selected = selectedIndices.get(i + 1);
-                    selectedIndices.set(i, selected);
-                    
-                    if (selected) {
-                        perm[idx++] = i;
-                    }
+            for (int i = position; i < selectedIndicesSize; i++) {
+                if ((i + shift) < 0) continue;
+                boolean selected = selectedIndices.get(i + 1);
+                selectedIndices.set(i + 1 + shift, selected);
+
+                if (selected) {
+                    perm[idx++] = i;
                 }
             }
         }