Hello,
I don't understand well : how to edit elements of the model pragmatically ?
I want to set feature "devicename" of "SystemMode" object via plugin.
When I test without "TransactionalEditingDomain" described by the example below :
public void SetDevice(Session s){
XMIResourceImpl xmiressourceImpl = (XMIResourceImpl) s.getSemanticResources().iterator().next();
final SystemModeImpl var = (SystemModeImpl) xmiressourceImpl.getContents().get(0);
var.setDevicename("SystemModeTest");
}
I get :
!ENTRY org.eclipse.emf.transaction 4 41 2015-06-05 17:57:37.136
!MESSAGE Read-only transaction rolled back
!SUBENTRY 1 org.eclipse.emf.transaction 4 40 2015-06-05 17:57:37.136
!MESSAGE Transaction aborted due to concurrent write
When I test with "TransactionalEditingDomain" described by the example below :
public void SetDevice(Session s){
XMIResourceImpl xmiressourceImpl = (XMIResourceImpl) s.getSemanticResources().iterator().next();
final SystemModeImpl var = (SystemModeImpl) xmiressourceImpl.getContents().get(0);
TransactionalEditingDomain ted = s.getTransactionalEditingDomain();
CommandStack stack = ted.getCommandStack();
try {
RecordingCommand cmd = new RecordingCommand(ted) {
@Override
protected void doExecute() {
// TODO Auto-generated method stub
var.setDevicename("SystemModeTest");
}
};
stack.execute(cmd);
}
catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I get :
!STACK 0
java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.acquire(TransactionalEditingDomainImpl.java:576)
....
Thanks,
Yassine.
[Updated on: Mon, 08 June 2015 14:42]
Report message to a moderator