this.treeView = treeView;
this.path = path;
// Get the data being edited
List<?> treeData = treeView.getTreeData();
TreeNode nodeData = (TreeNode)Sequence.Tree.get(treeData, path);
// Get the node bounds
Bounds nodeBounds = treeView.getNodeBounds(path);
int nodeIndent = treeView.getNodeIndent(path.getLength());
nodeBounds = new Bounds(nodeBounds.x + nodeIndent, nodeBounds.y,
nodeBounds.width - nodeIndent, nodeBounds.height);
// Render the node data
TreeViewNodeRenderer nodeRenderer = (TreeViewNodeRenderer)treeView.getNodeRenderer();
nodeRenderer.render(nodeData, treeView, false, false,
TreeView.NodeCheckState.UNCHECKED, false, false);
nodeRenderer.setSize(nodeBounds.width, nodeBounds.height);
// Get the text bounds
Bounds textBounds = nodeRenderer.getTextBounds();
if (textBounds != null) {
textInput = new TextInput();
Insets padding = (Insets)textInput.getStyles().get("padding");
// Calculate the bounds of what we're editing
Bounds editBounds = new Bounds(nodeBounds.x + textBounds.x - (padding.left + 1),
nodeBounds.y, nodeBounds.width - textBounds.x + (padding.left + 1),
nodeBounds.height);
// Scroll to make the text as visible as possible
treeView.scrollAreaToVisible(editBounds.x, editBounds.y,
textBounds.width + padding.left + 1, editBounds.height);
// Constrain the bounds by what is visible through Viewport ancestors
editBounds = treeView.getVisibleArea(editBounds.x, editBounds.y,
editBounds.width, editBounds.height);
textInput.setText(nodeData.getText());
textInput.setPreferredWidth(editBounds.width);
textInput.getComponentKeyListeners().add(textInputKeyHandler);
popup = new Window(textInput, true);
popup.getWindowStateListeners().add(popupStateHandler);