Within my generateScript function I am experiencing the following error:
Modification of program tree and/or data model not allowed outside UI thread
com.ur.urcap.domain.undoredomanager.UndoRedoException: Modification of program tree and/or data model not allowed outside UI thread
Basically what my program was doing prior to implementing swing was iterating through children nodes of a given type and performing calculations based on their position. The result was then stored in the child node’s data model. When I attempt to store these values in the child node’s data model I am getting the above error. While it seems like a straightforward error, I do not know how to fix the issue. Please advise.
Please review some of the Swing URCap samples in the SDK.
Any change to a nodes DataModel or the program tree must be grouped inside an UndoableAction, which is demonstrated in these samples.
The purpose is to group multiple changes as one single undoable action.
All of my changes are wrapped inside of the UndoableAction block. That is the issue that I am experiencing. Here is an example of what is happening inside the generateScript method:
this.api.getProgramModel().getRootTreeNode(this).traverse(new ProgramNodeVisitor() {
@Override
public void visit(URCapProgramNode programNode, int index, int depth) {
if (programNode.isDefined()) {
api.getUndoRedoManager().recordChanges(new UndoableChanges() {
@Override
public void executeChanges() {
programNode.dataModel.set("some_key, "some_value");
}
});
}
}
});
Even having wrapped my model changes inside the UndoableChanges block I am getting the error described above.
Is there a particular reason for doing this child-modification in the generateScript() method?
Typically, I would expect this to happen e.g. as a result of a button push in the parent-node UI.
Dear @jbm,
I am stucked with a similar issue. I have my code wrapped inside an UndoableChanges block, in my case not includded en generateScript.
This code works fine when called form a button in the screen, generated using swing.
But when I try to launch this same method from a Thread that is monitoring the press of a external button, i’m having this exception:
ERROR [Thread-19] 15:10:23 07/05/19: Modification of program tree and/or data model not allowed outside UI thread
com.ur.urcap.domain.undoredomanager.UndoRedoException: Modification of program tree and/or data model not allowed outside UI thread
How do you recomend to call the undoable code from a thread different than UI? Thank you!
Hi @r.larsson, thank you for the info. I don’t see the relation of ‘Image implementation’ with this post. [EDIT: Now I see, this post contains the line below in a sample code]
But I think this line
can be an answer to this post, or at least a lead to follow. Thank you!