}
private void maybeRenameSelectedProject() {
// determine which team project is selected. If none, abort.
PropertyKey projectNode = getSelectedTreeNode();
String projectPath = projectNode.path();
String templateID = ctx.getHierarchy().getID(projectNode);
if (!StringUtils.hasValue(templateID))
return;
// Create objects we will use in a dialog
String title = resources.getString("Rename.Title");
JTextField newPathField = new JTextField(projectPath);
Object message = resources.formatStrings("Rename.Message_Header_FMT",
projectPath);
message = new Object[] { message, " ", newPathField,
new JOptionPaneTweaker.GrabFocus(newPathField) };
while (true) {
// Show the user a dialog asking for the new path and name.
int userChoice = JOptionPane.showConfirmDialog(this, message,
title, JOptionPane.OK_CANCEL_OPTION);
// if the user didn't press the OK button, abort.
if (userChoice != JOptionPane.OK_OPTION)
return;
// get the new path in canonical form. If it was not absolute,
// interpret it relative to the current parent of the project.
String newPath = newPathField.getText().trim();
if (newPath.indexOf('/') == -1)
newPath = projectNode.getParent().path() + "/" + newPath;
newPath = DashHierarchy.scrubPath(newPath);
newPathField.setText(newPath);
// if the user didn't change the name, abort.
if (newPath.length() < 2 || newPath.equals(projectPath))
return;
// check for various error conditions.
if (projectAlreadyExists(newPath)) {
showInvalidRenameMessage("Rename.Duplicate_Name");
} else if (projectParentIsInvalid(newPath)) {
showInvalidRenameMessage("Rename.Invalid_Parent");
} else {
try {
// try performing the renaming operation.
HierarchyAlterer hierarchyAlterer = DashController
.getHierarchyAlterer();
hierarchyAlterer.renameNode(projectPath, newPath);
// if this caused the old parent of the project to become
// childless, delete that parent (and grandparent, etc)
PropertyKey oldParent = projectNode.getParent();
while (ctx.getHierarchy().getNumChildren(oldParent) == 0) {
hierarchyAlterer.deleteNode(oldParent.path());
oldParent = oldParent.getParent();
}
// point the "active task" at the renamed project.
PropertyKey newNode = ctx.getHierarchy().findExistingKey(
newPath);
if (newNode != null)
taskModel.setNode(newNode);
} catch (HierarchyAlterationException e) {