b.addKeyboardListener(new KeyboardListener() {
public void onKeyDown(Widget sender, char keyCode, int modifiers) {
if (keyCode == KEY_ENTER) {
String value = b.getText().trim();
FastTreeItem chosen = treeItems.get(value);
if (chosen == null) {
Window.alert("No such tree item exists");
}
tree.setSelectedItem(chosen);
tree.ensureSelectedItemVisible();
}
}
public void onKeyPress(Widget sender, char keyCode, int modifiers) {
}
public void onKeyUp(Widget sender, char keyCode, int modifiers) {
}
});
ScrollPanel scroller = new ScrollPanel();
for (int i = 0; i < 10; i++) {
FastTreeItem item = tree.addItem("" + i);
treeItems.put("" + i, item);
for (int j = 0; j < 5; j++) {
String value = "" + i + "." + j;
FastTreeItem subItem = item.addItem(value);
treeItems.put(value, subItem);
for (int k = 0; k < 2; k++) {
String newValue = i + "." + j + "." + k;
treeItems.put(newValue, subItem.addItem(newValue));
}
}
}
scroller.setWidget(tree);
scroller.setHeight("200px");