I’m trying to have my Cap installation node code generate only if the user has added a Cap program node to their program. Is there a simple way to check if a program node has been created in the installation node? I’m not having much luck combing through the API reference looking for it.
I don’t think if there are specific methods in the API for this, however I believe there is a way of doing it.
The constructor of a program node’s contribution is called when it is added to the program tree. As a result, we use it as the trigger for the creation of a program node.
In the constructor of your ProgramNodeContribution, add the line
This will store the current instance of the installation node in a variable called installation.
Now in your installation file, define a boolean field at the top, something like
private boolean areThereChildren = false
and a public method:
public void setAreThereChildren(boolean b)
{
areThereChildren = b;
}
Now back in the constructor of your contribution, call
installation.setAreThereChildren(true)
Finally, in the installation’s generateScript() method, simply add
if(areThereChildren)
{
//generate your script
}
else
{
//do something else? remove if nothing else needs to be done
}
But on purpose, we did not intend installation nodes to be aware if there are program nodes.
Basically, they should be “self contained”. I.e. the installation node could only define functions, which are then used by the program node, when required.
In the above workaround, this is not guaranteed that the program node is indeed present.
I.e. if the node is deleted or suppressed, the installation is not notified.