Hello all,
I would like to fix some broken names of some components in my model automatically. Actually, I can do it by providing a new operation action. So a user can do a right click and call the fixing function. However, I want to do it by abstracting from the user. So, the user will not be aware of these automatic fixes. I thought that I could perform these kind of automatic fixes during a semantic validation. However, I cannot run a write transaction during a validation and get this error when I call the execute function of a command stack object:
java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context.
I can understand the point, but could not find any solution for this. How can I call a function without requesting an action from the user?
Here is my code that is called during a validation:
public boolean fixComponents(EObject self){
Component c = (Component) self;
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(self);
CommandStack stack = domain.getCommandStack();
RecordingCommand r = new RecordingCommand(domain){
@Override
protected void doExecute(){
c.setName("SomeAutoGeneratedString");
}
}
try{
stack.execute(r);
} catch(Exception e){
System.err.println(e); // Produces: java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context.
}
}
Thanks in advance.