private void editPattern(@Nullable("null means new") Pair<FileNameMatcher, Language> item) {
    FileTypeManagerImpl.FileTypeWithDescriptor ftd = myRecognizedFileType.getSelectedFileType();
    if (ftd == null) return;
    FileType type = ftd.fileType();

    if (item == null) {
      FileTypeConfigurableInteractions.patternAdded.log(type);
    }
    else {
      FileTypeConfigurableInteractions.patternEdited.log(type);
    }

    String title = FileTypesBundle.message(item == null ? "filetype.edit.add.pattern.title" : "filetype.edit.edit.pattern.title");

    Language oldLanguage = item == null ? null : item.second;
    String oldPattern = item == null ? null : item.first.getPresentableString();
    FileTypePatternDialog dialog = new FileTypePatternDialog(oldPattern, type, oldLanguage);
    DialogBuilder builder = new DialogBuilder(myPatterns.myList);
    builder.setPreferredFocusComponent(dialog.getPatternField());
    builder.setCenterPanel(dialog.getMainPanel());
    builder.setTitle(title);
    builder.showModal(true);
    if (builder.getDialogWrapper().isOK()) {
      String pattern = dialog.getPatternField().getText();
      if (StringUtil.isEmpty(pattern)) return;

      FileNameMatcher matcher = FileTypeManager.parseFromString(pattern);
      FileTypeManagerImpl.FileTypeWithDescriptor registeredFtd = findExistingFileType(matcher);
      if (registeredFtd != null && registeredFtd.fileType() != type) {
        FileType registeredFileType = registeredFtd.fileType();
        if (registeredFileType.isReadOnly()) {
          Messages.showMessageDialog(myPatterns.myList,
                                     FileTypesBundle.message("filetype.edit.add.pattern.exists.error", registeredFileType.getDescription()),
                                     title, Messages.getErrorIcon());
          return;
        }
        int ret = Messages.showOkCancelDialog(myPatterns.myList, FileTypesBundle.message("filetype.edit.add.pattern.exists.message",
                                                                                         registeredFileType.getDescription()),
                                              FileTypesBundle.message("filetype.edit.add.pattern.exists.title"),
                                              FileTypesBundle.message("filetype.edit.add.pattern.reassign.button"),
                                              CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
        if (ret == Messages.OK) {
          myTempPatternsTable.removeAssociation(matcher, registeredFtd);
          myTempTemplateDataLanguages.removeAssociation(matcher, null);
        }
        else {
          return;
        }
      }

      if (item != null) {
        myTempPatternsTable.removeAssociation(item.first, ftd);
        myTempTemplateDataLanguages.removeAssociation(item.first, item.second);
      }
      myTempPatternsTable.addAssociation(matcher, ftd);
      Language language = dialog.getTemplateDataLanguage();
      if (language != null) {
        myTempTemplateDataLanguages.addAssociation(matcher, language);
      }

      updateExtensionList();
      myPatterns.select(pattern);
      IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(myPatterns.myList, true));
    }
  }
private void editPattern(@Nullable("null means new") Pair<FileNameMatcher, Language> item)