Example usage for com.intellij.openapi.ui Messages getQuestionIcon

List of usage examples for com.intellij.openapi.ui Messages getQuestionIcon

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages getQuestionIcon.

Prototype

@NotNull
    public static Icon getQuestionIcon() 

Source Link

Usage

From source file:org.jetbrains.jet.plugin.refactoring.safeDelete.KotlinSafeDeleteProcessor.java

License:Apache License

@Nullable
private static Collection<? extends PsiElement> checkParametersInMethodHierarchy(
        @NotNull PsiParameter parameter) {
    PsiMethod method = (PsiMethod) parameter.getDeclarationScope();
    int parameterIndex = method.getParameterList().getParameterIndex(parameter);

    Set<PsiElement> parametersToDelete = collectParametersToDelete(method, parameterIndex);
    if (parametersToDelete.size() > 1) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            return parametersToDelete;
        }/*from  w  ww.  ja  v  a  2 s  .  c  om*/

        String message = JetBundle.message("delete.param.in.method.hierarchy",
                JetRefactoringUtil.formatJavaOrLightMethod(method));
        int exitCode = Messages.showOkCancelDialog(parameter.getProject(), message,
                IdeBundle.message("title.warning"), Messages.getQuestionIcon());
        if (exitCode == Messages.OK) {
            return parametersToDelete;
        } else {
            return null;
        }
    }

    return parametersToDelete;
}

From source file:org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil.java

License:Apache License

@NotNull
private static List<? extends PsiElement> askUserForMethodsToSearch(@NotNull KtDeclaration declaration,
        @NotNull CallableDescriptor declarationDescriptor,
        @NotNull Map<PsiElement, CallableDescriptor> overriddenElementsToDescriptor,
        @NotNull List<String> superClasses, @NotNull String actionStringKey) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return ContainerUtil.newArrayList(overriddenElementsToDescriptor.keySet());
    }/*from w w  w.j  av  a2s .co m*/

    String superClassesStr = "\n" + StringUtil.join(superClasses, "");
    String message = KotlinBundle.message("x.overrides.y.in.class.list",
            DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.render(declarationDescriptor),
            IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES
                    .render(declarationDescriptor.getContainingDeclaration()),
            superClassesStr, KotlinBundle.message(actionStringKey));

    int exitCode = Messages.showYesNoCancelDialog(declaration.getProject(), message,
            IdeBundle.message("title.warning"), Messages.getQuestionIcon());
    switch (exitCode) {
    case Messages.YES:
        return ContainerUtil.newArrayList(overriddenElementsToDescriptor.keySet());
    case Messages.NO:
        return Collections.singletonList(declaration);
    default:
        return Collections.emptyList();
    }
}

From source file:org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil.java

License:Apache License

@Nullable
public static Collection<? extends PsiElement> checkParametersInMethodHierarchy(
        @NotNull PsiParameter parameter) {
    PsiMethod method = (PsiMethod) parameter.getDeclarationScope();

    Set<PsiElement> parametersToDelete = collectParametersHierarchy(method, parameter);
    if (parametersToDelete.size() > 1) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            return parametersToDelete;
        }//from www. ja  v a2 s .co m

        String message = KotlinBundle.message("delete.param.in.method.hierarchy",
                formatJavaOrLightMethod(method));
        int exitCode = Messages.showOkCancelDialog(parameter.getProject(), message,
                IdeBundle.message("title.warning"), Messages.getQuestionIcon());
        if (exitCode == Messages.OK) {
            return parametersToDelete;
        } else {
            return null;
        }
    }

    return parametersToDelete;
}

From source file:org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java

License:Apache License

