【问题标题】:Attaching Properties view to a custom XML Editor将属性视图附加到自定义 XML 编辑器
【发布时间】:2016-11-07 09:52:31
【问题描述】:

我在 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 接口来贡献属性?

让我知道我的方向是否正确、遗漏了什么或完全错误。

希望这是有道理的!

【问题讨论】:

  • 您将什么设置为编辑器的选择提供者?
  • 我将 treeViewer 设置为选择提供者 - 'getSite().setSelectionProvider(treeViewer);'

标签: eclipse eclipse-plugin


【解决方案1】:

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

属性视图将尝试从选择中获取IPropertySourceProvider。你的对象可以直接实现IPropertySourceProvider,或者提供给它查看IAdaptable接口或者使用IAdapterFactory。

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

【讨论】:

  • 在这种情况下,treeViewer 中的当前对象将是一个 dom 节点,那么我应该如何在其上实现 IPropertySourceProvider 呢?
  • 您可能可以使用IAdapterFactory 做一些事情,但很可能您将不得不更改您的内容提供者以提供一个包装到 DOM 节点的对象,以便您可以在那里添加代码。跨度>
  • 谢谢!!我能够使用 IAdapterFactory 使其工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多