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

问题描述:

我已经在eclipse插件中创建了一个自定义编辑器,该自定义编辑器以Tree-Table(TreeViewer)格式显示具有其属性的XML。为了显示剩余的属性,我试图将它与“属性视图”绑定,但并不真正能够取得进展。将属性视图附加到自定义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接口来贡献属性?

让我知道,如果我正确的方向或失去一些东西或完全错误。

希望这是有道理的!

+0

作为编辑器的选择提供者,你设置了什么? –

+0

我将treeViewer设置为选择提供者 - 'getSite()。setSelectionProvider(treeViewer);' – Hitesh

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

属性视图将尝试从选择中获得IPropertySourceProvider。您的对象可以直接执行IPropertySourceProvider,或者提供查看IAdaptable界面或使用IAdapterFactory

一旦视图有IPropertySourceProvier它将调用getPropertySource方法。您的代码必须返回IPropertySource对象 - 由您来编写此课程。

+0

在这种情况下,treeViewer中的当前对象将是一个DOM节点,所以我应该如何在其上实现IPropertySourceProvider? – Hitesh

+0

您可能可以使用'IAdapterFactory'做些事情,但很有可能您必须更改您的内容提供者以提供包装到DOM节点的对象,以便您可以在其中添加代码。 –

+0

谢谢!!我能够使用IAdapterFactory工作。 – Hitesh