JBPopup (@NotNull MyInputValidator validator, @NotNull Consumer<? super PsiElement[]> consumer) { NewItemSimplePopupPanel contentPanel = new NewItemSimplePopupPanel(); JTextField nameField = contentPanel.getTextField(); JBPopup popup = NewItemPopupUtil.createNewItemPopup(IdeBundle.message("title.new.file"), contentPanel, nameField); contentPanel.setApplyAction(event -> { String name = nameField.getText(); if (validator.checkInput(name) && validator.canClose(name)) { popup.closeOk(event); consumer.accept(validator.getCreatedElements()); } else { String errorMessage = validator instanceof InputValidatorEx ? ((InputValidatorEx)validator).getErrorText(name) : LangBundle.message("incorrect.name"); contentPanel.setError(errorMessage); } }); return popup; }