PDA

View Full Version : ReOrdering of child nodes within the parent



akshayrpin
7 Nov 2012, 2:29 AM
Hi
i have created a Treepanel using a treestore. i need to reorder [move the child node up and down within the parent] on click of a button. is this possible ???

i have been trying to achive the same by reomiving the seleted node and insert the same node again
but the problem am facing is when i remove a node the code written after is not executing, even thoug the node gets deleted from the treepanel but a new node is not being added/inserted when debuged it
I tried using a button upArrow

upArrow
.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
BeanModel selItem = treePanel.getSelectionModel().getSelectedItem();
BeanModel parent = treePanel.getStore().getParent(selItem);
List<BeanModel> childrens = treePanel.getStore().getChildren(parent, true);
for(BeanModel child : childrens){
treePanel.getStore().remove(child); // this works well for the nodes not being selected, for selected node it throws Targetinvocationexception.
}
treePanel.getStore().add(parent, childrens, true); // Doesnt get executed at all
}
});

let me know if any this is wrong or suggest me a proper solution for moving the children within the parent and i have to have this funcionality on click of a button.


39882

akshayrpin
14 Nov 2012, 6:03 AM
got the solution i had added two listners for treePanel

1 listner for Checkbox and also for TreePanel.getSelectionModel() listner so when tried to remove the node it was trying to remover the nodes twice.


so removed one listner and added treepanel.onClick instead of getSelectionModel() listner.

akshayrpin
14 Nov 2012, 6:11 AM
I am stuck up with another problem. when Expanding the node i am trying to sort the Childrens byt

Collections.sort(childrens, new Comparator<BeanModel>() {
@Override
public int compare(BeanModel f1,
BeanModel f2) {}});

so after sorting i am removing the childrens from the Treepanel

store.removeAll(parent); // removing as this was not sorted from the server.

store.add(parent, childrens, true);// addign the sorted children based on the sequence value


here i am able to get the Nodes displayed on the UI but the problem is not able to get the checkbox, inspite of

treePanel.setCheckable(true);
treePanel.setCheckNodes(CheckNodes.LEAF);
treePanel.setAutoLoad(true);
store.sort("defaultValue", SortDir.ASC);



if i comment the bold part above checkbox is visible.

let me know if am missing anything here