void () { PsiPackage selectedPackage = getTreeSelection(); if (selectedPackage == null) return; String newPackageName = Messages.showInputDialog( myProject, IdeBundle.message("prompt.enter.a.new.package.name"), IdeBundle.message("title.new.package"), null, "", new InputValidator() { @Override public boolean checkInput(String inputString) { return inputString != null && !inputString.isEmpty(); } @Override public boolean canClose(String inputString) { return checkInput(inputString); } } ); if (newPackageName == null) return; CommandProcessor.getInstance().executeCommand(myProject, () -> { Runnable action = () -> { try { String newQualifiedName = selectedPackage.getQualifiedName(); if (!Comparing.strEqual(newQualifiedName,"")) newQualifiedName += "."; newQualifiedName += newPackageName; PsiPackage newPackage = getPsiPackage(newQualifiedName); if (newPackage != null) { DefaultMutableTreeNode newChild = addPackage(new PackageUpdate(newPackage)); DefaultTreeModel model = (DefaultTreeModel)myTree.getModel(); model.nodeStructureChanged((TreeNode)model.getRoot()); TreePath path = new TreePath(newChild.getPath()); myTree.setSelectionPath(path); myTree.scrollPathToVisible(path); myTree.expandPath(path); } } catch (IncorrectOperationException e) { Messages.showMessageDialog( getContentPane(), StringUtil.getMessage(e), CommonBundle.getErrorTitle(), Messages.getErrorIcon() ); LOG.debug(e); } }; ApplicationManager.getApplication().runReadAction(action); }, IdeBundle.message("command.create.new.package"), null); }