@Nullable
private MoveDestination selectPackageBasedMoveDestination(boolean askIfDoesNotExist) {
    String packageName = getTargetPackage();

    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
    PackageWrapper targetPackage = new PackageWrapper(PsiManager.getInstance(myProject), packageName);
    if (!targetPackage.exists() && askIfDoesNotExist) {
        int ret = Messages.showYesNoDialog(myProject,
                RefactoringBundle.message("package.does.not.exist", packageName),
                RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
        if (ret != Messages.YES)
            return null;
    }//w  w  w  .  j  a  v a  2 s . com

    return ((DestinationFolderComboBox) destinationFolderCB).selectDirectory(targetPackage, false);
}

From source file:org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java

License:Apache License

@Nullable
private KotlinMoveTarget selectMoveTarget() {
    String message = verifyBeforeRun();
    if (message != null) {
        setErrorText(message);/*from   www .  j  a  v a2 s . com*/
        return null;
    }

    setErrorText(null);

    List<KtFile> sourceFiles = getSourceFiles(getSelectedElementsToMove());
    PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles);

    if (isMoveToPackage()) {
        final MoveDestination moveDestination = selectPackageBasedMoveDestination(true);
        if (moveDestination == null)
            return null;

        final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
        if (targetFileName != null && !checkTargetFileName(targetFileName))
            return null;

        PsiDirectory targetDirectory = moveDestination.getTargetIfExists(sourceDirectory);

        List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName,
                targetDirectory);
        if (!filesExistingInTargetDir.isEmpty()) {
            if (!CollectionsKt.intersect(sourceFiles, filesExistingInTargetDir).isEmpty()) {
                setErrorText("Can't move to the original file(s)");
                return null;
            }

            if (filesExistingInTargetDir.size() > 1) {
                String filePathsToReport = StringUtil.join(filesExistingInTargetDir,
                        new Function<PsiFile, String>() {
                            @Override
                            public String fun(PsiFile file) {
                                return file.getVirtualFile().getPath();
                            }
                        }, "\n");
                Messages.showErrorDialog(myProject,
                        "Cannot perform refactoring since the following files already exist:\n\n"
                                + filePathsToReport,
                        RefactoringBundle.message("move.title"));
                return null;
            }

            String question = String.format(
                    "File '%s' already exists. Do you want to move selected declarations to this file?",
                    filesExistingInTargetDir.get(0).getVirtualFile().getPath());
            int ret = Messages.showYesNoDialog(myProject, question, RefactoringBundle.message("move.title"),
                    Messages.getQuestionIcon());
            if (ret != Messages.YES)
                return null;
        }

        // All source files must be in the same directory
        return new KotlinMoveTargetForDeferredFile(new FqName(getTargetPackage()),
                moveDestination.getTargetIfExists(sourceFiles.get(0)), new Function1<KtFile, KtFile>() {
                    @Override
                    public KtFile invoke(@NotNull KtFile originalFile) {
                        return JetRefactoringUtilKt.getOrCreateKotlinFile(
                                targetFileName != null ? targetFileName : originalFile.getName(),
                                moveDestination.getTargetDirectory(originalFile));
                    }
                });
    }

    final File targetFile = new File(getTargetFilePath());
    if (!checkTargetFileName(targetFile.getName()))
        return null;
    KtFile jetFile = (KtFile) JetRefactoringUtilKt.toPsiFile(targetFile, myProject);
    if (jetFile != null) {
        if (sourceFiles.size() == 1 && sourceFiles.contains(jetFile)) {
            setErrorText("Can't move to the original file");
            return null;
        }

        return new KotlinMoveTargetForExistingElement(jetFile);
    }

    File targetDir = targetFile.getParentFile();
    final PsiDirectory psiDirectory = targetDir != null
            ? JetRefactoringUtilKt.toPsiDirectory(targetDir, myProject)
            : null;
    if (psiDirectory == null) {
        setErrorText("No directory found for file: " + targetFile.getPath());
        return null;
    }

    Set<FqName> sourcePackageFqNames = CollectionsKt.mapTo(sourceFiles, new LinkedHashSet<FqName>(),
            new Function1<KtFile, FqName>() {
                @Override
                public FqName invoke(KtFile file) {
                    return file.getPackageFqName();
                }
            });
    FqName targetPackageFqName = CollectionsKt.singleOrNull(sourcePackageFqNames);
    if (targetPackageFqName == null) {
        PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
        if (psiPackage == null) {
            setErrorText("Could not find package corresponding to " + targetDir.getPath());
            return null;
        }
        targetPackageFqName = new FqName(psiPackage.getQualifiedName());
    }

    final String finalTargetPackageFqName = targetPackageFqName.asString();
    return new KotlinMoveTargetForDeferredFile(targetPackageFqName, psiDirectory,
            new Function1<KtFile, KtFile>() {
                @Override
                public KtFile invoke(@NotNull KtFile originalFile) {
                    return JetRefactoringUtilKt.getOrCreateKotlinFile(targetFile.getName(), psiDirectory,
                            finalTargetPackageFqName);
                }
            });
}

