'Project Structure' dialog: fix moving module node to a group node if it was initially located directly the tree root

This commit is contained in:
nik
2017-01-18 11:25:23 +03:00
parent 0339448167
commit 06f8aa8d6f
@@ -650,34 +650,32 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
@Override
protected void reloadNode(DefaultTreeModel treeModel) {
TreeNode parent = getParent();
if (parent instanceof ModuleGroupNode) {
List<String> actualPath = ((ModuleGroupNode)parent).myModuleGroup.getGroupPathList();
List<String> 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<String> actualPath = parent instanceof ModuleGroupNode ? ((ModuleGroupNode)parent).myModuleGroup.getGroupPathList() : Collections.emptyList();
List<String> 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);
}