eclipse-rcp : how to add double click listener on a ListViewer's item?
I开发者_StackOverflow中文版 have a ListViewer in my eclipse-plugin, I want to do some work when user double click on the items in that ListViewer.
I had attached a doubleClick listener with my ListViewer instance, but it will be fired when I double click on anywhere inside the ListViewer
Check the current selection inside your listener. Like in the following code:
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty()) return;
List<Object> list = selection.toList();
///...
}
});
Remember that the selection for ListView (and TableViewer, ComboViewer, and TreeViewer) is always a IStructuredSelection..
精彩评论