From source file:org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java

License:Apache License

@Override
protected void doAction() {
    KotlinMoveTarget target = selectMoveTarget();
    if (target == null)
        return;//  w ww .j a v a2  s . c  o m

    saveRefactoringSettings();

    List<KtNamedDeclaration> elementsToMove = getSelectedElementsToMove();
    final List<KtFile> sourceFiles = getSourceFiles(elementsToMove);
    final PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles);

    for (PsiElement element : elementsToMove) {
        String message = target.verify(element.getContainingFile());
        if (message != null) {
            CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), message, null,
                    myProject);
            return;
        }
    }

    try {
        boolean deleteSourceFile = false;

        if (isFullFileMove()) {
            if (isMoveToPackage()) {
                final MoveDestination moveDestination = selectPackageBasedMoveDestination(false);
                //noinspection ConstantConditions
                PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory);
                final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
                List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles,
                        targetFileName, targetDir);
                if (filesExistingInTargetDir.isEmpty()) {
                    PsiDirectory targetDirectory = ApplicationUtilsKt
                            .runWriteAction(new Function0<PsiDirectory>() {
                                @Override
                                public PsiDirectory invoke() {
                                    return moveDestination.getTargetDirectory(sourceDirectory);
                                }
                            });

                    for (KtFile sourceFile : sourceFiles) {
                        MoveUtilsKt.setUpdatePackageDirective(sourceFile,
                                cbUpdatePackageDirective.isSelected());
                    }

                    invokeRefactoring(new MoveFilesOrDirectoriesProcessor(myProject,
                            sourceFiles.toArray(new PsiElement[sourceFiles.size()]), targetDirectory, true,
                            isSearchInComments(), isSearchInNonJavaFiles(), new MoveCallback() {
                                @Override
                                public void refactoringCompleted() {
                                    try {
                                        if (targetFileName != null) {
                                            CollectionsKt.single(sourceFiles).setName(targetFileName);
                                        }
                                    } finally {
                                        if (moveCallback != null) {
                                            moveCallback.refactoringCompleted();
                                        }
                                    }
                                }
                            }, EmptyRunnable.INSTANCE) {
                        @Override
                        protected String getCommandName() {
                            return targetFileName != null
                                    ? "Move " + CollectionsKt.single(sourceFiles).getName()
                                    : "Move";
                        }

                        @Override
                        protected void performRefactoring(@NotNull UsageInfo[] usages) {
                            if (targetFileName != null) {
                                KtFile sourceFile = CollectionsKt.single(sourceFiles);
                                //noinspection ConstantConditions
                                String temporaryName = UniqueNameGenerator.generateUniqueName("temp", "", ".kt",
                                        ArraysKt.map(sourceFile.getContainingDirectory().getFiles(),
                                                new Function1<PsiFile, String>() {
                                                    @Override
                                                    public String invoke(PsiFile file) {
                                                        return file.getName();
                                                    }
                                                }));
                                sourceFile.setName(temporaryName);
                            }

                            super.performRefactoring(usages);
                        }
                    });

                    return;
                }
            }

            int ret = Messages.showYesNoCancelDialog(myProject,
                    "You are about to move all declarations out of the source file(s). Do you want to delete empty files?",
                    RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
            if (ret == Messages.CANCEL)
                return;
            deleteSourceFile = ret == Messages.YES;
        }

        MoveDeclarationsDescriptor options = new MoveDeclarationsDescriptor(elementsToMove, target,
                MoveDeclarationsDelegate.TopLevel.INSTANCE, isSearchInComments(), isSearchInNonJavaFiles(),
                true, deleteSourceFile, moveCallback, false);
        invokeRefactoring(new MoveKotlinDeclarationsProcessor(myProject, options, Mover.Default.INSTANCE));
    } catch (IncorrectOperationException e) {
        CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), null,
                myProject);
    }
}

