Structures may have dynamic content, produced by generators.

Generators can be added to structure and moved around in the same way other items are added, as described in Changing Structure Content. A generator will have effect on the whole sub-tree under its parent.

Generators are a separate entities, managed by Structure add-on. So to create a dynamic structure, we need to create a generator first and then insert it into the structure.

1.  Create generator instance

You create a generator instance by calling GeneratorManager.

long generatorId = myStructureComponents.getGeneratorManager().createGenerator(
  CoreStructureGenerators.SORTER_AGILE_RANK, 
  ImmutableMap.of(CoreGeneratorParameters.SORT_DESCENDING, false), 
  structureId);
CODE

Note the third parameter – the generator is "owned" by a structure, so we should pass the ID of the owning structure.

2. Insert generator into the forest

Find parent row under which you'd like the forest to be automated. To apply generator to the whole forest insert generator at the top level by making "under" coordinate zero.

Do not use "after" and "before" coordinates unless you are adding an Inserter.

forestSource.apply(new ForestAction.Add(CoreIdentities.generator(generatorId), under, 0, 0));
CODE

This is it! Next time you read the contents of this forest source, it will have the results of this generator applied.