List of usage examples for com.intellij.openapi.ui InputValidatorEx InputValidatorEx
InputValidatorEx
From source file:com.intellij.ide.actions.CreateClassAction.java
License:Apache License
@Override protected void buildDialog(final Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder.setTitle(JavaCoreBundle.message("action.create.new.class")) .addKind("Class", PlatformIcons.CLASS_ICON, JavaTemplateUtil.INTERNAL_CLASS_TEMPLATE_NAME) .addKind("Interface", PlatformIcons.INTERFACE_ICON, JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME); Module module = ModuleUtilCore.findModuleForPsiElement(directory); assert module != null; LanguageLevel languageLevel = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module); if (languageLevel.isAtLeast(LanguageLevel.JDK_1_5)) { builder.addKind("Enum", PlatformIcons.ENUM_ICON, JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME); builder.addKind("Annotation", PlatformIcons.ANNOTATION_TYPE_ICON, JavaTemplateUtil.INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME); }// w ww . j a v a 2 s . c om for (FileTemplate template : FileTemplateManager.getInstance().getAllTemplates()) { final JavaCreateFromTemplateHandler handler = new JavaCreateFromTemplateHandler(); if (handler.handlesTemplate(template) && JavaCreateFromTemplateHandler.canCreate(directory)) { builder.addKind(template.getName(), JavaFileType.INSTANCE.getIcon(), template.getName()); } } builder.setValidator(new InputValidatorEx() { @Override public String getErrorText(String inputString) { if (inputString.length() > 0 && !PsiNameHelper.getInstance(project).isQualifiedName(inputString)) { return "This is not a valid Java qualified name"; } return null; } @Override public boolean checkInput(String inputString) { return true; } @Override public boolean canClose(String inputString) { return !StringUtil.isEmptyOrSpaces(inputString) && getErrorText(inputString) == null; } }); }
From source file:defrac.intellij.action.create.NewDelegateAction.java
License:Apache License
@Override protected void updateDialog(@NotNull final Project project, @NotNull final DefracFacet facet, @NotNull final AnActionEvent event, @NotNull final MultiPlatformCreateDialog<PsiFile> dialog) { dialog.setTitle(DefracBundle.message("dialog.new.delegate.title")); dialog.setValidator(new InputValidatorEx() { public String getErrorText(String inputString) { return inputString.length() > 0 && !PsiNameHelper.getInstance(project).isQualifiedName(inputString) ? "This is not a valid Java class name" : null;/*w ww . j ava 2 s .c o m*/ } public boolean checkInput(String inputString) { return true; } public boolean canClose(String inputString) { return !StringUtil.isEmptyOrSpaces(inputString) && this.getErrorText(inputString) == null; } }); }
From source file:defrac.intellij.action.create.NewMacroAction.java
License:Apache License
@Override protected void updateDialog(@NotNull final Project project, @NotNull final DefracFacet facet, @NotNull final AnActionEvent event, @NotNull final MultiPlatformCreateDialog<PsiFile> dialog) { dialog.setTitle(DefracBundle.message("dialog.new.macro.title")); dialog.setValidator(new InputValidatorEx() { public String getErrorText(String inputString) { return inputString.length() > 0 && !PsiNameHelper.getInstance(project).isIdentifier(inputString) ? "This is not a valid Java class name" : null;//w ww . ja va 2 s . c o m } public boolean checkInput(String inputString) { return true; } public boolean canClose(String inputString) { return !StringUtil.isEmptyOrSpaces(inputString) && this.getErrorText(inputString) == null; } }); }
From source file:org.consulo.compiler.impl.resourceCompiler.ResourceCompilerConfigurable.java
License:Apache License
private void showAddOrChangeDialog(final String initialValue) { String pattern = Messages.showInputDialog(myProject, "Pattern", "Enter Pattern", null, initialValue, new InputValidatorEx() { @Override//from w w w . ja va2 s. c o m public boolean checkInput(String inputString) { return (initialValue == null && myModel.getElementIndex(inputString) == -1 || initialValue != null) && getErrorText(inputString) == null; } @Override public boolean canClose(String inputString) { return true; } @Nullable @Override public String getErrorText(String inputString) { try { ResourceCompilerConfiguration.convertToRegexp(inputString); return null; } catch (Exception ex) { return ex.getMessage(); } } }); if (pattern != null) { if (initialValue != null) { myModel.remove(initialValue); } myModel.add(pattern); } }
From source file:org.intellij.coq.actions.CreateCoqFileAction.java
License:Open Source License
@Override protected void buildDialog(Project project, PsiDirectory psiDirectory, CreateFileFromTemplateDialog.Builder builder) { builder.setTitle(NEW_COQ_MODULE).addKind("Empty module", CoqIcons.FILE, "Coq Module"). /* addKind("Header file", ErlangIcons.HEADER, "Erlang Header"). addKind("EUnit tests", ErlangIcons.EUNIT, "Erlang EUnit Tests"). addKind("OTP application", ErlangIcons.OTP_APPLICATION, "Erlang Application"). addKind("OTP application resource file", ErlangIcons.OTP_APP_RESOURCE, "Erlang Application Resource File"). addKind("OTP supervisor", ErlangIcons.OTP_SUPERVISOR, "Erlang Supervisor"). addKind("OTP gen_server", ErlangIcons.OTP_GEN_SERVER, "Erlang Gen Server"). addKind("OTP gen_fsm", ErlangIcons.OTP_GEN_FSM, "Erlang Gen FSM"). addKind("OTP gen_event", ErlangIcons.OTP_GEN_EVENT, "Erlang Gen Event").*/ setValidator(new InputValidatorEx() { @Override// w ww . j av a 2 s .c o m public boolean checkInput(String inputString) { return getErrorText(inputString) == null; } @Override public boolean canClose(String inputString) { return getErrorText(inputString) == null; } @Nullable @Override public String getErrorText(String inputString) { return null; } }); }
From source file:org.intellij.erlang.actions.CreateErlangFileAction.java
License:Apache License
@Override protected void buildDialog(final Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder.setTitle(NEW_ERLANG_FILE).addKind("Empty module", ErlangIcons.FILE, "Erlang Module") .addKind("Header file", ErlangIcons.HEADER, "Erlang Header") .addKind("EUnit tests", ErlangIcons.EUNIT, "Erlang EUnit Tests") .addKind("OTP application", ErlangIcons.OTP_APPLICATION, "Erlang Application") .addKind("OTP application resource file", ErlangIcons.OTP_APP_RESOURCE, "Erlang Application Resource File") .addKind("OTP supervisor", ErlangIcons.OTP_SUPERVISOR, "Erlang Supervisor") .addKind("OTP gen_server", ErlangIcons.OTP_GEN_SERVER, "Erlang Gen Server") .addKind("OTP gen_fsm", ErlangIcons.OTP_GEN_FSM, "Erlang Gen FSM") .addKind("OTP gen_event", ErlangIcons.OTP_GEN_EVENT, "Erlang Gen Event") .setValidator(new InputValidatorEx() { @Override/*from w ww. ja v a 2 s. c o m*/ public boolean checkInput(String inputString) { return true; } @Override public boolean canClose(String inputString) { return !StringUtil.isEmptyOrSpaces(inputString) && getErrorText(inputString) == null; } @Override public String getErrorText(String inputString) { String error = " is not a valid Erlang module name"; if (StringUtil.isEmpty(inputString)) return null; try { ErlangElementFactory.createQAtomFromText(project, inputString); if (inputString != null && inputString.equals(FileUtil.sanitizeFileName(inputString))) { return null; } return "'" + inputString + "'" + error; } catch (Exception ignored) { } return "'" + inputString + "'" + error; } }); }
From source file:org.intellij.xquery.actions.CreateXQueryFileAction.java
License:Apache License
private InputValidatorEx getValidator() { return new InputValidatorEx() { @Override// w w w . j a v a2 s. c o m public boolean checkInput(String inputString) { return true; } @Override public boolean canClose(String inputString) { return !StringUtil.isEmptyOrSpaces(inputString) && getErrorText(inputString) == null; } @Override public String getErrorText(String inputString) { String error = " is not a valid XQuery Module name"; if (StringUtil.isEmpty(inputString)) return null; if (isValidFileName(inputString)) { return null; } return "'" + inputString + "'" + error; } }; }
From source file:org.textmapper.idea.actions.CreateTextmapperFileAction.java
License:Open Source License
@Override protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder.setTitle(TextmapperBundle.message("newfile.action.text")); for (TemplatesHandler handler : TemplatesHandler.EP_NAME.getExtensions()) { handler.addTemplates(builder);/*from w w w. jav a 2 s . c om*/ } builder.addKind("generates Javascript", StdFileTypes.JS.getIcon(), "GrammarForJS.tm"); builder.setValidator(new InputValidatorEx() { @Nullable @Override public String getErrorText(String inputString) { return null; } @Override public boolean checkInput(String inputString) { return StringUtil.isJavaIdentifier(inputString); } @Override public boolean canClose(String inputString) { return checkInput(inputString); } }); }
From source file:ru.artlebedev.idea.plugins.parser.zencoding.ZenCodingTemplate.java
License:Apache License
public void wrap(final String selection, @NotNull final CustomTemplateCallback callback) { InputValidatorEx validator = new InputValidatorEx() { public String getErrorText(String inputString) { if (!checkTemplateKey(inputString, callback)) { return XmlBundle.message("zen.coding.incorrect.abbreviation.error"); }//w w w . j a v a 2 s .com return null; } public boolean checkInput(String inputString) { return getErrorText(inputString) == null; } public boolean canClose(String inputString) { return checkInput(inputString); } }; final String abbreviation = Messages.showInputDialog(callback.getProject(), XmlBundle.message("zen.coding.enter.abbreviation.dialog.label"), XmlBundle.message("zen.coding.title"), Messages.getQuestionIcon(), "", validator); if (abbreviation != null) { doWrap(selection, abbreviation, callback); } }