Project Structure: do single sort and redraw when adding multiple nodes to a UI Tree
authorJim Purbrick <jimp@fb.com>
Tue, 7 Jul 2015 11:24:35 +0000 (14:24 +0300)
committernik <Nikolay.Chashnikov@jetbrains.com>
Wed, 8 Jul 2015 17:42:44 +0000 (20:42 +0300)
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetEditorFacadeImpl.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FacetStructureConfigurable.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java
platform/platform-api/src/com/intellij/openapi/ui/MasterDetailsComponent.java

index 376abb0751aa334caab679a5e48a1bbd9b7547e0..db72e479f79d63347a4792d562dce542867c39f9 100644 (file)
@@ -66,7 +66,7 @@ public class FacetEditorFacadeImpl implements FacetEditorFacade {
     final FacetStructureConfigurable facetStructureConfigurable = FacetStructureConfigurable.getInstance(myStructureConfigurable.getProject());
     final MasterDetailsComponent.MyNode facetTypeNode = facetStructureConfigurable.getOrCreateFacetTypeNode(facet.getType());
     LOG.assertTrue(facetTypeNode != null, "Cannot found node for " + facet.getType());
-    facetStructureConfigurable.addFacetNode(facetTypeNode, facet, this);
+    facetStructureConfigurable.addFacetNode(facetTypeNode, facet, this, false);
   }
 
   private MasterDetailsComponent.MyNode addFacetNode(final Facet facet, final MasterDetailsComponent.MyNode moduleNode) {
index d5248a55e7add97334d47e2695fa1d9d9b390348..b8027eccbabe894d9193526f64a9eac4ae9b3ae7 100644 (file)
@@ -175,9 +175,10 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
       Collection<? extends Facet> facets = FacetManager.getInstance(module).getFacetsByType(facetType.getId());
       FacetEditorFacadeImpl editorFacade = ModuleStructureConfigurable.getInstance(myProject).getFacetEditorFacade();
       for (Facet facet : facets) {
-        addFacetNode(facetTypeNode, facet, editorFacade);
+        addFacetNode(facetTypeNode, facet, editorFacade, true);
       }
     }
+    addNodeCompleted(facetTypeNode);
     return facetTypeNode;
   }
 
@@ -202,9 +203,13 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
     return addFacetTypeNode(facetType);
   }
 
-  public void addFacetNode(@NotNull MyNode facetTypeNode, @NotNull Facet facet, @NotNull FacetEditorFacadeImpl editorFacade) {
+  public void addFacetNode(
+    @NotNull MyNode facetTypeNode,
+    @NotNull Facet facet,
+    @NotNull FacetEditorFacadeImpl editorFacade,
+    boolean delayRedraw) {
     FacetConfigurable facetConfigurable = editorFacade.getOrCreateConfigurable(facet);
-    addNode(new FacetConfigurableNode(facetConfigurable), facetTypeNode);
+    addNode(new FacetConfigurableNode(facetConfigurable), facetTypeNode, delayRedraw);
     myContext.getDaemonAnalyzer().queueUpdate(new FacetProjectStructureElement(myContext, facet));
   }
 
index 6bab039159d1389857d6a7753cae70133e1e1d62..6eebd449f58eee364873b4f13b805fb2c4e5cfe2 100644 (file)
@@ -144,6 +144,10 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
     super.addNode(nodeToAdd, parent);
   }
 
+  public void addNode(MyNode nodeToAdd, MyNode parent, boolean delayRedraw) {
+    super.addNode(nodeToAdd, parent, delayRedraw);
+  }
+
   @Override
   @NotNull
   protected ArrayList<AnAction> createActions(final boolean fromPopup) {
@@ -230,14 +234,14 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
       }
       final String[] groupPath = myPlainMode ? null : myContext.myModulesConfigurator.getModuleModel().getModuleGroupPath(module);
       if (groupPath == null || groupPath.length == 0){
-        addNode(moduleNode, myRoot);
+        addNode(moduleNode, myRoot, true);
       } else {
         final MyNode moduleGroupNode = ModuleGroupUtil
           .buildModuleGroupPath(new ModuleGroup(groupPath), myRoot, moduleGroup2NodeMap,
                                 new Consumer<ModuleGroupUtil.ParentChildRelation<MyNode>>() {
                                   @Override
                                   public void consume(final ModuleGroupUtil.ParentChildRelation<MyNode> parentChildRelation) {
-                                    addNode(parentChildRelation.getChild(), parentChildRelation.getParent());
+                                    addNode(parentChildRelation.getChild(), parentChildRelation.getParent(), true);
                                   }
                                 },
                                 new Function<ModuleGroup, MyNode>() {
@@ -248,9 +252,10 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
                                     return new MyNode(moduleGroupConfigurable, true);
                                   }
                                 });
-        addNode(moduleNode, moduleGroupNode);
+        addNode(moduleNode, moduleGroupNode, true);
       }
     }
+    addNodeCompleted(myRoot);
     if (myProject.isDefault()) {  //do not add modules node in case of template project
       myRoot.removeAllChildren();
     }
index 52f763ee0e10fcc720a25a427d9580a6db3ace94..45ed57353228ccb7bf49d1626e794c0bcf9001ec 100644 (file)
@@ -584,6 +584,18 @@ public abstract class MasterDetailsComponent implements Configurable, DetailsCom
     ((DefaultTreeModel)myTree.getModel()).reload(parent);
   }
 
+  protected void addNode(MyNode nodeToAdd, MyNode parent, boolean delayRedraw) {
+    parent.add(nodeToAdd);
+    if (!delayRedraw) {
+      addNodeCompleted(parent);
+    }
+  }
+
+  protected void addNodeCompleted(MyNode parent) {
+    TreeUtil.sort(parent, getNodeComparator());
+    ((DefaultTreeModel)myTree.getModel()).reload(parent);
+  }
+
   protected Comparator<MyNode> getNodeComparator() {
     return new Comparator<MyNode>() {
       public int compare(final MyNode o1, final MyNode o2) {