如果我试图通过事务编辑域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)
发布于 2016-06-30 07:59:13
我认为问题在于,您试图在另一个写事务中执行写事务。命令应该能做到这一点。这可以使用模型的EditingDomain来完成:(确保org.eclipse.emf.transaction在您的依赖项中)
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");
}
});
}https://stackoverflow.com/questions/38114267
复制相似问题