From 06f8aa8d6fd878d8a7ec6dbd459206805f0d6a8a Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 18 Jan 2017 11:01:38 +0300 Subject: [PATCH] 'Project Structure' dialog: fix moving module node to a group node if it was initially located directly the tree root --- .../ModuleStructureConfigurable.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java index 07e45e8d4aa6..63a162ae9068 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/ModuleStructureConfigurable.java @@ -650,34 +650,32 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple @Override protected void reloadNode(DefaultTreeModel treeModel) { TreeNode parent = getParent(); - if (parent instanceof ModuleGroupNode) { - List actualPath = ((ModuleGroupNode)parent).myModuleGroup.getGroupPathList(); - List expectedPath = myGrouper.getGroupPath(getModule()); - if (!actualPath.equals(expectedPath)) { - TreePath path = myTree.getSelectionPath(); - boolean wasSelected = path != null && this.equals(path.getLastPathComponent()); - boolean autoScrollWasEnabled = myAutoScrollEnabled; - try { - myAutoScrollEnabled = false; - MyNode newParent = getOrCreateModuleGroupNode(expectedPath, treeModel); - treeModel.removeNodeFromParent(this); - while (parent instanceof ModuleGroupNode && parent.getChildCount() == 0) { - TreeNode grandParent = parent.getParent(); - treeModel.removeNodeFromParent((MutableTreeNode)parent); - parent = grandParent; - } + List actualPath = parent instanceof ModuleGroupNode ? ((ModuleGroupNode)parent).myModuleGroup.getGroupPathList() : Collections.emptyList(); + List expectedPath = myGrouper.getGroupPath(getModule()); + if (!actualPath.equals(expectedPath)) { + TreePath path = myTree.getSelectionPath(); + boolean wasSelected = path != null && this.equals(path.getLastPathComponent()); + boolean autoScrollWasEnabled = myAutoScrollEnabled; + try { + myAutoScrollEnabled = false; + MyNode newParent = getOrCreateModuleGroupNode(expectedPath, treeModel); + treeModel.removeNodeFromParent(this); + while (parent instanceof ModuleGroupNode && parent.getChildCount() == 0) { + TreeNode grandParent = parent.getParent(); + treeModel.removeNodeFromParent((MutableTreeNode)parent); + parent = grandParent; + } - newParent.add(this); - treeModel.nodesWereInserted(newParent, new int[] {newParent.getChildCount()-1}); - if (wasSelected) { - myTree.expandPath(TreeUtil.getPath(myRoot, newParent)); - myTree.setSelectionPath(TreeUtil.getPath(myRoot, this)); - } - } - finally { - myAutoScrollEnabled = autoScrollWasEnabled; + newParent.add(this); + treeModel.nodesWereInserted(newParent, new int[] {newParent.getChildCount()-1}); + if (wasSelected) { + myTree.expandPath(TreeUtil.getPath(myRoot, newParent)); + myTree.setSelectionPath(TreeUtil.getPath(myRoot, this)); } } + finally { + myAutoScrollEnabled = autoScrollWasEnabled; + } } super.reloadNode(treeModel); }