private JBPopup createLightWeightPopup(CreateDirectoryOrPackageHandler validator, String title, Consumer<PsiElement> consumer) {
NewItemSimplePopupPanel contentPanel = new NewItemSimplePopupPanel();
TextBox nameField = contentPanel.getTextField();
JBPopup popup = NewItemPopupUtil.createNewItemPopup(title, contentPanel, (JComponent)TargetAWT.to(nameField));
contentPanel.addValidator(value -> {
if (!validator.checkInput(value)) {
String message = InputValidatorEx.getErrorText(validator, value, LangBundle.message("incorrect.name"));
return new ValidableComponent.ValidationInfo(message);
}
return null;
});
contentPanel.setApplyAction(event -> {
String name = nameField.getValue();
validator.canClose(name);
popup.closeOk(event);
consumer.accept(validator.getCreatedElement());
});
return popup;
}