private Widget dynamicTree() {
FlowPanel container = new FlowPanel();
// Add Tree
final FastTree topTree = new FastTree();
FastTreeItem firstBranch = topTree.addItem("Inbox (3)");
firstBranch.addItem("Urgent");
FastTreeItem familyBranch = firstBranch.addItem("Family");
familyBranch.becomeInteriorNode();
familyBranch.addItem("Mom");
familyBranch.addItem("Brosef");
FastTreeItem secondBranch = firstBranch.addItem("Calendar");
secondBranch.addItem("Important Meetings");
container.add(topTree);
final Button btnAdd = new Button("Add to Family Branch",
new ClickHandler() {
public void onClick(ClickEvent event) {
FastTreeItem selectedItem = topTree.getChild(0).getChild(1);
Window.alert("Adding new " + selectedItem.getText()
+ " Child Nodes");
selectedItem.addItem("Dad");
selectedItem.addItem("Sissef");
}
});
final Button btnKill = new Button("Disown Family Branch",
new ClickHandler() {
public void onClick(ClickEvent event) {
FastTreeItem selectedItem = topTree.getChild(0).getChild(1);
Window.alert("Disowning " + selectedItem.getText() + " Child Nodes");
selectedItem.becomeLeaf();
btnAdd.setVisible(true);
}
});
topTree.addBeforeCloseHandler(new BeforeCloseHandler<FastTreeItem>() {
public void onBeforeClose(BeforeCloseEvent<FastTreeItem> event) {
btnKill.setVisible(event.getTarget().getText().equals("Family"));
}
});
btnKill.setVisible(false);