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

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

Introduction

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

Prototype

int YES

To view the source code for com.intellij.openapi.ui Messages YES.

Click Source Link

Usage

From source file:com.intellij.history.integration.ui.views.HistoryDialog.java

License:Apache License

private boolean askForProceeding(Reverter r) throws IOException {
    List<String> questions = r.askUserForProceeding();
    if (questions.isEmpty())
        return true;

    return Messages.showYesNoDialog(myProject,
            message("message.do.you.want.to.proceed", formatQuestions(questions)),
            CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.YES;
}

From source file:com.intellij.ide.plugins.ActionInstallPlugin.java

License:Apache License

private static boolean suggestToEnableInstalledPlugins(final InstalledPluginsTableModel pluginsModel,
        final Set<IdeaPluginDescriptor> disabled, final Set<IdeaPluginDescriptor> disabledDependants,
        final ArrayList<PluginNode> list) {
    if (!disabled.isEmpty() || !disabledDependants.isEmpty()) {
        String message = "";
        if (disabled.size() == 1) {
            message += "Updated plugin '" + disabled.iterator().next().getName() + "' is disabled.";
        } else if (!disabled.isEmpty()) {
            message += "Updated plugins "
                    + StringUtil.join(disabled, new Function<IdeaPluginDescriptor, String>() {
                        @Override
                        public String fun(IdeaPluginDescriptor pluginDescriptor) {
                            return pluginDescriptor.getName();
                        }//  w w  w  . jav  a2 s.  c om
                    }, ", ") + " are disabled.";
        }

        if (!disabledDependants.isEmpty()) {
            message += "<br>";
            message += "Updated plugin" + (list.size() > 1 ? "s depend " : " depends ") + "on disabled";
            if (disabledDependants.size() == 1) {
                message += " plugin '" + disabledDependants.iterator().next().getName() + "'.";
            } else {
                message += " plugins "
                        + StringUtil.join(disabledDependants, new Function<IdeaPluginDescriptor, String>() {
                            @Override
                            public String fun(IdeaPluginDescriptor pluginDescriptor) {
                                return pluginDescriptor.getName();
                            }
                        }, ", ") + ".";
            }
        }
        message += " Disabled plugins and plugins which depends on disabled plugins won't be activated after restart.";

        int result;
        if (!disabled.isEmpty() && !disabledDependants.isEmpty()) {
            result = Messages.showYesNoCancelDialog(XmlStringUtil.wrapInHtml(message),
                    CommonBundle.getWarningTitle(), "Enable all",
                    "Enable updated plugin" + (disabled.size() > 1 ? "s" : ""),
                    CommonBundle.getCancelButtonText(), Messages.getQuestionIcon());
            if (result == Messages.CANCEL)
                return false;
        } else {
            message += "<br>Would you like to enable ";
            if (!disabled.isEmpty()) {
                message += "updated plugin" + (disabled.size() > 1 ? "s" : "");
            } else {
                //noinspection SpellCheckingInspection
                message += "plugin dependenc" + (disabledDependants.size() > 1 ? "ies" : "y");
            }
            message += "?</body></html>";
            result = Messages.showYesNoDialog(message, CommonBundle.getWarningTitle(),
                    Messages.getQuestionIcon());
            if (result == Messages.NO)
                return false;
        }

        if (result == Messages.YES) {
            disabled.addAll(disabledDependants);
            pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true);
        } else if (result == Messages.NO && !disabled.isEmpty()) {
            pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true);
        }
        return true;
    }
    return false;
}

From source file:com.intellij.ide.plugins.ActionInstallPlugin.java

License:Apache License

private boolean userConfirm(IdeaPluginDescriptor[] selection) {
    String message;// w  w  w  .  j ava  2 s  .  c  o m
    if (selection.length == 1) {
        if (selection[0] instanceof IdeaPluginDescriptorImpl) {
            message = IdeBundle.message("prompt.update.plugin", selection[0].getName());
        } else {
            message = IdeBundle.message("prompt.download.and.install.plugin", selection[0].getName());
        }
    } else {
        message = IdeBundle.message("prompt.install.several.plugins", selection.length);
    }

    return Messages.showYesNoDialog(host.getMainPanel(), message,
            IdeBundle.message("action.download.and.install.plugin"),
            Messages.getQuestionIcon()) == Messages.YES;
}

From source file:com.intellij.ide.plugins.PluginInstaller.java

License:Apache License

