Hello,
Is anyone able to help with the code that allows you to move a node up and down exactly as the buttons below do?
Thank you in advance.
Best regards.
Under certain circumstance, this use-case makes sense, i might find a feasible solution:
public void onMoveNodeClick(boolean is_move_up) {
final TreeNode cn = apiProvider.getProgramAPI().getProgramModel().getRootTreeNode(this);
//find current node
undoRedoManager.recordChanges(new UndoableChanges() {
@Override
public void executeChanges() {
// TODO Auto-generated method stub
try {
parent.setChildSequenceLocked(false);
treeindex = -1;
// let a private variable to find current node's index
parent.traverse(new ProgramNodeVisitor() {
public void visit(URCapProgramNode pn, int index, int depth) {
if(pn.canGetAs(Search1RotationCustomerAPI.class)) {
// it requires that every node in the sub-tree needs to have unique ID, i.e., here i make it into Display name.
if(pn.getAs(Search1RotationCustomerAPI.class).getDisplayName().equals(getDisplayName())) {
treeindex = index;
System.out.println("Current tree index is: "+index);
}
}
}
});
if(is_move_up) {
if(treeindex > 0) {
TreeNode toMove = parent.getChildren().get(treeindex-1);
parent.removeChild(cn);
parent.insertChildBefore(toMove, cn.getProgramNode());
}
}else {
if(treeindex < (parent.getChildren().size()-1)) {
TreeNode toMove = parent.getChildren().get(treeindex+1);
parent.removeChild(cn);
parent.insertChildAfter(toMove, cn.getProgramNode());
}
}
parent.setChildSequenceLocked(true);
}catch(TreeStructureException e15) {
e15.printStackTrace();
}
}
});
}
As a result:
