TreeUi: expand elements optimization
authorKirill Kalishev <kirill.kalishev@jetbrains.com>
Sun, 25 Oct 2009 09:11:36 +0000 (12:11 +0300)
committerKirill Kalishev <kirill.kalishev@jetbrains.com>
Sun, 25 Oct 2009 09:11:36 +0000 (12:11 +0300)
platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java

index c84a46b90cf4544a72c6b65778eaf465f5f48f33..297d342428796bfc18662195ce619e7bda82e0fe 100644 (file)
@@ -2803,17 +2803,29 @@ public class AbstractTreeUi {
           }
         });
 
-        for (final Object toExpand : element) {
-          _expand(toExpand, new Runnable() {
-            public void run() {
-              done.setDone();
-            }
-          }, parentsOnly, checkIfInStructure, canSmartExpand);
-        }
+        expandNext(element, 0, parentsOnly, checkIfInStructure, canSmartExpand, done);
       }
     });
   }
 
+  private void expandNext(final Object[] elements, final int index, final boolean parentsOnly, final boolean checkIfInStricture, final boolean canSmartExpand, final ActionCallback done) {
+    if (elements.length <= 0) {
+      done.setDone();
+      return;
+    }
+
+    if (index >= elements.length) {
+      return;
+    }
+
+    _expand(elements[index], new Runnable() {
+      public void run() {
+        done.setDone();
+        expandNext(elements, index + 1, parentsOnly, checkIfInStricture, canSmartExpand, done);
+      }
+    }, parentsOnly, checkIfInStricture, canSmartExpand);
+  }
+
   public void collapseChildren(final Object element, @Nullable final Runnable onDone) {
     runDone(new Runnable() {
       public void run() {