@Nullable("Will return null is download failed")
private static Set<PluginNode> prepareToInstall(@NotNull PluginNode toInstall,
        @NotNull List<PluginId> toInstallAll, @NotNull List<IdeaPluginDescriptor> allPlugins)
        throws IOException {
    val depends = new ArrayListSet<PluginNode>();
    val unknownDepends = new ArrayListSet<String>();
    collectDepends(toInstall, toInstallAll, depends, allPlugins, unknownDepends);

    if (!unknownDepends.isEmpty()) {
        val ref = new boolean[1];
        UIUtil.invokeAndWaitIfNeeded(new Runnable() {
            @Override//from  w ww .java2  s. com
            public void run() {
                String mergedIds = StringUtil.join(unknownDepends, ", ");

                String title = IdeBundle.message("plugin.manager.unknown.dependencies.detected.title");
                String message = IdeBundle.message("plugin.manager.unknown.dependencies.detected.message",
                        unknownDepends.size(), mergedIds);
                ref[0] = Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES;
            }
        });

        if (!ref[0]) {
            return null;
        }
    }
    val toDownloadList = new ArrayListSet<PluginNode>();
    if (!depends.isEmpty()) {

        UIUtil.invokeAndWaitIfNeeded(new Runnable() {
            @Override
            public void run() {
                String mergedIds = StringUtil.join(depends, new Function<PluginNode, String>() {
                    @Override
                    public String fun(PluginNode pluginNode) {
                        return pluginNode.getName();
                    }
                }, ", ");

                String title = IdeBundle.message("plugin.manager.dependencies.detected.title");
                String message = IdeBundle.message("plugin.manager.dependencies.detected.message",
                        depends.size(), mergedIds);
                if (Messages.showYesNoDialog(message, title, Messages.getWarningIcon()) == Messages.YES) {
                    toDownloadList.addAll(depends);
                }
            }
        });
    }

    toDownloadList.add(toInstall);

    for (PluginNode pluginNode : toDownloadList) {
        PluginDownloader downloader = null;
        final String repositoryName = pluginNode.getRepositoryName();
        if (repositoryName != null) {
            try {
                final List<PluginDownloader> downloaders = new ArrayList<PluginDownloader>();
                if (!UpdateChecker.checkPluginsHost(repositoryName, downloaders)) {
                    return null;
                }
                for (PluginDownloader pluginDownloader : downloaders) {
                    if (Comparing.strEqual(pluginDownloader.getPluginId(),
                            pluginNode.getPluginId().getIdString())) {
                        downloader = pluginDownloader;
                        break;
                    }
                }
                if (downloader == null)
                    return null;
            } catch (Exception e) {
                return null;
            }
        } else {
            downloader = PluginDownloader.createDownloader(pluginNode);
        }
        if (downloader.prepareToInstall(ProgressManager.getInstance().getProgressIndicator())) {
            downloader.install(true);
            pluginNode.setStatus(PluginNode.STATUS_DOWNLOADED);
        } else {
            return null;
        }
    }
    return toDownloadList;
}

From source file:com.intellij.ide.plugins.PluginManagerConfigurable.java

License:Apache License

@Override
public void apply() throws ConfigurationException {
    final String applyMessage = myPluginManagerMain.apply();
    if (applyMessage != null) {
        throw new ConfigurationException(applyMessage);
    }//  w ww  . j a v a2  s . co  m

    if (myPluginManagerMain.isRequireShutdown()) {
        final ApplicationEx app = ApplicationManagerEx.getApplicationEx();

        int response = app.isRestartCapable() ? showRestartIDEADialog() : showShutDownIDEADialog();
        if (response == Messages.YES) {
            app.restart(true);
        } else {
            myPluginManagerMain.ignoreChanges();
        }
    }
}

From source file:com.intellij.ide.plugins.PluginManagerConfigurable.java

License:Apache License

public static void shutdownOrRestartApp(String title) {
    final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
    int response = app.isRestartCapable() ? showRestartIDEADialog(title) : showShutDownIDEADialog(title);
    if (response == Messages.YES)
        app.restart(true);/*from   ww  w  . j  a  v a  2  s  . co m*/
}

From source file:com.intellij.ide.plugins.UninstallPluginAction.java

License:Apache License

public static void uninstall(PluginManagerMain host, IdeaPluginDescriptor... selection) {
    String message;//from  w w w  .  ja va  2  s.c om

    if (selection.length == 1) {
        message = IdeBundle.message("prompt.uninstall.plugin", selection[0].getName());
    } else {
        message = IdeBundle.message("prompt.uninstall.several.plugins", selection.length);
    }
    if (Messages.showYesNoDialog(host.getMainPanel(), message, IdeBundle.message("title.plugin.uninstall"),
            Messages.getQuestionIcon()) != Messages.YES)
        return;

    for (IdeaPluginDescriptor descriptor : selection) {
        IdeaPluginDescriptorImpl pluginDescriptor = (IdeaPluginDescriptorImpl) descriptor;

        boolean actualDelete = true;

        //  Get the list of plugins which depend on this one. If this list is
        //  not empty - issue warning instead of simple prompt.
        ArrayList<IdeaPluginDescriptorImpl> dependant = host.getDependentList(pluginDescriptor);
        if (dependant.size() > 0) {
            message = IdeBundle.message("several.plugins.depend.on.0.continue.to.remove",
                    pluginDescriptor.getName());
            actualDelete = (Messages.showYesNoDialog(host.getMainPanel(), message,
                    IdeBundle.message("title.plugin.uninstall"), Messages.getQuestionIcon()) == Messages.YES);
        }

        if (actualDelete) {
            uninstallPlugin(pluginDescriptor, host);
        }
    }
}

From source file:com.intellij.ide.util.DeleteHandler.java

License:Apache License

public static void deletePsiElement(final PsiElement[] elementsToDelete, final Project project,
        boolean needConfirmation) {
    if (elementsToDelete == null || elementsToDelete.length == 0)
        return;//  ww w. j  a v  a  2s  .co m

    final PsiElement[] elements = PsiTreeUtil.filterAncestors(elementsToDelete);

    boolean safeDeleteApplicable = true;
    for (int i = 0; i < elements.length && safeDeleteApplicable; i++) {
        PsiElement element = elements[i];
        safeDeleteApplicable = SafeDeleteProcessor.validElement(element);
    }

    final boolean dumb = DumbService.getInstance(project).isDumb();
    if (safeDeleteApplicable && !dumb) {
        final Ref<Boolean> exit = Ref.create(false);
        final SafeDeleteDialog dialog = new SafeDeleteDialog(project, elements,
                new SafeDeleteDialog.Callback() {
                    @Override
                    public void run(final SafeDeleteDialog dialog) {
                        if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project,
                                Arrays.asList(elements), true))
                            return;
                        SafeDeleteProcessor.createInstance(project, new Runnable() {
                            @Override
                            public void run() {
                                exit.set(true);
                                dialog.close(DialogWrapper.OK_EXIT_CODE);
                            }
                        }, elements, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true)
                                .run();
                    }
                }) {
            @Override
            protected boolean isDelete() {
                return true;
            }
        };
        if (needConfirmation) {
            dialog.show();
            if (!dialog.isOK() || exit.get())
                return;
        }
    } else {
        @SuppressWarnings({ "UnresolvedPropertyKey" })
        String warningMessage = DeleteUtil.generateWarningMessage(IdeBundle.message("prompt.delete.elements"),
                elements);

        boolean anyDirectories = false;
        String directoryName = null;
        for (PsiElement psiElement : elementsToDelete) {
            if (psiElement instanceof PsiDirectory && !PsiUtilBase.isSymLink((PsiDirectory) psiElement)) {
                anyDirectories = true;
                directoryName = ((PsiDirectory) psiElement).getName();
                break;
            }
        }
        if (anyDirectories) {
            if (elements.length == 1) {
                warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories",
                        directoryName);
            } else {
                warningMessage += IdeBundle
                        .message("warning.delete.all.files.and.subdirectories.in.the.selected.directory");
            }
        }

        if (safeDeleteApplicable && dumb) {
            warningMessage += "\n\nWarning:\n  Safe delete is not available while "
                    + ApplicationNamesInfo.getInstance().getFullProductName()
                    + " updates indices,\n  no usages will be checked.";
        }

        if (needConfirmation) {
            int result = Messages.showOkCancelDialog(project, warningMessage, IdeBundle.message("title.delete"),
                    ApplicationBundle.message("button.delete"), CommonBundle.getCancelButtonText(),
                    Messages.getQuestionIcon());
            if (result != Messages.OK)
                return;
        }
    }

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        @Override
        public void run() {
            if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(elements),
                    false)) {
                return;
            }

            // deleted from project view or something like that.
            if (CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext()) == null) {
                CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
            }

            for (final PsiElement elementToDelete : elements) {
                if (!elementToDelete.isValid())
                    continue; //was already deleted
                if (elementToDelete instanceof PsiDirectory) {
                    VirtualFile virtualFile = ((PsiDirectory) elementToDelete).getVirtualFile();
                    if (virtualFile.isInLocalFileSystem() && !virtualFile.is(VFileProperty.SYMLINK)) {
                        ArrayList<VirtualFile> readOnlyFiles = new ArrayList<VirtualFile>();
                        CommonRefactoringUtil.collectReadOnlyFiles(virtualFile, readOnlyFiles);

                        if (!readOnlyFiles.isEmpty()) {
                            String message = IdeBundle.message("prompt.directory.contains.read.only.files",
                                    virtualFile.getPresentableUrl());
                            int _result = Messages.showYesNoDialog(project, message,
                                    IdeBundle.message("title.delete"), Messages.getQuestionIcon());
                            if (_result != Messages.YES)
                                continue;

                            boolean success = true;
                            for (VirtualFile file : readOnlyFiles) {
                                success = clearReadOnlyFlag(file, project);
                                if (!success)
                                    break;
                            }
                            if (!success)
                                continue;
                        }
                    }
                } else if (!elementToDelete.isWritable() && !(elementToDelete instanceof PsiFileSystemItem
                        && PsiUtilBase.isSymLink((PsiFileSystemItem) elementToDelete))) {
                    final PsiFile file = elementToDelete.getContainingFile();
                    if (file != null) {
                        final VirtualFile virtualFile = file.getVirtualFile();
                        if (virtualFile.isInLocalFileSystem()) {
                            int _result = MessagesEx.fileIsReadOnly(project, virtualFile)
                                    .setTitle(IdeBundle.message("title.delete"))
                                    .appendMessage(IdeBundle.message("prompt.delete.it.anyway")).askYesNo();
                            if (_result != Messages.YES)
                                continue;

                            boolean success = clearReadOnlyFlag(virtualFile, project);
                            if (!success)
                                continue;
                        }
                    }
                }

                try {
                    elementToDelete.checkDelete();
                } catch (IncorrectOperationException ex) {
                    Messages.showMessageDialog(project, ex.getMessage(), CommonBundle.getErrorTitle(),
                            Messages.getErrorIcon());
                    continue;
                }

                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            elementToDelete.delete();
                        } catch (final IncorrectOperationException ex) {
                            ApplicationManager.getApplication().invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    Messages.showMessageDialog(project, ex.getMessage(),
                                            CommonBundle.getErrorTitle(), Messages.getErrorIcon());
                                }
                            });
                        }
                    }
                });
            }
        }
    }, RefactoringBundle.message("safe.delete.command",
            RefactoringUIUtil.calculatePsiElementDescriptionList(elements)), null);
}

From source file:com.intellij.ide.util.projectWizard.NamePathComponent.java

License:Apache License

public boolean validateNameAndPath(WizardContext context) throws ConfigurationException {
    final String name = getNameValue();
    if (name.length() == 0) {
        final ApplicationInfo info = ApplicationManager.getApplication().getComponent(ApplicationInfo.class);
        throw new ConfigurationException(IdeBundle.message("prompt.new.project.file.name",
                info.getVersionName(), context.getPresentationName()));
    }/* w w  w.j  av  a 2 s.  c o m*/

    final String projectFileDirectory = getPath();
    if (projectFileDirectory.length() == 0) {
        throw new ConfigurationException(
                IdeBundle.message("prompt.enter.project.file.location", context.getPresentationName()));
    }

    final boolean shouldPromptCreation = isPathChangedByUser();
    if (!ProjectWizardUtil.createDirectoryIfNotExists(
            IdeBundle.message("directory.project.file.directory", context.getPresentationName()),
            projectFileDirectory, shouldPromptCreation)) {
        return false;
    }

    final File file = new File(projectFileDirectory);
    if (file.exists() && !file.canWrite()) {
        throw new ConfigurationException(
                String.format("Directory '%s' is not writable!\nPlease choose another project location.",
                        projectFileDirectory));
    }

    boolean shouldContinue = true;
    final File projectDir = new File(getPath(), Project.DIRECTORY_STORE_FOLDER);
    if (projectDir.exists()) {
        int answer = Messages.showYesNoDialog(
                IdeBundle.message("prompt.overwrite.project.folder", projectDir.getAbsolutePath(),
                        context.getPresentationName()),
                IdeBundle.message("title.file.already.exists"), Messages.getQuestionIcon());
        shouldContinue = (answer == Messages.YES);
    }

    return shouldContinue;
}

From source file:com.intellij.ide.util.projectWizard.SdkSettingsStep.java

License:Apache License

@Override
public boolean validate() throws ConfigurationException {
    if (mySdkComboBox.getSelectedSdk() == null) {
        if (Messages.showDialog(getNoSdkMessage(), IdeBundle.message("title.no.jdk.specified"),
                new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1,
                Messages.getWarningIcon()) != Messages.YES) {
            return false;
        }/*from   ww  w  .  ja v  a2  s  .c  om*/
    }
    try {
        myModel.apply(null, true);
    } catch (ConfigurationException e) {
        //IDEA-98382 We should allow Next step if user has wrong SDK
        if (Messages.showDialog(e.getMessage() + "/nDo you want to proceed?", e.getTitle(),
                new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1,
                Messages.getWarningIcon()) != Messages.YES) {
            return false;
        }
    }
    return true;
}