我在Eclipse RCP应用程序中使用Viewer Framework,我遇到了一种情况,我需要从TableViewer获取(知道在UI中选择了哪一行)所选行。 在UI中,用户可以选择一行.Below是我的Tableviewer声明
TableViewer viewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION
| SWT.HIDE_SELECTION);
当用户点击突出显示的特定行时,我能够选择某一行,我想知道用户是选择了哪一行并准确获取行详细信息?我怎样才能实现这一目标?
答案 0 :(得分:11)
在JFace中,您可以向TableViewer添加selectionListener。您将收到有关所选对象的通知,而不是选定的行。下面是代码:
this.viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(final SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection)event.getSelection();
}
});