I found the solution myself,
Instead of adding the IfNode directly to the root tree I create an TreeNode ifNodeTreeNode and then add the ifNode as a child.
After that it is possible to add children to the IfNode, below is some of my test code.
root_ = programModel_.getRootTreeNode(programNode_.get());
TreeNode ifNodeTreeNode = root_ .addChild(createIfNode(“digital_in[0]”,“true”));
FolderNode testFolderNode = programNodeFactory_.createFolderNode();
String folderNametest = “TestFolder”;
testFolderNode.setName(folderNametest);
ifNodeTreeNode.addChild(testFolderNode);

/Benny