use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.
the class HierarchyEditor method canPaste.
private boolean canPaste(String parentID, String parentPath, Vector templateChildren, DefaultMutableTreeNode cutNode) {
if (parentID == null || parentPath == null || cutNode == null || (templateChildren != null && templateChildren.size() == 0))
return false;
PropertyKey cutKey = treeModel.getPropKey(useProps, cutNode.getPath());
String cutPath = cutKey.path();
// disallow pasting a node into itself.
if (cutPath.equals(parentPath) || // create an illegal recursive tree.
parentPath.startsWith(cutPath + "/") || // already lives there!)
parentPath.equals(cutKey.getParent().path()))
return false;
Prop cutProp = useProps.pget(cutKey);
String cutID = cutProp.getID();
/* match child with parent's allowed child list, if any */
if (templateChildren != null && !templateChildren.contains(cutID))
return false;
/* match parent with child's required parent list, if any */
String cutStatus = cutProp.getStatus();
if (cutStatus == null)
return true;
/* no required parent */
int idx = cutStatus.indexOf(REQUIRED_PARENT);
if (idx == -1)
return true;
/* no required parent */
StringTokenizer st = new StringTokenizer(cutStatus.substring(idx + 1), String.valueOf(REQUIRED_PARENT));
while (st.hasMoreElements()) /* matches required parent */
if (parentID.equals(st.nextElement()))
return true;
// moved under arbitrary plain nodes
if ((cutID.endsWith("/IndivRoot") || cutID.endsWith("/Indiv2Root")) && "".equals(parentID))
return true;
return false;
}
use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.
the class HierarchyEditor method treeNodesRemoved.
public void treeNodesRemoved(TreeModelEvent e) {
Object[] path = e.getPath();
int[] indices = e.getChildIndices();
PropertyKey parent = treeModel.getPropKey(useProps, path);
// (haven't seen mult nodes yet, either...)
for (int nodeIdx = 0; nodeIdx < indices.length; nodeIdx++) {
useProps.removeChildKey(parent, indices[nodeIdx]);
}
setDirty(true);
}
use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.
the class EditSubprojectList method ensureMasterProject.
private void ensureMasterProject() throws TinyCGIException {
DashHierarchy hierarchy = getPSPProperties();
PropertyKey key = hierarchy.findExistingKey(getPrefix());
String templateID = hierarchy.getID(key);
if (templateID == null || !templateID.endsWith(MASTER_ROOT))
throw new TinyCGIException(403, "Not a Master Project");
}
use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.
the class TeamProjectBrowser method maybeRenameSelectedProject.
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) {
e.printStackTrace();
}
return;
}
}
}
use of net.sourceforge.processdash.hier.PropertyKey in project processdash by dtuma.
the class TeamProjectBrowser method updateTreeSelectionFromActiveTask.
private void updateTreeSelectionFromActiveTask() {
PropertyKey activeTask = taskModel.getNode();
setSelectedTreeNode(activeTask);
}
Aggregations