@Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
final Folder model = TestData.getTreeModel();
final TreeStore<ModelData> store = new TreeStore<ModelData>();
store.add(model.getChildren(), true);
add(new Button("Reset", new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
store.removeAll();
store.add(model.getChildren(), true);
}
}),new FlowData(10));
final TreePanel<ModelData> tree = new TreePanel<ModelData>(store);
tree.setDisplayProperty("name");
tree.getStyle().setLeafIcon(Resources.ICONS.music());
tree.setWidth(260);
Menu contextMenu = new Menu();
MenuItem insert = new MenuItem();
insert.setText("Insert Item");
insert.setIcon(Resources.ICONS.add());
insert.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
ModelData folder = tree.getSelectionModel().getSelectedItem();
if (folder != null) {
Folder child = new Folder("Add Child " + count++);
store.add(folder, child, false);
tree.setExpanded(folder, true);
}
}
});