When copying a program node, I need to change a value in the model representing a unique identification of the program node. In the constructor of the ProgramNodeContribution, I am checking if the value is set, and if so try to change it as follows:
if (model.isSet("key")) {
model.set("key", "something else");
}
If I check the value right after in the constructor, it is set correctly. But after done “constructing” the contribution object the value is back to its original value! It seems that the model is reset AFTER the contribution is constructed.
Hi,
both copying and inserting a new urcap node triggers the openView method of the unique object, therefore i would try to pass your unique data to any constructor variable and save that data to the urcap objects model in the openView method.
Copying and inserting does not trigger the openView method - unfortunately. isDefined seems to be triggered on all nodes, but always on the pasted node first.
when inserting your copied urcap, its parent node will be opened and trigger the openview method. As you mentioned in another thread, the creationcontext of your copied node will be LOAD, therefore you will know which one is the copied one.
Note that Model setters do not work properly inside constructors or the isDefined method. setters should normally fired by user input (and will need to use the undo/redo manager)
is there any other condition that prevents your copied node from triggering openview? it worked fine on many urcaps i tested.
I found that isDefined for the inserted node is always called before the remaining program. I therefore created a local java variable that is initialized to false, and set to true the first time isDefined is run. Then for each node, I am creating a global ur-variable with a unique node name, every time isDefined is run the first time. If the name already exists as a variable, it creates a new unique variable name. The trick is to try and remove the ur-variable from the nodes data model, before trying to create it.
Now, when the node is cut, the UR libraries automatically removes the ur-variable which is in the cutted nodes data model. When it is then pasted, the first is able to obtain the same unique name, but if it is pasted multiple times each new will get new unique names. If the node is copied, all new nodes will get new unique names, since the copied nodes data model still exists in the program.
Since all nodes always have unique names, their names will be restored when loading the program.