首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emf写事务

Emf写事务
EN

Stack Overflow用户
提问于 2016-06-30 04:57:10
回答 1查看 2.8K关注 0票数 1

如果我试图通过事务编辑域I am getting exception as修改该资源文件,则资源文件在资源管理器中。

org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348) at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302) at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284) at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240) at org.eclipse.emf在没有写事务的情况下不能修改资源集.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374) at org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1027) at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:299) at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-30 07:59:13

我认为问题在于,您试图在另一个写事务中执行写事务。命令应该能做到这一点。这可以使用模型的EditingDomain来完成:(确保org.eclipse.emf.transaction在您的依赖项中)

代码语言:javascript
复制
import org.eclipse.emf.transaction.TransactionalEditingDomain; 
import org.eclipse.emf.transaction.util.TransactionUtil;

public void doEditing(EObject element) {
    // Make sure your element is attached to a resource, otherwise this will return null
    TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(element);
    domain.getCommandStack().execute(new RecordingCommand(domain) {

        @Override
        protected void doExecute() {
            // Implement your write operations here,
            // for example: set a new name
            element.eSet(element.eClass().getEStructuralFeature("name"), "aNewName");
        }
    });
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38114267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档