PDA

View Full Version : [1.2.x] NPE when unselecting TreeItem's



Jose Jeria
15 May 2009, 7:31 AM
Steps to reproduce
Run testcase
Select two items (multi-select tree)
Unselect one of the items
NPE is thrown on tree.getSelectedItem();

public class TreeSelectionBug extends LayoutContainer {

@Override
public void onRender(Element parent, int index) {
super.onRender(parent, index);

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

this.setStyleAttribute("margin", "10px");

TreeStore store = new TreeStore();
TreeModel root = new BaseTreeModel<TreeModel>();
root.set("name", "Ext GWT");
TreeModel child = new BaseTreeModel<TreeModel>();
child.set("name", "First");
root.add(child);
child = new BaseTreeModel<TreeModel>();
child.set("name", "Second");
root.add(child);
child = new BaseTreeModel<TreeModel>();
child.set("name", "Third");
root.add(child);

store.add(root, true);

final Tree tree = new Tree();
tree.setSelectionMode(SelectionMode.MULTI);
tree.getStyle().setLeafIconStyle("icon-list");

TreeBinder binder = new TreeBinder(tree, store);
binder.setDisplayProperty("name");
binder.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

@Override
public void selectionChanged(SelectionChangedEvent<ModelData> se) {
if (se.getSelection().size() == 1) {
TreeItem item = tree.getSelectedItems().get(0);
GWT.log(item.getText(), null);

TreeItem item2 = tree.getSelectedItem();
GWT.log(item2.getText(), null);
}
}

});
binder.init();

tree.getRootItem().getItem(0).setExpanded(true);

container.add(tree);
this.add(container);
}
}


tree.getSelectedItem(); will be null when the selection size goes back to 1. The TreeItem can be retrieved with tree.getSelectedItems().get(0); though.