From source file:org.jetbrains.kotlin.idea.refactoring.move.moveTopLevelDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java

License:Apache License

@Nullable
private KotlinMoveTarget selectMoveTarget() {
    String message = verifyBeforeRun();
    if (message != null) {
        setErrorText(message);//  w w w  .  java2  s .c  o m
        return null;
    }

    setErrorText(null);

    List<KtFile> sourceFiles = getSourceFiles(getSelectedElementsToMove());
    PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles);

    if (isMoveToPackage()) {
        final MoveDestination moveDestination = selectPackageBasedMoveDestination(true);
        if (moveDestination == null)
            return null;

        final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
        if (targetFileName != null && !checkTargetFileName(targetFileName))
            return null;

        PsiDirectory targetDirectory = moveDestination.getTargetIfExists(sourceDirectory);

        List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles, targetFileName,
                targetDirectory);
        if (!filesExistingInTargetDir.isEmpty()) {
            if (!CollectionsKt.intersect(sourceFiles, filesExistingInTargetDir).isEmpty()) {
                setErrorText("Can't move to the original file(s)");
                return null;
            }

            if (filesExistingInTargetDir.size() > 1) {
                String filePathsToReport = StringUtil.join(filesExistingInTargetDir,
                        new Function<PsiFile, String>() {
                            @Override
                            public String fun(PsiFile file) {
                                return file.getVirtualFile().getPath();
                            }
                        }, "\n");
                Messages.showErrorDialog(myProject,
                        "Cannot perform refactoring since the following files already exist:\n\n"
                                + filePathsToReport,
                        RefactoringBundle.message("move.title"));
                return null;
            }

            String question = String.format(
                    "File '%s' already exists. Do you want to move selected declarations to this file?",
                    filesExistingInTargetDir.get(0).getVirtualFile().getPath());
            int ret = Messages.showYesNoDialog(myProject, question, RefactoringBundle.message("move.title"),
                    Messages.getQuestionIcon());
            if (ret != Messages.YES)
                return null;
        }

        return new DeferredJetFileKotlinMoveTarget(myProject, new FqName(getTargetPackage()),
                new Function1<KtFile, KtFile>() {
                    @Override
                    public KtFile invoke(@NotNull KtFile originalFile) {
                        return JetRefactoringUtilKt.getOrCreateKotlinFile(
                                targetFileName != null ? targetFileName : originalFile.getName(),
                                moveDestination.getTargetDirectory(originalFile));
                    }
                });
    }

    final File targetFile = new File(getTargetFilePath());
    if (!checkTargetFileName(targetFile.getName()))
        return null;
    KtFile jetFile = (KtFile) JetRefactoringUtilKt.toPsiFile(targetFile, myProject);
    if (jetFile != null) {
        if (sourceFiles.size() == 1 && sourceFiles.contains(jetFile)) {
            setErrorText("Can't move to the original file");
            return null;
        }

        return new JetFileKotlinMoveTarget(jetFile);
    }

    File targetDir = targetFile.getParentFile();
    final PsiDirectory psiDirectory = JetRefactoringUtilKt.toPsiDirectory(targetDir, myProject);
    assert psiDirectory != null : "No directory found: " + targetDir.getPath();

    PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory);
    if (psiPackage == null) {
        setErrorText("Could not find package corresponding to " + targetDir.getPath());
        return null;
    }

    return new DeferredJetFileKotlinMoveTarget(myProject, new FqName(psiPackage.getQualifiedName()),
            new Function1<KtFile, KtFile>() {
                @Override
                public KtFile invoke(@NotNull KtFile originalFile) {
                    return JetRefactoringUtilKt.getOrCreateKotlinFile(targetFile.getName(), psiDirectory);
                }
            });
}

From source file:org.jetbrains.kotlin.idea.refactoring.move.moveTopLevelDeclarations.ui.MoveKotlinTopLevelDeclarationsDialog.java

