PDA

View Full Version : Saving order after Drag and drop in a TreePanel<ModelData>



Toams
28 Feb 2012, 9:01 AM
Hi,

I try to save the order of the elements of a treePanel<ModelData> in order to reproduce this ordre later. (I already developpe the server side).
When I want to set the new order for each element

When I try to update the position of each elem the list I have do not contains
the operation I could make. It is exactly the same list in the same order than when I create the store..


model = new ModelPopup(listeModel, true);
store = new TreeStore<ModelData>();
store.add(model.getChildren(), true);

final TreePanel<ModelData> tree = new TreePanel<ModelData>(store);
tree.setDisplayProperty("name");
store.sort("order", SortDir.ASC);

new TreePanelDragSource(tree);
final TreePanelDropTarget target = new TreePanelDropTarget(tree){
@Override
public void onDragDrop(DNDEvent e) {
super.onDragDrop(e);
int i = 0;
// I try to update the position of each elem but the list have the order before the first sort
for (ModelData Element : store.getAllItems()){
final ModelArbrePopup element = (ModelArbrePopup) Element;
element.setOrder(i);
GWT.log(element.getName());
i++;
}
}
};
target.setAllowSelfAsSource(true);
target.setFeedback(Feedback.BOTH);


I hope than someone could help me

thanks

A.Rothe
29 Feb 2012, 4:13 AM
I think, in the API docs you can find, that store.getAllItems() returns a list of all models without any order...

~Andre

A.Rothe
29 Feb 2012, 4:55 AM
Try TreeStore.getRootItems() and TreeStore.getChildren(model, true) to build your own list. The method getModels() returns the same as getAllItems().