Search in sources :

Example 6 with InputValidator

use of com.intellij.openapi.ui.InputValidator in project intellij-plugins by JetBrains.

the class CucumberCreateStepFixBase method askUserForFilePath.

@Nullable
private static CreateStepDefinitionFileModel askUserForFilePath(@NotNull final GherkinStep step) {
    final InputValidator validator = new InputValidator() {

        public boolean checkInput(final String filePath) {
            return !StringUtil.isEmpty(filePath);
        }

        public boolean canClose(final String fileName) {
            return true;
        }
    };
    Map<BDDFrameworkType, String> supportedFileTypesAndDefaultFileNames = new HashMap<>();
    Map<BDDFrameworkType, PsiDirectory> fileTypeToDefaultDirectoryMap = new HashMap<>();
    for (CucumberJvmExtensionPoint e : Extensions.getExtensions(CucumberJvmExtensionPoint.EP_NAME)) {
        if (e instanceof OptionalStepDefinitionExtensionPoint) {
            // Skip if framework file creation support is optional
            if (!((OptionalStepDefinitionExtensionPoint) e).participateInStepDefinitionCreation(step)) {
                continue;
            }
        }
        supportedFileTypesAndDefaultFileNames.put(e.getStepFileType(), e.getStepDefinitionCreator().getDefaultStepFileName(step));
        fileTypeToDefaultDirectoryMap.put(e.getStepFileType(), e.getStepDefinitionCreator().getDefaultStepDefinitionFolder(step));
    }
    CreateStepDefinitionFileModel model = new CreateStepDefinitionFileModel(step.getProject(), supportedFileTypesAndDefaultFileNames, fileTypeToDefaultDirectoryMap);
    CreateStepDefinitionFileDialog createStepDefinitionFileDialog = new CreateStepDefinitionFileDialog(step.getProject(), model, validator);
    if (createStepDefinitionFileDialog.showAndGet()) {
        return model;
    } else {
        return null;
    }
}
Also used : InputValidator(com.intellij.openapi.ui.InputValidator) HashMap(com.intellij.util.containers.HashMap) PsiDirectory(com.intellij.psi.PsiDirectory) CreateStepDefinitionFileModel(org.jetbrains.plugins.cucumber.inspections.model.CreateStepDefinitionFileModel) CreateStepDefinitionFileDialog(org.jetbrains.plugins.cucumber.inspections.ui.CreateStepDefinitionFileDialog) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with InputValidator

use of com.intellij.openapi.ui.InputValidator in project android by JetBrains.

the class CreateTypedResourceFileAction method invokeDialog.

@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;
}
Also used : AndroidProjectViewPane(com.android.tools.idea.navigator.AndroidProjectViewPane) InputValidator(com.intellij.openapi.ui.InputValidator) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with InputValidator

use of com.intellij.openapi.ui.InputValidator in project android by JetBrains.

the class CreateMultiRootResourceFileAction method invokeDialog.

@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);
            final AndroidFacet facet = AndroidFacet.getInstance(directory);
            if (facet != null) {
                final MyDialog dialog = new MyDialog(facet, validator);
                dialog.show();
                return PsiElement.EMPTY_ARRAY;
            }
        }
    }
    return PsiElement.EMPTY_ARRAY;
}
Also used : AndroidProjectViewPane(com.android.tools.idea.navigator.AndroidProjectViewPane) InputValidator(com.intellij.openapi.ui.InputValidator) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with InputValidator

use of com.intellij.openapi.ui.InputValidator in project android by JetBrains.

the class CreateResourceFileAction method doCreateFileResource.

