@NotNull public PsiElement[] invokeDialog(@NotNull final Project project, @NotNull final PsiDirectory directory) { final CreateResourceDirectoryDialog dialog = new CreateResourceDirectoryDialog(project, myResourceFolderType, directory, AndroidPsiUtils.getModuleSafely(directory)) { @Override protected InputValidator createValidator() { return CreateResourceDirectoryAction.this.createValidator(project, directory); } }; dialog.setTitle(AndroidBundle.message("new.resource.dir.dialog.title")); dialog.show(); final InputValidator validator = dialog.getValidator(); if (validator == null) { return PsiElement.EMPTY_ARRAY; } return ((MyInputValidator)validator).getCreatedElements(); }
@NotNull @Override protected PsiElement[] invokeDialog(@NotNull Project project, @NotNull DataContext dataContext) { final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); if (view != null) { // If you're in the Android View, we want to ask you not just the filename but also let you // create other resource folder configurations AbstractProjectViewPane pane = ProjectView.getInstance(project).getCurrentProjectViewPane(); if (pane instanceof AndroidProjectViewPane) { return CreateResourceFileAction.getInstance().invokeDialog(project, dataContext); } final PsiDirectory directory = view.getOrChooseDirectory(); if (directory != null) { InputValidator validator = createValidator(project, directory); Messages.showInputDialog(project, AndroidBundle.message("new.file.dialog.text"), AndroidBundle.message("new.typed.resource.dialog.title", myResourcePresentableName), Messages.getQuestionIcon(), "", validator); } } return PsiElement.EMPTY_ARRAY; }
protected MyDialog(@NotNull AndroidFacet facet, @Nullable InputValidator validator) { super(facet.getModule().getProject()); myValidator = validator; setTitle(AndroidBundle.message("new.typed.resource.dialog.title", myResourcePresentableName)); final List<String> tagNames = getSortedAllowedTagNames(facet); myRootElementField = new TextFieldWithAutoCompletion<String>( facet.getModule().getProject(), new TextFieldWithAutoCompletion.StringsCompletionProvider(tagNames, null), true, null); myRootElementField.setText(myDefaultRootTag); myRootElementFieldWrapper.add(myRootElementField, BorderLayout.CENTER); myRootElementLabel.setLabelFor(myRootElementField); init(); myFileNameField.getDocument().addDocumentListener(new DocumentAdapter() { @Override public void textChanged(DocumentEvent event) { final String text = myFileNameField.getText().trim(); if (myValidator instanceof InputValidatorEx) { setErrorText(((InputValidatorEx) myValidator).getErrorText(text)); } } }); }
@NotNull private InputValidator getRegexInputValidator() { return new InputValidator() { @Override public boolean checkInput(String string) { try { if (string == null || string.trim().isEmpty()) { //do not allow null or blank entries return false; } Pattern.compile(string); return true; } catch (PatternSyntaxException e) { return false; } } @Override public boolean canClose(String s) { return true; } }; }
@Override public void configure(@Nonnull Binder binder) { binder.bind(Project.class) .toInstance(project); // Binding InputValidator related classes binder.bind(InputValidator.class) .annotatedWith(Name.NAME_VALIDATOR.annotation()) .to(NameValidator.class); binder.bind(InputValidator.class) .annotatedWith(Name.JSON_VALIDATOR.annotation()) .to(JsonValidator.class); binder.bind(InputValidator.class) .annotatedWith(Name.CLASS_PREFIX_VALIDATOR.annotation()) .to(ClassPrefixValidator.class); binder.bind(InputValidator.class) .annotatedWith(Name.CLASS_SUFFIX_VALIDATOR.annotation()) .to(ClassSuffixValidator.class); // Binding NamePolicy classes binder.bind(NamePolicy.class) .annotatedWith(Name.CLASS_NAME_POLICY.annotation()) .to(ClassNamePolicy.class); binder.bind(NamePolicy.class) .annotatedWith(Name.FIELD_NAME_POLICY.annotation()) .to(FieldNamePolicy.class); binder.bind(NamePolicy.class) .annotatedWith(Name.METHOD_NAME_POLICY.annotation()) .to(MethodNamePolicy.class); binder.bind(NamePolicy.class) .annotatedWith(Name.PARAMETER_NAME_POLICY.annotation()) .to(ParameterNamePolicy.class); // Binding other classes binder.bind(Json2JavaBundle.class) .toInstance(Json2JavaBundle.getInstance()); // Installation factory modules binder.install(new FactoryModuleBuilder().build(CommandActionFactory.class)); }
@Override public void actionPerformed(AnActionEvent e) { final List<? extends RadViewComponent> targets = mySelectedChildren; if (targets.isEmpty()) { return; } String currentWeight = targets.get(0).getTag().getAttributeValue(ATTR_LAYOUT_WEIGHT, ANDROID_URI); if (currentWeight == null || currentWeight.isEmpty()) { currentWeight = "0.0"; } String title = getTemplatePresentation().getDescription(); InputValidator validator = null; // TODO: Number validation! final String weight = Messages.showInputDialog(myDesigner, "Enter Weight Value:", title, null, currentWeight, validator); if (weight != null) { myDesigner.getToolProvider().execute(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { if (weight.isEmpty()) { // Remove attributes ClearWeightsAction.clearWeights(myLayout, targets); } else { for (RadViewComponent target : targets) { target.getTag().setAttribute(ATTR_LAYOUT_WEIGHT, ANDROID_URI, weight); } } } }); } }, getTemplatePresentation().getDescription(), true); } }
@Nullable public static PsiDirectory selectFolderDir(final Project project, VirtualFile res, ResourceFolderType folderType) { final PsiDirectory directory = PsiManager.getInstance(project).findDirectory(res); if (directory == null) { return null; } if (ApplicationManager.getApplication().isUnitTestMode() && ourTargetFolderName != null) { PsiDirectory subDirectory = directory.findSubdirectory(ourTargetFolderName); if (subDirectory != null) { return subDirectory; } return directory.createSubdirectory(ourTargetFolderName); } final CreateResourceDirectoryDialog dialog = new CreateResourceDirectoryDialog(project, folderType, directory, null) { @Override protected InputValidator createValidator() { return new ResourceDirectorySelector(project, directory); } }; dialog.setTitle("Select Resource Directory"); dialog.show(); final InputValidator validator = dialog.getValidator(); if (validator != null) { PsiElement[] createdElements = ((ResourceDirectorySelector)validator).getCreatedElements(); if (createdElements != null && createdElements.length > 0) { return (PsiDirectory)createdElements[0]; } } return null; }
public InputHostDialog(Component parentComponent, String message, String title, Icon icon, String initialValue, InputValidator validator) { super(parentComponent, message, title, icon, initialValue, validator); }
@Override public void actionPerformed(AnActionEvent e) { final List<? extends RadViewComponent> targets = mySelectedChildren; if (targets.isEmpty()) { return; } String currentWeight = targets.get(0).getTag().getAttributeValue(ATTR_LAYOUT_WEIGHT, CORDOVASTUDIO_URI); if (currentWeight == null || currentWeight.isEmpty()) { currentWeight = "0.0"; } String title = getTemplatePresentation().getDescription(); InputValidator validator = null; // TODO: Number validation! final String weight = Messages.showInputDialog(myDesigner, "Enter Weight Value:", title, null, currentWeight, validator); if (weight != null) { myDesigner.getToolProvider().execute(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { if (weight.isEmpty()) { // Remove attributes ClearWeightsAction.clearWeights(myLayout, targets); } else { for (RadViewComponent target : targets) { target.getTag().setAttribute(ATTR_LAYOUT_WEIGHT, CORDOVASTUDIO_URI, weight); } } } }); } }, getTemplatePresentation().getDescription(), true); } }
@Override public Builder setValidator(InputValidator validator) { myDialog.myInputValidator = validator; return this; }
public InputHostDialog(Component parent, String message, String title, Icon icon, String initialValue, InputValidator validator) { super(parent, message, title, icon, initialValue, validator); }
@Nullable protected InputValidator createValidator(@NotNull String subdirName) { return null; }
public InputValidator getValidator() { return myValidator; }
protected InputValidator createValidator(Project project, PsiDirectory directory) { return new MyValidator(project, directory); }
public void setValidator(@Nullable final InputValidator value) { inputValidator = value; }
Builder setValidator(InputValidator validator);
protected abstract InputValidator createValidator();