EMF 编辑域命令创建

发布于 2025-01-05 00:12:34 字数 1011 浏览 0 评论 0原文

我现在正在深入研究 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画离情绘悲伤 2025-01-12 00:12:34

仅当 ff 作为容器(即 ff.eContainer != null)时才能使用指令 RemoveCommand.create(editingDomain, ff)。当您将对象添加到具有包含属性的关系时,eContainer 会由 EMF 自动设置。

remove3 命令肯定不起作用,因为 getField() 关系不是包含关系。

The instruction RemoveCommand.create(editingDomain, ff) can be used only if ff as a container (ie ff.eContainer != null). The eContainer is set automatically by EMF when you add the object to a relation with containment property.

The remove3 command does not work certainly because the getField() relation is not a containment relation.

一人独醉 2025-01-12 00:12:34

最后我找到了一个答案:

正如我使用 XSD 作为源,模型是从这个片段生成的:

<xsd:sequence>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="field" type="fieldElem" />
            <xsd:element name="autofill-field" type="fieldElem" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="fieldset" type="fieldsetElem" />
            <xsd:element name="join-field" type="joinFieldElem"/>
        </xsd:choice>
    </xsd:sequence>

因此 FieldsetElem 不直接包含 FieldElem,而是从适当的 FutureMap 条目派生 FieldElem。所以正确的代码是:

Command remove = RemoveCommand.create(ed,  ed.getWrapper(fe));

Finally i've founded an answer:

As i've used and XSD as a source, the model was generated from this fragment:

<xsd:sequence>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="field" type="fieldElem" />
            <xsd:element name="autofill-field" type="fieldElem" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="fieldset" type="fieldsetElem" />
            <xsd:element name="join-field" type="joinFieldElem"/>
        </xsd:choice>
    </xsd:sequence>

So the FieldsetElem, aren't contains FieldElem directly, instead the FieldElem is derieved from an appropriate FutureMap entry. So the correct code is:

Command remove = RemoveCommand.create(ed,  ed.getWrapper(fe));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文