License:Apache License

@Override
protected void doAction() {
    KotlinMoveTarget target = selectMoveTarget();
    if (target == null)
        return;/*from ww w  .  j  a  va 2  s  .c  o m*/

    saveRefactoringSettings();

    List<KtNamedDeclaration> elementsToMove = getSelectedElementsToMove();
    final List<KtFile> sourceFiles = getSourceFiles(elementsToMove);
    final PsiDirectory sourceDirectory = getSourceDirectory(sourceFiles);

    for (PsiElement element : elementsToMove) {
        String message = target.verify(element.getContainingFile());
        if (message != null) {
            CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), message, null,
                    myProject);
            return;
        }
    }

    try {
        boolean deleteSourceFile = false;

        if (isFullFileMove()) {
            if (isMoveToPackage()) {
                final MoveDestination moveDestination = selectPackageBasedMoveDestination(false);
                //noinspection ConstantConditions
                PsiDirectory targetDir = moveDestination.getTargetIfExists(sourceDirectory);
                final String targetFileName = sourceFiles.size() > 1 ? null : tfFileNameInPackage.getText();
                List<PsiFile> filesExistingInTargetDir = getFilesExistingInTargetDir(sourceFiles,
                        targetFileName, targetDir);
                if (filesExistingInTargetDir.isEmpty()) {
                    PsiDirectory targetDirectory = ApplicationUtilsKt
                            .runWriteAction(new Function0<PsiDirectory>() {
                                @Override
                                public PsiDirectory invoke() {
                                    return moveDestination.getTargetDirectory(sourceDirectory);
                                }
                            });

                    for (KtFile sourceFile : sourceFiles) {
                        MoveUtilsKt.setUpdatePackageDirective(sourceFile,
                                cbUpdatePackageDirective.isSelected());
                    }

                    invokeRefactoring(new MoveFilesOrDirectoriesProcessor(myProject,
                            sourceFiles.toArray(new PsiElement[sourceFiles.size()]), targetDirectory, true,
                            isSearchInComments(), isSearchInNonJavaFiles(), new MoveCallback() {
                                @Override
                                public void refactoringCompleted() {
                                    try {
                                        if (targetFileName != null) {
                                            CollectionsKt.single(sourceFiles).setName(targetFileName);
                                        }
                                    } finally {
                                        if (moveCallback != null) {
                                            moveCallback.refactoringCompleted();
                                        }
                                    }
                                }
                            }, EmptyRunnable.INSTANCE) {
                        @Override
                        protected String getCommandName() {
                            return targetFileName != null
                                    ? "Move " + CollectionsKt.single(sourceFiles).getName()
                                    : "Move";
                        }

                        @Override
                        protected void performRefactoring(@NotNull UsageInfo[] usages) {
                            if (targetFileName != null) {
                                KtFile sourceFile = CollectionsKt.single(sourceFiles);
                                //noinspection ConstantConditions
                                String temporaryName = UniqueNameGenerator.generateUniqueName("temp", "", ".kt",
                                        ArraysKt.map(sourceFile.getContainingDirectory().getFiles(),
                                                new Function1<PsiFile, String>() {
                                                    @Override
                                                    public String invoke(PsiFile file) {
                                                        return file.getName();
                                                    }
                                                }));
                                sourceFile.setName(temporaryName);
                            }

                            super.performRefactoring(usages);
                        }
                    });

                    return;
                }
            }

            int ret = Messages.showYesNoCancelDialog(myProject,
                    "You are about to move all declarations out of the source file(s). Do you want to delete empty files?",
                    RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
            if (ret == Messages.CANCEL)
                return;
            deleteSourceFile = ret == Messages.YES;
        }

        MoveKotlinTopLevelDeclarationsOptions options = new MoveKotlinTopLevelDeclarationsOptions(
                elementsToMove, target, isSearchInComments(), isSearchInNonJavaFiles(), true, deleteSourceFile,
                moveCallback);
        invokeRefactoring(
                new MoveKotlinTopLevelDeclarationsProcessor(myProject, options, Mover.Default.INSTANCE$));
    } catch (IncorrectOperationException e) {
        CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("error.title"), e.getMessage(), null,
                myProject);
    }
}

