private void editTemplate(@NotNull PostfixTemplateCheckedTreeNode lastPathComponent) {
    PostfixTemplate template = lastPathComponent.getTemplate();
    PostfixTemplateProvider provider = lastPathComponent.getTemplateProvider();
    if (isEditable(template)) {
      PostfixTemplate templateToEdit =
        template instanceof PostfixChangedBuiltinTemplate ? ((PostfixChangedBuiltinTemplate)template).getDelegate()
                                                          : template;
      PostfixTemplateEditor editor = provider.createEditor(templateToEdit);
      if (editor == null) {
        editor = new DefaultPostfixTemplateEditor(provider, templateToEdit);
      }
      String providerName = StringUtil.notNullize(provider.getPresentableName());
      PostfixEditTemplateDialog dialog = new PostfixEditTemplateDialog(this, editor, providerName, templateToEdit);
      if (dialog.showAndGet()) {
        PostfixTemplate newTemplate = editor.createTemplate(template.getId(), dialog.getTemplateName());
        if (newTemplate.equals(template)) {
          return;
        }
        if (template.isBuiltin()) {
          PostfixTemplate builtin = template instanceof PostfixChangedBuiltinTemplate
                                    ? ((PostfixChangedBuiltinTemplate)template).getBuiltinTemplate()
                                    : templateToEdit;
          lastPathComponent.setTemplate(new PostfixChangedBuiltinTemplate(newTemplate, builtin));
        }
        else {
          lastPathComponent.setTemplate(newTemplate);
        }
        myModel.nodeStructureChanged(lastPathComponent);

        //update before /after panel
        selectionChanged();
      }
    }
  }
private void editTemplate(@NotNull PostfixTemplateCheckedTreeNode lastPathComponent)