views:

135

answers:

1

Hi All.

When a user clicks a 'Add Node' button above a tree and the program adds a tree item below the selected node, I would like to insert the new tree item with the text highlight and ready for editing by the user... like labels in GMail. Any ideas?

--Kirt

A: 

Are you using the GWT default TreeItem? If so, when you add the node, you could add the TreeItem with a Widget which you write which contains a TextBox and a Button to save.

When the save button is clicked, it calls setText() on the tree item with the text box's text, thus removing the widgets from the tree item.

It may be an even better idea to subclass TreeItem to encapsulate this logic and provide more functionality.

edit: Here, just because I'm feeling generous...

public class EditableTreeItem extends TreeItem {
  public EditableTreeItem() {
    super();
    TextBox textBox = new TextBox();
    Button saveButton = new Button("Save");
    saveButton.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent e) {
        if (!textBox.getText().isEmpty()) {
          EditableTreeItem.this.setText(textBox.getText());
        }
      }
    });
  }
}
Jason Hall