PDA

View Full Version : [CLOSED] Reordered Sequence Cannot be Retrieved in TreePanel



nyklogistics
24 Jun 2009, 7:21 PM
I have add a test button in your example.
After reordering the items, I cannot retrieve the reordered sequence of the tree items.



public class ReorderingTreePanelDNDExample extends LayoutContainer {

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FlowLayout(10));

LayoutContainer container = new LayoutContainer();
container.setSize(280, 400);
container.setBorders(true);
container.setScrollMode(Scroll.AUTO);

TreeStore<ModelData> store = new TreeStore<ModelData>();
final TreeModel root = (ExamplesModel) Registry.get(Examples.MODEL);
root.set("name", "Ext GWT");
store.add(root, true);

final TreePanel<ModelData> tree = new TreePanel<ModelData>(store) {
@Override
public boolean hasChildren(ModelData parent) {
if ("My Files".equals(parent.get("name")) || parent instanceof Category) {
return true;
}
return super.hasChildren(parent);
}
};

tree.getStyle().setLeafIcon(IconHelper.createStyle("icon-list"));
tree.setAutoLoad(true);
tree.setDisplayProperty("name");
tree.addListener(Events.Render, new Listener<TreePanelEvent<ModelData>>() {
public void handleEvent(TreePanelEvent<ModelData> be) {
be.getTreePanel().setExpanded(root, true);
}
});

TreePanelDragSource source = new TreePanelDragSource(tree);
source.addDNDListener(new DNDListener() {
@Override
public void dragStart(DNDEvent e) {
ModelData sel = tree.getSelectionModel().getSelectedItem();
if (sel != null && sel == tree.getStore().getRootItems().get(0)) {
e.setCancelled(true);
e.getStatus().setStatus(false);
return;
}
super.dragStart(e);
}
});

TreePanelDropTarget target = new TreePanelDropTarget(tree);
target.setAllowSelfAsSource(true);
target.setFeedback(Feedback.BOTH);

container.add(tree);
container.add(new Button("Test", new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
List<ModelData> rootItems = tree.getStore().getRootItems();
TreeModel root = (TreeModel) rootItems.get(0);
for (ModelData child : root.getChildren()) {
Window.alert("child.name="+child.get("name"));
}
}

}));
add(container);
}
}

darrellmeyer
25 Jun 2009, 5:32 AM
The parent / child relationships are not determined from the models itself, rather the store keeps the relationships internally. You must get a model's children from the tree store using store.getChildren(parent).