将Properties视图附加到自定义XML编辑器

时间:2016-07-05 14:02:15

标签: eclipse eclipse-plugin

我在eclipse插件中创建了一个自定义编辑器,它以Tree-Table(TreeViewer)格式显示了XML,并带有几个属性。为了显示剩余的属性,我试图将其与"属性视图"联系起来,但却无法在其上取得进展。

我在SO上经历了类似的问题 How to handle property sheet from customized editor in eclipse plugin development?在其中讨论使您的查看者参与工作台选择并在编辑器中选择的对象上实现IPropertySource。

在我的情况下,我直接在treeviewer输入中设置文档对象,如下所示。

IFileEditorInput editorInput = (IFileEditorInput) getEditorInput();
IFile inputIFile = editorInput.getFile();
File f = new File(inputIFile.getLocation().toString());
try {
    doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f);
    } 
    catch (SAXException | IOException | ParserConfigurationException e) {
    e.printStackTrace();
    }
//setting root element of doc as input
treeViewer.setInput(doc.getDocumentElement());

现在应该在什么对象上实现IPropertySource接口来提供属性?

让我知道我是朝着正确的方向前进,还是错过了某些事情,或者做错了。

希望这有意义!!

1 个答案:

答案 0 :(得分:1)

当您的选择提供程序触发选择更改事件时,属性页面将查看新选择。如果您使用树查看器作为提供程序,则选择将是树内容提供程序中的当前对象。

属性视图将尝试从选择中获取IPropertySourceProvider。您的对象可以直接实现IPropertySourceProvider,或者让它查看IAdaptable界面或使用IAdapterFactory

一旦视图中有IPropertySourceProvier,它就会调用getPropertySource方法。您的代码必须返回IPropertySource对象 - 由您来编写此类。