当在项目上按下ENTER
时,会调用widgetDefaultSelected
方法。在那里,ControlEditor
以所选TreeItem
文本作为其编辑器设置Text
:editor.setEditor(text);
。
这Text
然后才处理当ENTER
或ESC
被按下,并在没有其他场合。这意味着即使您选择其他项目,Text
仍然可以显示其原始内容。
要更改此行为,您可以修改widgetSelected
方法,以便例如处置Text
,以便它不再可见或使用当前选定的项目更新其文本。
要删除Text
:
@Override
public void widgetSelected(SelectionEvent e) {
// get the current editor
Text text = (Text) editor.getEditor();
if (text != null && !text.isDisposed()) {
// remove the editor
text.dispose();
}
tree.setSelection(new TreeItem[] { cursor.getRow() });
}
要更新Text
内容:
@Override
public void widgetSelected(SelectionEvent e) {
// get the current editor
Text text = (Text) editor.getEditor();
if (text != null && !text.isDisposed()) {
// update the text in the editor
TreeItem row = cursor.getRow();
int column = cursor.getColumn();
text.setText(row.getText(column));
}
tree.setSelection(new TreeItem[] { cursor.getRow() });
}
由于一吨快速回复!有用 :) – Vrinda