Merge branch 'master' of git@git.labs.intellij.net:idea/community
authorKirill Kalishev <kirill.kalishev@jetbrains.com>
Fri, 27 Nov 2009 12:46:59 +0000 (15:46 +0300)
committerKirill Kalishev <kirill.kalishev@jetbrains.com>
Fri, 27 Nov 2009 12:46:59 +0000 (15:46 +0300)
platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java
platform/platform-api/src/com/intellij/ide/util/treeView/UpdaterTreeState.java

index 07a589023ddbc7b9748e959d0e8d1ec7330c621c..b670e0812c13d492643f9cfb675932e0368a6025 100644 (file)
@@ -928,7 +928,7 @@ public class AbstractTreeUi {
         }
 
         if (isSelectionInside(node)) {
-          addSelectionPath(getPathFor(node), true, Condition.TRUE);
+          addSelectionPath(getPathFor(node), true, Condition.TRUE, null);
         }
 
         doWithUpdaterState(new Runnable() {
@@ -2095,7 +2095,7 @@ public class AbstractTreeUi {
     DefaultMutableTreeNode node = getNodeForElement(disposedElement, false);
     if (node != null && isValidForSelectionAdjusting(node)) {
       Object newElement = getElementFor(node);
-      addSelectionPath(getPathFor(node), true, getExpiredElementCondition(newElement));
+      addSelectionPath(getPathFor(node), true, getExpiredElementCondition(newElement), disposedElement);
       return;
     }
 
@@ -2105,18 +2105,18 @@ public class AbstractTreeUi {
         if (parentNode.getChildCount() > selectedIndex) {
           TreeNode newChildNode = parentNode.getChildAt(selectedIndex);
           if (isValidForSelectionAdjusting(newChildNode)) {
-            addSelectionPath(new TreePath(myTreeModel.getPathToRoot(newChildNode)), true, getExpiredElementCondition(disposedElement));
+            addSelectionPath(new TreePath(myTreeModel.getPathToRoot(newChildNode)), true, getExpiredElementCondition(disposedElement), disposedElement);
           }
         }
         else {
           TreeNode newChild = parentNode.getChildAt(parentNode.getChildCount() - 1);
           if (isValidForSelectionAdjusting(newChild)) {
-            addSelectionPath(new TreePath(myTreeModel.getPathToRoot(newChild)), true, getExpiredElementCondition(disposedElement));
+            addSelectionPath(new TreePath(myTreeModel.getPathToRoot(newChild)), true, getExpiredElementCondition(disposedElement), disposedElement);
           }
         }
       }
       else {
-        addSelectionPath(new TreePath(myTreeModel.getPathToRoot(parentNode)), true, getExpiredElementCondition(disposedElement));
+        addSelectionPath(new TreePath(myTreeModel.getPathToRoot(parentNode)), true, getExpiredElementCondition(disposedElement), disposedElement);
       }
     }
   }
@@ -2146,7 +2146,7 @@ public class AbstractTreeUi {
     };
   }
 
-  private void addSelectionPath(final TreePath path, final boolean isAdjustedSelection, final Condition isExpiredAdjustement) {
+  private void addSelectionPath(final TreePath path, final boolean isAdjustedSelection, final Condition isExpiredAdjustement, @Nullable final Object adjustmentCause) {
     doWithUpdaterState(new Runnable() {
       public void run() {
         TreePath toSelect = null;
@@ -2171,7 +2171,7 @@ public class AbstractTreeUi {
 
           if (isAdjustedSelection && myUpdaterState != null) {
             final Object toSelectElement = getElementFor(toSelect.getLastPathComponent());
-            myUpdaterState.addAdjustedSelection(toSelectElement, isExpiredAdjustement);
+            myUpdaterState.addAdjustedSelection(toSelectElement, isExpiredAdjustement, adjustmentCause);
           }
         }
       }
@@ -2737,7 +2737,7 @@ public class AbstractTreeUi {
     for (Object each : selection) {
       DefaultMutableTreeNode node = getNodeForElement(each, false);
       if (node != null && isValidForSelectionAdjusting(node)) {
-        addSelectionPath(getPathFor(node), false, null);
+        addSelectionPath(getPathFor(node), false, null, null);
       }
     }
   }
@@ -3204,7 +3204,7 @@ public class AbstractTreeUi {
   }
 
   private void dropUpdaterStateIfExternalChange() {
-    if (myUpdaterState != null && !myUpdaterState.isProcessingNow()) {
+   if (myUpdaterState != null && !myUpdaterState.isProcessingNow()) {
       clearUpdaterState();
     }
   }
@@ -3470,7 +3470,7 @@ public class AbstractTreeUi {
       }
 
       if (pathToSelect != null && myTree.isSelectionEmpty()) {
-        addSelectionPath(pathToSelect, true, Condition.FALSE);
+        addSelectionPath(pathToSelect, true, Condition.FALSE, null);
       }
     }
 
index eb2faef6e42e3a227ab7defbe7696fa1360dcb63..885d45b5e4a327015dd1af87bf5ab2bf76066b2e 100644 (file)
@@ -37,6 +37,8 @@ public class UpdaterTreeState {
 
   private boolean myCanRunRestore = true;
 
+  private WeakHashMap<Object, Object> myAdjustmentCause2Adjustment = new WeakHashMap<Object, Object>();
+
   public UpdaterTreeState(AbstractTreeUi ui) {
     myUi = ui;
 
@@ -192,7 +194,7 @@ public class UpdaterTreeState {
             if (!children.contains(eachToSelect)) {
               toSelect.remove();
               if (!myToSelect.containsKey(readyElement) && !myUi.getSelectedElements().contains(eachToSelect)) {
-                addAdjustedSelection(eachToSelect, Condition.FALSE);
+                addAdjustedSelection(eachToSelect, Condition.FALSE, null);
               }
             }
           }
@@ -257,7 +259,7 @@ public class UpdaterTreeState {
               if (myUi.isInStructure(o) && !adjusted.get(o).value(o)) {
                 hangByParent.add(o);
               } else {
-                addAdjustedSelection(o, adjusted.get(o));
+                addAdjustedSelection(o, adjusted.get(o), null);
               }
               return null;
             }
@@ -278,7 +280,12 @@ public class UpdaterTreeState {
 
     ActionCallback result = new ActionCallback(elements.size());
     for (Iterator<Object> iterator = elements.iterator(); iterator.hasNext();) {
-      processHangByParent(iterator.next()).notify(result);
+      Object hangElement = iterator.next();
+      if (!myAdjustmentCause2Adjustment.containsKey(hangElement)) {
+        processHangByParent(hangElement).notify(result);
+      } else {
+        result.setDone();
+      }
     }
     return result;
   }
@@ -329,8 +336,11 @@ public class UpdaterTreeState {
     myToSelect.put(element, element);
   }
 
-  public void addAdjustedSelection(final Object element, Condition isExpired) {
+  public void addAdjustedSelection(final Object element, Condition isExpired, @Nullable Object adjustmentCause) {
     myAdjustedSelection.put(element, isExpired);
+    if (adjustmentCause != null) {
+      myAdjustmentCause2Adjustment.put(adjustmentCause, element);
+    }
   }
 
   @Override
@@ -348,4 +358,9 @@ public class UpdaterTreeState {
       myUi.maybeReady();
     }
   }
+
+  public void removeFromSelection(Object element) {
+    myToSelect.remove(element);
+    myAdjustedSelection.remove(element);
+  }
 }