Open globallyunique opened 3 months ago
The only place to do this is in the generated code, there is no standard way to do this. To support this in a way that does not toch the generated code we would e.g have to insert some kind of call back function in the generated code or something similar.
I think an optional callback would be good to have, or maybe an optional custom factory? You could even define an instance template next to the DSL's structure definition (in .ast
or next to it).
We probably need many more "tuning" options indeed.
Another option is using the generation gap pattern, this allows for all kind of tuning of the AST code, not just for initialization.
Before I go down a path that isn't possible, for now, could I create a custom Box Provider that is a sub-class of the generated provider, switch my Box provider to be used by changing the mapping in CustomXXXnModelProjection, and override the getContent method to do something like check if there is anything in the model and if not add it?
This should not be done on the box providers, they are only used by the editor, so won't change the model unless it is opened in the editor. They are also not meant to be replaced, not even sure what will happen if you do.
@dslmeinte An optional factory is also an option indeed. And defining a template is also interesting, but less flexible as you cannot add code easily (unless treated as text).
@joswarmer Exactly: a programmatic (i.e., coded in a GPL) custom optional factory is the most flexible option.
Actually the generation gap pattern is even more flexible as it allows not only the initialisation to be adjusted but everything else as well.
Mandatory children that have only one possible concrete concept type are now added automatically with their parent.
For now the creation of mandatory children solves the main problem, we don't plan to make this generic as described above.
How can some concepts be created automatically when an instance of a model-unit is created, e.g., add a blank item to a list so the user doesn't need to add it.