From source file:org.jetbrains.plugins.github.util.GithubNotifications.java

License:Apache License

@Messages.YesNoResult
public static int showYesNoDialog(final @Nullable Project project, final @NotNull String title,
        final @NotNull String message) {
    return Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon());
}

From source file:org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataService.java

License:Apache License

@Nullable
private ExternalProject importExternalProject(@NotNull final Project project,
        @NotNull final ProjectSystemId projectSystemId, @NotNull final File projectRootDir) {
    final Boolean result = UIUtil.invokeAndWaitIfNeeded(new Computable<Boolean>() {
        @Override// w w w.  jav  a2 s .c o  m
        public Boolean compute() {
            final Ref<Boolean> result = new Ref<Boolean>(false);
            if (project.isDisposed()) {
                return false;
            }

            final String linkedProjectPath = FileUtil.toCanonicalPath(projectRootDir.getPath());
            final ExternalProjectSettings projectSettings = ExternalSystemApiUtil
                    .getSettings(project, projectSystemId).getLinkedProjectSettings(linkedProjectPath);
            if (projectSettings == null) {
                LOG.warn("Unable to get project settings for project path: " + linkedProjectPath);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Available projects paths: " + ContainerUtil.map(
                            ExternalSystemApiUtil.getSettings(project, projectSystemId)
                                    .getLinkedProjectsSettings(),
                            new Function<ExternalProjectSettings, String>() {
                                @Override
                                public String fun(ExternalProjectSettings settings) {
                                    return settings.getExternalProjectPath();
                                }
                            }));
                }
                return false;
            }

            final File projectFile = new File(linkedProjectPath);
            final String projectName;
            if (projectFile.isFile()) {
                projectName = projectFile.getParentFile().getName();
            } else {
                projectName = projectFile.getName();
            }

            // ask a user for the project import if auto-import is disabled
            if (!projectSettings.isUseAutoImport()) {
                String message = String.format(
                        "Project '%s' require synchronization with %s configuration. \nImport the project?",
                        projectName, projectSystemId.getReadableName());
                int returnValue = Messages.showOkCancelDialog(message, "Import Project",
                        CommonBundle.getOkButtonText(), CommonBundle.getCancelButtonText(),
                        Messages.getQuestionIcon());
                if (returnValue != Messages.OK) {
                    return false;
                }
            }

            final String title = ExternalSystemBundle.message("progress.import.text", linkedProjectPath,
                    projectSystemId.getReadableName());
            new Task.Modal(project, title, false) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    if (project.isDisposed()) {
                        return;
                    }

                    ExternalSystemNotificationManager.getInstance(project).clearNotifications(null,
                            NotificationSource.PROJECT_SYNC, projectSystemId);
                    ExternalSystemResolveProjectTask task = new ExternalSystemResolveProjectTask(
                            projectSystemId, project, linkedProjectPath, false);
                    task.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
                    if (project.isDisposed()) {
                        return;
                    }

                    final Throwable error = task.getError();
                    if (error != null) {
                        ExternalSystemNotificationManager.getInstance(project)
                                .processExternalProjectRefreshError(error, projectName, projectSystemId);
                        return;
                    }
                    final DataNode<ProjectData> projectDataDataNode = task.getExternalProject();
                    if (projectDataDataNode == null) {
                        return;
                    }

                    final Collection<DataNode<ExternalProject>> nodes = ExternalSystemApiUtil
                            .findAll(projectDataDataNode, KEY);
                    if (nodes.size() != 1) {
                        throw new IllegalArgumentException(
                                String.format("Expected to get a single external project but got %d: %s",
                                        nodes.size(), nodes));
                    }

                    ProjectRootManagerEx.getInstanceEx(myProject).mergeRootsChangesDuring(new Runnable() {
                        @Override
                        public void run() {
                            myProjectDataManager.importData(KEY, nodes, project, true);
                        }
                    });

                    result.set(true);
                }
            }.queue();

            return result.get();
        }
    });

    return result ? getRootExternalProject(projectSystemId, projectRootDir) : null;
}