NVN*_*NVN 2 eclipse eclipse-emf eclipse-emf-ecore
如果我尝试通过事务编辑域修改该资源文件,我在资源管理器中有该资源文件I am getting exception as
java.lang.IllegalStateException:如果没有写入事务,则无法在 org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348) 处修改资源集,在 org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification( TransactionChangeRecorder.java:302) 在 org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284) 在 org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240) 在 org .eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374) 在 org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1027) 在 org.eclipse.emf .common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:299) 在 org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:303)
我认为问题在于,您正在尝试在另一个写入事务中执行写入事务。一条命令就可以解决问题。这可以使用您的模型来完成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");
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3124 次 |
| 最近记录: |