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

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

Introduction

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

Prototype

@YesNoResult
public static int showYesNoDialog(@NotNull Component parent, String message,
        @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Usage

From source file:com.intellij.refactoring.lang.ExtractIncludeFileBase.java

License:Apache License

private void replaceDuplicates(final String includePath, final List<IncludeDuplicate<T>> duplicates,
        final Editor editor, final Project project) {
    if (duplicates.size() > 0) {
        final String message = RefactoringBundle.message(
                "idea.has.found.fragments.that.can.be.replaced.with.include.directive",
                ApplicationNamesInfo.getInstance().getProductName());
        final int exitCode = Messages.showYesNoDialog(project, message, getRefactoringName(),
                Messages.getInformationIcon());
        if (exitCode == Messages.YES) {
            CommandProcessor.getInstance().executeCommand(project, new Runnable() {
                @Override/*w  ww  . j a  va 2  s.co m*/
                public void run() {
                    boolean replaceAll = false;
                    for (IncludeDuplicate<T> pair : duplicates) {
                        if (!replaceAll) {

                            highlightInEditor(project, pair, editor);

                            ReplacePromptDialog promptDialog = new ReplacePromptDialog(false,
                                    RefactoringBundle.message("replace.fragment"), project);
                            promptDialog.show();
                            final int promptResult = promptDialog.getExitCode();
                            if (promptResult == FindManager.PromptResult.SKIP)
                                continue;
                            if (promptResult == FindManager.PromptResult.CANCEL)
                                break;

                            if (promptResult == FindManager.PromptResult.OK) {
                                doReplaceRange(includePath, pair.getStart(), pair.getEnd());
                            } else if (promptResult == FindManager.PromptResult.ALL) {
                                doReplaceRange(includePath, pair.getStart(), pair.getEnd());
                                replaceAll = true;
                            } else {
                                LOG.error("Unknown return status");
                            }
                        } else {
                            doReplaceRange(includePath, pair.getStart(), pair.getEnd());
                        }
                    }
                }
            }, RefactoringBundle.message("remove.duplicates.command"), null);
        }
    }
}

From source file:com.intellij.refactoring.makeStatic.MakeParameterizedStaticDialog.java

License:Apache License

protected boolean validateData() {
    int ret = 0;/*www .  jav  a  2 s . co  m*/
    if (isMakeClassParameter()) {
        final PsiMethod methodWithParameter = checkParameterDoesNotExist();
        if (methodWithParameter != null) {
            String who = methodWithParameter == myMember ? RefactoringBundle.message("this.method")
                    : DescriptiveNameUtil.getDescriptiveName(methodWithParameter);
            String message = RefactoringBundle.message("0.already.has.parameter.named.1.use.this.name.anyway",
                    who, getClassParameterName());
            ret = Messages.showYesNoDialog(myProject, message, RefactoringBundle.message("warning.title"),
                    Messages.getWarningIcon());
            myClassParameterNameInputField.requestFocusInWindow();
        }
    }
    return ret == 0;
}

From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.java

License:Apache License

@Nullable
private MoveDestination selectDestination() {
    final String packageName = getTargetPackage().trim();
    if (packageName.length() > 0
            && !PsiNameHelper.getInstance(myManager.getProject()).isQualifiedName(packageName)) {
        Messages.showErrorDialog(myProject,
                RefactoringBundle.message("please.enter.a.valid.target.package.name"),
                RefactoringBundle.message("move.title"));
        return null;
    }/*from  w  w w  .  j a  va 2 s . c om*/
    RecentsManager.getInstance(myProject).registerRecentEntry(RECENTS_KEY, packageName);
    PackageWrapper targetPackage = new PackageWrapper(myManager, packageName);
    if (!targetPackage.exists()) {
        final int ret = Messages.showYesNoDialog(myProject,
                RefactoringBundle.message("package.does.not.exist", packageName),
                RefactoringBundle.message("move.title"), Messages.getQuestionIcon());
        if (ret != 0)
            return null;
    }

    return ((DestinationFolderComboBox) myDestinationFolderCB).selectDirectory(targetPackage,
            mySuggestToMoveToAnotherRoot);
}

From source file:com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesImpl.java

License:Apache License

private static boolean checkMovePackage(Project project, PsiJavaPackage aPackage) {
    final PsiDirectory[] directories = aPackage.getDirectories();
    final VirtualFile[] virtualFiles = aPackage.occursInPackagePrefixes();
    if (directories.length > 1 || virtualFiles.length > 0) {
        final StringBuffer message = new StringBuffer();
        RenameUtil.buildPackagePrefixChangedMessage(virtualFiles, message, aPackage.getQualifiedName());
        if (directories.length > 1) {
            DirectoryAsPackageRenameHandlerBase.buildMultipleDirectoriesInPackageMessage(message,
                    aPackage.getQualifiedName(), directories);
            message.append("\n\n");
            String report = RefactoringBundle.message(
                    "all.these.directories.will.be.moved.and.all.references.to.0.will.be.changed",
                    aPackage.getQualifiedName());
            message.append(report);/*from  www. j  a  v a 2  s  . co m*/
        }
        message.append("\n");
        message.append(RefactoringBundle.message("do.you.wish.to.continue"));
        int ret = Messages.showYesNoDialog(project, message.toString(),
                RefactoringBundle.message("warning.title"), Messages.getWarningIcon());
        if (ret != 0) {
            return false;
        }
    }
    return true;
}

From source file:com.intellij.refactoring.move.moveInstanceMethod.MoveInstanceMethodDialogBase.java

License:Apache License

protected boolean verifyTargetClass(PsiClass targetClass) {
    if (targetClass.isInterface()) {
        final Project project = getProject();
        if (ClassInheritorsSearch.search(targetClass, false).findFirst() == null) {
            final String message = RefactoringBundle.message(
                    "0.is.an.interface.that.has.no.implementing.classes",
                    DescriptiveNameUtil.getDescriptiveName(targetClass));

            Messages.showErrorDialog(project, message, myRefactoringName);
            return false;
        }/*from   w ww . j  a  v a  2 s.  co m*/

        final String message = RefactoringBundle.message(
                "0.is.an.interface.method.implementation.will.be.added.to.all.directly.implementing.classes",
                DescriptiveNameUtil.getDescriptiveName(targetClass));

        final int result = Messages.showYesNoDialog(project, message, myRefactoringName,
                Messages.getQuestionIcon());
        if (result != 0)
            return false;
    }

    return true;
}

From source file:com.intellij.refactoring.move.moveMembers.MoveMembersDialog.java

License:Apache License

@Nullable
private PsiClass findOrCreateTargetClass(final PsiManager manager, final String fqName)
        throws IncorrectOperationException {
    final String className;
    final String packageName;
    int dotIndex = fqName.lastIndexOf('.');
    if (dotIndex >= 0) {
        packageName = fqName.substring(0, dotIndex);
        className = (dotIndex + 1 < fqName.length()) ? fqName.substring(dotIndex + 1) : "";
    } else {/*  w w  w  .ja  v  a2 s  .c o m*/
        packageName = "";
        className = fqName;
    }

    PsiClass aClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(fqName,
            GlobalSearchScope.projectScope(myProject));
    if (aClass != null)
        return aClass;

    final PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(myProject, packageName,
            mySourceClass.getContainingFile().getContainingDirectory(), true);

    if (directory == null) {
        return null;
    }

    int answer = Messages.showYesNoDialog(myProject,
            RefactoringBundle.message("class.0.does.not.exist", fqName), MoveMembersImpl.REFACTORING_NAME,
            Messages.getQuestionIcon());
    if (answer != 0)
        return null;
    final Ref<IncorrectOperationException> eRef = new Ref<IncorrectOperationException>();
    final PsiClass newClass = ApplicationManager.getApplication().runWriteAction(new Computable<PsiClass>() {
        public PsiClass compute() {
            try {
                return JavaDirectoryService.getInstance().createClass(directory, className);
            } catch (IncorrectOperationException e) {
                eRef.set(e);
                return null;
            }
        }
    });
    if (!eRef.isNull())
        throw eRef.get();
    return newClass;
}

From source file:com.intellij.refactoring.rename.PsiElementRenameHandler.java

License:Apache License

public static void invoke(PsiElement element, Project project, PsiElement nameSuggestionContext,
        Editor editor) {/*  w  w  w.j  a  v  a2 s  . c om*/
    if (element != null && !canRename(project, editor, element)) {
        return;
    }

    if (nameSuggestionContext != null && !PsiManager.getInstance(project).isInProject(nameSuggestionContext)) {
        final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?";
        if (ApplicationManager.getApplication().isUnitTestMode())
            throw new CommonRefactoringUtil.RefactoringErrorHintException(message);
        if (Messages.showYesNoDialog(project, message, RefactoringBundle.getCannotRefactorMessage(null),
                Messages.getWarningIcon()) != Messages.YES) {
            return;
        }
    }

    FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename");

    rename(element, project, nameSuggestionContext, editor);
}

From source file:com.intellij.refactoring.rename.RenameJavaVariableProcessor.java

License:Apache License

private static boolean askToRenameAccesors(PsiMethod getter, PsiMethod setter, String newName,
        final Project project) {
    if (ApplicationManager.getApplication().isUnitTestMode())
        return false;
    String text = RefactoringMessageUtil.getGetterSetterMessage(newName,
            RefactoringBundle.message("rename.title"), getter, setter);
    return Messages.showYesNoDialog(project, text, RefactoringBundle.message("rename.title"),
            Messages.getQuestionIcon()) != 0;
}

From source file:com.intellij.refactoring.replaceConstructorWithFactory.ReplaceConstructorWithFactoryHandler.java

License:Apache License

private void invoke(PsiClass aClass, Editor editor) {
    String qualifiedName = aClass.getQualifiedName();
    if (qualifiedName == null) {
        showJspOrLocalClassMessage(editor);
        return;//  ww  w  .  j  av  a  2  s . c om
    }
    if (!checkAbstractClassOrInterfaceMessage(aClass, editor))
        return;
    final PsiMethod[] constructors = aClass.getConstructors();
    if (constructors.length > 0) {
        String message = RefactoringBundle.message("class.does.not.have.implicit.default.constructor",
                aClass.getQualifiedName());
        CommonRefactoringUtil.showErrorHint(myProject, editor, message, REFACTORING_NAME,
                HelpID.REPLACE_CONSTRUCTOR_WITH_FACTORY);
        return;
    }
    final int answer = Messages.showYesNoDialog(myProject,
            RefactoringBundle.message("would.you.like.to.replace.default.constructor.of.0.with.factory.method",
                    aClass.getQualifiedName()),
            REFACTORING_NAME, Messages.getQuestionIcon());
    if (answer != 0)
        return;
    if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, aClass))
        return;
    new ReplaceConstructorWithFactoryDialog(myProject, null, aClass).show();
}

From source file:com.intellij.refactoring.safeDelete.JavaSafeDeleteProcessor.java

License:Apache License

@Nullable
@Override/*from  w w w.j a v  a  2 s .  com*/
public Collection<? extends PsiElement> getElementsToSearch(PsiElement element, @Nullable Module module,
        Collection<PsiElement> allElementsToDelete) {
    Project project = element.getProject();
    if (element instanceof PsiPackage && module != null) {
        final PsiDirectory[] directories = ((PsiPackage) element).getDirectories(module.getModuleScope());
        if (directories.length == 0)
            return null;
        return Arrays.asList(directories);
    } else if (element instanceof PsiMethod) {
        final PsiMethod[] methods = SuperMethodWarningUtil.checkSuperMethods((PsiMethod) element,
                RefactoringBundle.message("to.delete.with.usage.search"), allElementsToDelete);
        if (methods.length == 0)
            return null;
        final ArrayList<PsiMethod> psiMethods = new ArrayList<PsiMethod>(Arrays.asList(methods));
        psiMethods.add((PsiMethod) element);
        return psiMethods;
    } else if (element instanceof PsiParameter
            && ((PsiParameter) element).getDeclarationScope() instanceof PsiMethod) {
        PsiMethod method = (PsiMethod) ((PsiParameter) element).getDeclarationScope();
        final Set<PsiParameter> parametersToDelete = new HashSet<PsiParameter>();
        parametersToDelete.add((PsiParameter) element);
        final int parameterIndex = method.getParameterList().getParameterIndex((PsiParameter) element);
        final List<PsiMethod> superMethods = new ArrayList<PsiMethod>(
                Arrays.asList(method.findDeepestSuperMethods()));
        if (superMethods.isEmpty()) {
            superMethods.add(method);
        }
        for (PsiMethod superMethod : superMethods) {
            parametersToDelete.add(superMethod.getParameterList().getParameters()[parameterIndex]);
            OverridingMethodsSearch.search(superMethod).forEach(new Processor<PsiMethod>() {
                public boolean process(PsiMethod overrider) {
                    parametersToDelete.add(overrider.getParameterList().getParameters()[parameterIndex]);
                    return true;
                }
            });
        }

        if (parametersToDelete.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode()) {
            String message = RefactoringBundle.message(
                    "0.is.a.part.of.method.hierarchy.do.you.want.to.delete.multiple.parameters",
                    UsageViewUtil.getLongName(method));
            if (Messages.showYesNoDialog(project, message, SafeDeleteHandler.REFACTORING_NAME,
                    Messages.getQuestionIcon()) != DialogWrapper.OK_EXIT_CODE)
                return null;
        }
        return parametersToDelete;
    } else {
        return Collections.singletonList(element);
    }
}