EMF 编辑域命令创建
我现在正在深入研究 EMF,并遇到了以下问题:
我正在尝试使用以下代码从字段集中删除字段:
FieldElem ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove = new RemoveCommand(editingDomain, nf,
DescPackage.eINSTANCE.getNestedFieldsetElem_Field(), ff);
editingDomain.getCommandStack().execute(remove);
ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove2 = RemoveCommand.create(editingDomain, nf,
DescPackage.eINSTANCE.getNestedFieldsetElem_Field(), ff);
editingDomain.getCommandStack().execute(remove2);
ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove3 = RemoveCommand.create(editingDomain, ff);
editingDomain.getCommandStack().execute(remove3);
前两个命令工作正常,但第三个命令不行。我什至没有添加到命令堆栈,也没有删除任何内容。我做错了什么?
更新:正如我在调试器中看到的,执行方法返回UNEXECUTABLE_COMMAND。
I'm diving into EMF now, and have encountered the following problem:
I'm trying to remove fields from fieldset with following code:
FieldElem ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove = new RemoveCommand(editingDomain, nf,
DescPackage.eINSTANCE.getNestedFieldsetElem_Field(), ff);
editingDomain.getCommandStack().execute(remove);
ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove2 = RemoveCommand.create(editingDomain, nf,
DescPackage.eINSTANCE.getNestedFieldsetElem_Field(), ff);
editingDomain.getCommandStack().execute(remove2);
ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove3 = RemoveCommand.create(editingDomain, ff);
editingDomain.getCommandStack().execute(remove3);
The first two commands works just fine, but third one not. I's not even adding to the command stack, and is not removing anything. What am i doing wrong?
UPDATE: As i've seen in debugger, execute method return UNEXECUTABLE_COMMAND.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当
ff
作为容器(即ff.eContainer != null
)时才能使用指令RemoveCommand.create(editingDomain, ff)
。当您将对象添加到具有包含属性的关系时,eContainer
会由 EMF 自动设置。remove3
命令肯定不起作用,因为getField()
关系不是包含关系。The instruction
RemoveCommand.create(editingDomain, ff)
can be used only ifff
as a container (ieff.eContainer != null
). TheeContainer
is set automatically by EMF when you add the object to a relation with containment property.The
remove3
command does not work certainly because thegetField()
relation is not a containment relation.最后我找到了一个答案:
正如我使用 XSD 作为源,模型是从这个片段生成的:
因此 FieldsetElem 不直接包含 FieldElem,而是从适当的 FutureMap 条目派生 FieldElem。所以正确的代码是:
Finally i've founded an answer:
As i've used and XSD as a source, the model was generated from this fragment:
So the FieldsetElem, aren't contains FieldElem directly, instead the FieldElem is derieved from an appropriate FutureMap entry. So the correct code is: