DefaultMutableTreeNode node = getSelectedNode();
if (node == null) return;
// get the default index for adding
PropertyKey parentPKey = treeModel.getPropKey (useProps, node.getPath ());
Prop val = useProps.pget (parentPKey);
int newIndex = useProps.getNumChildren (parentPKey);
// See if should be adding at other index...
// if parent specifies allowed children
String status, allowedChild;
PropertyKey cutKey = treeModel.getPropKey (useProps, cutNode.getPath());
Prop cutProp = useProps.pget(cutKey);
String cutID = cutProp.getID();
if ((val != null) && ((status = val.getStatus()) != null)) {
int idx1 = status.indexOf (ALLOWED_CHILD);
int idx2 = status.indexOf (REQUIRED_PARENT);
if (idx1 >= 0) {
if (idx2 < 0)
idx2 = status.length();
StringTokenizer st = new StringTokenizer
(status.substring (idx1 + 1, idx2), String.valueOf (ALLOWED_CHILD));
while (st.hasMoreTokens()) {
allowedChild = st.nextToken();
// if parent specifies THIS child
if (allowedChild.startsWith (cutID)) {
idx1 = allowedChild.indexOf("(");
idx2 = allowedChild.indexOf(")");
// if parent specifies index
if (idx1 >= 0 && idx2 >= 0) {
// change index
idx1 = Integer.valueOf (allowedChild.substring
(idx1 + 1, idx2)).intValue();
newIndex = ((idx1 < 0) ? (newIndex + idx1) : idx1);
}
break; // exit while loop
}
}
}
}
// Create an appropriately named node (original + made unique(if needed))
String newChildName =
useProps.pget(parentPKey).uniqueChildName(cutKey.name());
useProps.addChildKey
(parentPKey,
useProps.pget(parentPKey).uniqueChildName(newChildName),
newIndex);