对轮廓节点进行分组
我正在开发 XTEXT 2.0 插件。我想将轮廓内的一些节点分组到“虚拟”节点中。达到这个结果的正确方法是什么?
目前,如果我想对“A”类型的节点进行分组,在我的 OutlineTreeProvider 中,我定义以下方法
protected void _createNode(IOutlineNode parentNode, A node) {
if(this.myContainerNode == null){
A container = S3DFactoryImpl.eINSTANCE.createA();
super._createNode(parentNode, container);
List<IOutlineNode> children = parentNode.getChildren();
this.myContainerNode = children.get(children.size()-1);
}
super._createNode(this.myContainerNode, node);
}
阅读 Xtext 2.0 文档,我还看到有一个 EStructuralFeatureNode。我不太明白这种类型的节点是什么以及如何使用它。您能解释一下 EStructuralFeatureNode 的用途吗?
非常感谢
I'm developing an XTEXT 2.0 plugin. I'd like to group some nodes inside my outline in a "virtual" node. Which is the right way to achieve this result?
Currently if i want to group nodes of type "A", in my OutlineTreeProvider I define the following method
protected void _createNode(IOutlineNode parentNode, A node) {
if(this.myContainerNode == null){
A container = S3DFactoryImpl.eINSTANCE.createA();
super._createNode(parentNode, container);
List<IOutlineNode> children = parentNode.getChildren();
this.myContainerNode = children.get(children.size()-1);
}
super._createNode(this.myContainerNode, node);
}
Reading the Xtext 2.0 documentation i saw also that there is a EStructuralFeatureNode. I didn't understand exactly what this type of node is and how to use it. Can you explain what EStructuralFeatureNode is used for?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码存在一些问题:
this.myContainerNode
:无法保证您的提供程序是原型;有人可以将实例配置为单例。因此,请避免实例字段。此问题有两种解决方案:
super._createNode()
:不要调用带有_
的方法,始终调用普通版本 (super.createNode()
)。该方法将确定要为您调用哪个重载的_create
* 方法。但在你的情况下,你不能调用任何这些方法,因为你会得到一个循环。请改为调用createEObjectNode()
。最后,您不需要创建
A
的实例 (S3DFactoryImpl.eINSTANCE.createA()
)。节点可以由模型元素支持,但这是可选的。对于分组,我使用此类:
在您的情况下,代码如下所示:
There are a couple of problems with your code:
this.myContainerNode
: There is no guarantee that your provider is a prototype; someone could configure the instance as singleton. Therefore, avoid instance fields.There are two solutions to this problem:
super._createNode()
: Don't call the methods with_
, always call the plain version (super.createNode()
). That method will figure out which overloaded_create
* method to call for you. But in your case, you can't call any of these methods because you'd get a loop. CallcreateEObjectNode()
instead.Lastely, you don't need to create an instance of
A
(S3DFactoryImpl.eINSTANCE.createA()
). Nodes can be backed by model elements but that's optional.For grouping, I use this class:
In your case, the code would look like so: