在自定义编辑器对话框中访问 EMF 模型实例
我有一个关于 Eclipse 建模框架的问题。我指定了一个 EMF 模型,并使用 EMF 为其创建了相应的编辑器。现在我想以对话框和向导的形式向该编辑器添加自定义功能。为此,我根据编辑器的plugin.xml 中的上下文菜单组和项目进行了定义,以允许用户调用这些对话框/向导。在编辑器的演示包中,我为对话框/向导创建了新类。
我现在的问题是,如何访问用户当前在这些对话框/向导中正在处理的模型?例如,需要将模型的某些部分加载到对话框/向导中并让用户更改它。
我对此进行了研究,但找不到足够的答案。我发现编辑域是一种可以通过“editor”使用的机制。getEditingDomain().getResourceSet().getResources().get(0).getContents().get(0);但在这里我不知道从哪里获得“编辑器”部分(我猜是编辑器的实例?)。
我很高兴获得一些有关如何进行的提示。
干杯,
埃里克
I have a question with regard to the Eclipse Modeling Framework. I specified an EMF-model and and used EMF to create an corresponding editor for it. Now I want to add custom functionality in form of dialogs and wizards to this editor. To do so, I defined according context menu groups and items in the editor's plugin.xml to allow the user to invoke these dialogs / wizards. In the editor's presentation package, I created new classes for the dialogs / wizards.
My question is now, how it is possible to access the model that the user is currently working on in these dialogs / wizards? This is needed for example to load some parts of the model into the dialog / wizard and let the user change it.
I did research on this but cannot find a sufficient answer. I came across the editing domain as a mechanism that could be used via "editor".getEditingDomain().getResourceSet().getResources().get(0).getContents().get(0); But here I don't know where to get the "editor" part (the instance of the editor I guess?).
I would be glad to get some hints on how to proceed.
cheers,
erik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 JFace,则可以实现 ISelectionChangedListener 以在用户选择模型中的某些内容时触发方法。这会将 SelectionChangedEvent 传递到 SelectionChanged 方法中。从那里,您可以使用 event.getSelection(); 获取用户当前的选择作为 ISelection。
希望这有帮助。
If you're using JFace, you can implement the ISelectionChangedListener to trigger a method whenever the user selects something in the model. This will pass a SelectionChangedEvent into the selectionChanged method. From there, you can get the user's current selection as an ISelection using event.getSelection();.
Hope this helps.