开发者

eclipse-rcp : how to add double click listener on a ListViewer's item?

开发者 https://www.devze.com 2023-03-12 13:43 出处:网络
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开发者_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..

0

精彩评论

暂无评论...
验证码 换一张
取 消