在ElementListSelectionDialog中向元素添加图标

时间:2015-08-31 19:18:46

标签: eclipse dialog eclipse-rcp

我有以下代码使用ElementListSelectionDialog类在RCP Eclipse应用程序中创建对话框:

ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new LabelProvider());

dialog.setTitle("test");
dialog.setMessage("test");
dialog.setMultipleSelection(false);
dialog.setElements(new String[]{"test1", "test2", "test3"});
dialog.open();

上一代码生成此对话框:

enter image description here

这很好,但我也想在列表中的元素中添加图标,类似于web.xml编辑器的外观:

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要扩展您传递给options_from_collections_for_select( @batches, :id, ->(ob) { "#{ob.id}. #{ob.name}" } ) 构造函数的LabelProvider并覆盖

ElementListSelectionDialog

方法。对于使用public Image getImage(Object element) 方法添加到对话框的每个对象,都会调用此方法。