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;
}
}
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;
}
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;
}
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();
}
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;
}
Aggregations