在视图中双击后如何从列表查看器中检索项目

How can I retrieve an item from a listviewer after I double click it, in a view

我按照教程在 Eclipse 中创建了一个新视图。我创建了一个包含某些项目的列表查看器。我已经实现了一个 doubleClickListener,但是我需要获取我双击的项目的字符串才能执行某些操作。所以我有以下代码:

viewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {

            try{
                if( /*ITEM CLICKED, MATCHES STRING "A"*/ ){
                    /*DO THIS */
                }else if( /*ITEM CLICKED, MATCHES STRING "B"*/ ){
                    /*DO THAT */
                }

            }catch (Exception ex){
                throw new RuntimeException(ex.getMessage());
            }
        }
});

使用DoubleClickEventgetSelection()方法获取选区:

@Override
public void doubleClick(final DoubleClickEvent event)
{
  IStructuredSelection selection = (IStructuredSelection)event.getSelection();

  if (selection == null || selection.isEmpty())
    return;

  Object sel = selection.getFirstElement();

  // TODO 'sel' is the object from your content provider
}