Eclipse SWT TreeCursor 总是从第一次选择的单元格中选择文本
Eclipse SWT TreeCursor always has the text selected from the cell that was selected first time
我尝试使用 TreeCursor
文档中的相同示例:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/plain/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet360.java
在我第一次按回车键 (SWT.CR
) 的任何单元格上,假设我按单元格 'root11',此后我单击任何单元格,'root11' 出现在它。
我的要求是 select 复制单元格中的文本。我不想编辑。因此,每次我单击一个单元格以复制其文本时,第一次 selected 的单元格中的文本就会出现。
任何关于可能导致此问题的指示?
提前致谢!
当ENTER
在一个项目上被按下时,widgetDefaultSelected
方法被调用。在那里,ControlEditor
设置了一个 Text
,其中 selectedTreeItem
文本作为其编辑器:editor.setEditor(text);
.
这个Text
只有在按下ENTER
或ESC
时才会被释放,其他情况下不会释放。这意味着即使您 select 另一个项目,Text
仍然可以看到其原始内容。
要更改此行为,您可以修改 widgetSelected
方法,例如,处理 Text
使其不再可见或使用当前 select 更新其文本编辑项目。
删除 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() });
}
我尝试使用 TreeCursor
文档中的相同示例:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/plain/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet360.java
在我第一次按回车键 (SWT.CR
) 的任何单元格上,假设我按单元格 'root11',此后我单击任何单元格,'root11' 出现在它。
我的要求是 select 复制单元格中的文本。我不想编辑。因此,每次我单击一个单元格以复制其文本时,第一次 selected 的单元格中的文本就会出现。
任何关于可能导致此问题的指示? 提前致谢!
当ENTER
在一个项目上被按下时,widgetDefaultSelected
方法被调用。在那里,ControlEditor
设置了一个 Text
,其中 selectedTreeItem
文本作为其编辑器:editor.setEditor(text);
.
这个Text
只有在按下ENTER
或ESC
时才会被释放,其他情况下不会释放。这意味着即使您 select 另一个项目,Text
仍然可以看到其原始内容。
要更改此行为,您可以修改 widgetSelected
方法,例如,处理 Text
使其不再可见或使用当前 select 更新其文本编辑项目。
删除 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() });
}