@NotNull
private static PsiElement[] doCreateFileResource(@NotNull AndroidFacet facet, @NotNull final ResourceFolderType resType, @Nullable String resName, @Nullable String rootElement, @Nullable FolderConfiguration config, boolean chooseResName, @Nullable String dialogTitle, @Nullable PsiDirectory resDirectory, @Nullable DataContext dataContext, final boolean navigate) {
    final CreateResourceFileAction action = getInstance();
    final Project project = facet.getModule().getProject();
    action.myNavigate = navigate;
    CreateResourceFileDialogBase.ValidatorFactory validatorFactory = action.createValidatorFactory(project);
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        String subdirName = resType.getName();
        VirtualFile resDir = facet.getPrimaryResourceDir();
        if (resDir == null) {
            return PsiElement.EMPTY_ARRAY;
        }
        PsiDirectory resourceDir = PsiManager.getInstance(project).findDirectory(resDir);
        if (resourceDir == null) {
            return PsiElement.EMPTY_ARRAY;
        }
        InputValidator inputValidator = validatorFactory.create(resourceDir, subdirName, null);
        // Simulate the dialog OK action by inlining the checkInput and canClose, before getCreatedElements.
        return (inputValidator.checkInput(resName) && inputValidator.canClose(resName)) ? ((MyInputValidator) inputValidator).getCreatedElements() : PsiElement.EMPTY_ARRAY;
    }
    NewResourceCreationHandler newResourceHandler = NewResourceCreationHandler.getInstance(project);
    final CreateResourceFileDialogBase dialog = newResourceHandler.createNewResourceFileDialog(facet, action.mySubactions.values(), resType, resName, rootElement, config, chooseResName, true, resDirectory, dataContext, validatorFactory);
    if (dialogTitle != null) {
        dialog.setTitle(dialogTitle);
    }
    if (!dialog.showAndGet()) {
        return PsiElement.EMPTY_ARRAY;
    }
    return dialog.getCreatedElements();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) InputValidator(com.intellij.openapi.ui.InputValidator) PsiDirectory(com.intellij.psi.PsiDirectory) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with InputValidator

use of com.intellij.openapi.ui.InputValidator in project intellij-community by JetBrains.

the class AddNewFavoritesListAction method doAddNewFavoritesList.

public static String doAddNewFavoritesList(final Project project) {
    final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
    final String name = Messages.showInputDialog(project, IdeBundle.message("prompt.input.new.favorites.list.name"), IdeBundle.message("title.add.new.favorites.list"), Messages.getInformationIcon(), getUniqueName(project), new InputValidator() {

        @Override
        public boolean checkInput(String inputString) {
            return inputString != null && inputString.trim().length() > 0;
        }

        @Override
        public boolean canClose(String inputString) {
            inputString = inputString.trim();
            if (favoritesManager.getAvailableFavoritesListNames().contains(inputString)) {
                Messages.showErrorDialog(project, IdeBundle.message("error.favorites.list.already.exists", inputString.trim()), IdeBundle.message("title.unable.to.add.favorites.list"));
                return false;
            }
            return inputString.length() > 0;
        }
    });
    if (name == null || name.length() == 0)
        return null;
    favoritesManager.createNewList(name);
    return name;
}
Also used : InputValidator(com.intellij.openapi.ui.InputValidator) FavoritesManager(com.intellij.ide.favoritesTreeView.FavoritesManager)

Aggregations

InputValidator (com.intellij.openapi.ui.InputValidator)15 PsiDirectory (com.intellij.psi.PsiDirectory)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 AndroidProjectViewPane (com.android.tools.idea.navigator.AndroidProjectViewPane)2 IdeView (com.intellij.ide.IdeView)2 AbstractProjectViewPane (com.intellij.ide.projectView.impl.AbstractProjectViewPane)2 PsiElement (com.intellij.psi.PsiElement)2 PsiReference (com.intellij.psi.PsiReference)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProjectGroup (com.intellij.ide.ProjectGroup)1 FavoritesManager (com.intellij.ide.favoritesTreeView.FavoritesManager)1 ASTNode (com.intellij.lang.ASTNode)1 Application (com.intellij.openapi.application.Application)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Module (com.intellij.openapi.module.Module)1 TestInputDialog (com.intellij.openapi.ui.TestInputDialog)1