public void init(List<? extends FileTemplate> templates) {
    FileTemplate oldSelection = getSelectedTemplate();
    String oldSelectionName = oldSelection != null? ((FileTemplateBase)oldSelection).getQualifiedName() : null;

    this.templates.clear();
    for (FileTemplate original : templates) {
      if (FileTemplateBase.isChild(original)) {
        continue;
      }
      FileTemplate copy = addCopy(original);
      copy.setChildren(ContainerUtil.map2Array(original.getChildren(), FileTemplate.class, template -> addCopy(template)));
    }
    initSelection(ContainerUtil.find(this.templates, base -> base.getQualifiedName().equals(oldSelectionName)));
  }
public void init(List<? extends FileTemplate> templates)