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.mbeddr.pluginmanager.com.intellij.ide.plugins.UninstallPluginAction.java

License:Apache License

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

    if (selection.length == 1) {
        message = IdeBundle.message("prompt.uninstall.plugin", selection[0].getName());
    } else {
        message = IdeBundle.message("prompt.uninstall.several.plugins", selection.length);
    }

    if (!confirmed && 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.
        List<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.microsoft.intellij.ui.azureroles.AzureRolePanel.java

License:Open Source License

private void handleSmallVMCacheConf() {
    try {/*w  ww  . j a v a 2s . c o m*/
        if (message("txtExtraSmallVM").equals((String) comboVMSize.getSelectedItem())
                && windowsAzureRole.getCacheMemoryPercent() > 0) {
            // If extra small VM and cache is enabled
            int choice = Messages.showYesNoDialog((Project) null, message("cacheConfMsg"),
                    message("cacheConfTitle"), Messages.getWarningIcon());
            if (choice == Messages.YES) {
                // Yes - Disable cache
                windowsAzureRole.setCacheMemoryPercent(0);
            } else {
                // No or if dialog is closed directly then reset VM size back to original
                comboVMSize.setSelectedItem(arrVMSize[getVMSizeIndex()]);
            }
        }
    } catch (WindowsAzureInvalidProjectOperationException e) {
        PluginUtil.displayErrorDialogAndLog(message("cachErrTtl"), message("cachGetErMsg"), e);
    }
}

From source file:com.microsoft.intellij.ui.RolesPanel.java

License:Open Source License

private ActionListener createBtnRemoveListener() {
    return new ActionListener() {
        @Override//from w  ww  . j  a v a 2s . co  m
        public void actionPerformed(ActionEvent e) {
            try {
                int selIndex = tblRoles.getSelectedRow();
                if (selIndex > -1) {
                    int choice = Messages.showYesNoDialog(myModule.getProject(), message("rolsDelMsg"),
                            message("rolsDelTitle"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        /*
                         * If the role selected for deletion is the last role,
                        * then do not delete it and give error message.
                        */
                        if (listRoles.size() == 1) {
                            PluginUtil.displayErrorDialog(message("rolsDelTitle"), message("lastRolDelMsg"));
                        } else {
                            WindowsAzureRole windowsAzureRole = listRoles.get(selIndex);
                            windowsAzureRole.delete();
                            waProjManager.save();
                            ((RolesTableModel) tblRoles.getModel()).fireTableDataChanged();
                        }
                    }
                }
            } catch (WindowsAzureInvalidProjectOperationException ex) {
                PluginUtil.displayErrorDialogAndLog(message("rolsErr"),
                        message("adRolErrMsgBox1") + message("adRolErrMsgBox2"), ex);
            }
        }
    };
}

From source file:com.microsoftopentechnologies.intellij.ui.RolesPanel.java

License:Apache License

private ActionListener createBtnRemoveListener() {
    return new ActionListener() {
        @Override//from  w  w  w . j av  a2  s . c  om
        public void actionPerformed(ActionEvent e) {
            try {
                int selIndex = tblRoles.getSelectedRow();
                if (selIndex > -1) {
                    int choice = Messages.showYesNoDialog(myModule.getProject(), message("rolsDelMsg"),
                            message("rolsDelTitle"), Messages.getQuestionIcon());
                    if (choice == Messages.YES) {
                        /*
                        * If the role selected for deletion is the last role,
                        * then do not delete it and give error message.
                        */
                        if (listRoles.size() == 1) {
                            PluginUtil.displayErrorDialog(message("rolsDelTitle"), message("lastRolDelMsg"));
                        } else {
                            WindowsAzureRole windowsAzureRole = listRoles.get(selIndex);
                            windowsAzureRole.delete();
                            waProjManager.save();
                            ((RolesTableModel) tblRoles.getModel()).fireTableDataChanged();
                        }
                    }
                }
            } catch (WindowsAzureInvalidProjectOperationException ex) {
                PluginUtil.displayErrorDialogAndLog(message("rolsErr"),
                        message("adRolErrMsgBox1") + message("adRolErrMsgBox2"), ex);
            }
        }
    };
}

From source file:com.NetworkDeploy.ui.SshUserInfo.java

License:Open Source License

@Override
public boolean promptYesNo(final String s) {
    result.remove(Fields.Answer);// www . ja  v a 2s.co m
    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
        @Override
        public void run() {
            result.put(Fields.Answer, Messages.showYesNoDialog(project, s, "", null));
        }
    }, ModalityState.defaultModalityState());
    Integer answer = (Integer) result.get(Fields.Answer);
    return answer == Messages.YES;
}

From source file:com.perl5.lang.perl.idea.configuration.module.PerlModuleSdkConfigurable.java

License:Apache License

private void init() {
    myJdkPanel = new JPanel(new GridBagLayout());
    myCbModuleJdk = new JdkComboBox(myJdksModel, new Condition<SdkTypeId>() {
        @Override/*from  ww w.j a  v a  2s.com*/
        public boolean value(SdkTypeId sdkTypeId) {
            return sdkTypeId == PerlSdkType.getInstance();
        }
    });
    myCbModuleJdk.insertItemAt(new JdkComboBox.ProjectJdkComboBoxItem(), 0);
    myCbModuleJdk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (myFreeze) {
                return;
            }

            final Sdk newJdk = myCbModuleJdk.getSelectedJdk();
            setSdk(newJdk);

            clearCaches();
        }
    });
    myJdkPanel.add(new JLabel(ProjectBundle.message("module.libraries.target.jdk.module.radio")),
            new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                    new Insets(12, 6, 12, 0), 0, 0));
    myJdkPanel.add(myCbModuleJdk, new GridBagConstraints(1, 0, 1, 1, 0, 1.0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(6, 6, 12, 0), 0, 0));
    final Project project = getRootModel().getModule().getProject();
    final JButton setUpButton = new JButton(ApplicationBundle.message("button.new"));
    myCbModuleJdk.setSetupButton(setUpButton, project, myJdksModel, new JdkComboBox.ProjectJdkComboBoxItem(),
            new Condition<Sdk>() {
                @Override
                public boolean value(Sdk jdk) {
                    final Sdk projectJdk = myJdksModel.getProjectSdk();
                    if (projectJdk == null) {
                        final int res = Messages.showYesNoDialog(myJdkPanel,
                                ProjectBundle.message("project.roots.no.jdk.on.project.message"),
                                ProjectBundle.message("project.roots.no.jdk.on.project.title"),
                                Messages.getInformationIcon());
                        if (res == Messages.YES) {
                            myJdksModel.setProjectSdk(jdk);
                            return true;
                        }
                    }
                    return false;
                }
            }, true);
    myJdkPanel.add(setUpButton, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(0, 4, 7, 0), 0, 0));
    final JButton editButton = new JButton(ApplicationBundle.message("button.edit"));
    myCbModuleJdk.setEditButton(editButton, getRootModel().getModule().getProject(), new Computable<Sdk>() {
        @Override
        @Nullable
        public Sdk compute() {
            return getRootModel().getSdk();
        }
    });
    myJdkPanel.add(editButton, new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 1.0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 4, 7, 0), 0, 0));
}

From source file:com.perl5.lang.perl.idea.configuration.paths.PerlModuleSdkConfigurable.java

License:Apache License

private void init() {
    myJdkPanel = new JPanel(new GridBagLayout());
    myCbModuleJdk = new JdkComboBox(myJdksModel, new Condition<SdkTypeId>() {
        @Override//from  www.j a  va  2s . c  om
        public boolean value(SdkTypeId sdkTypeId) {
            return sdkTypeId == PerlSdkType.getInstance();
        }
    });
    myCbModuleJdk.insertItemAt(new JdkComboBox.ProjectJdkComboBoxItem(), 0);
    myCbModuleJdk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (myFreeze)
                return;

            final Sdk newJdk = myCbModuleJdk.getSelectedJdk();
            setSdk(newJdk);

            clearCaches();
        }
    });
    myJdkPanel.add(new JLabel(ProjectBundle.message("module.libraries.target.jdk.module.radio")),
            new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                    new Insets(12, 6, 12, 0), 0, 0));
    myJdkPanel.add(myCbModuleJdk, new GridBagConstraints(1, 0, 1, 1, 0, 1.0, GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE, new Insets(6, 6, 12, 0), 0, 0));
    final Project project = getRootModel().getModule().getProject();
    final JButton setUpButton = new JButton(ApplicationBundle.message("button.new"));
    myCbModuleJdk.setSetupButton(setUpButton, project, myJdksModel, new JdkComboBox.ProjectJdkComboBoxItem(),
            new Condition<Sdk>() {
                @Override
                public boolean value(Sdk jdk) {
                    final Sdk projectJdk = myJdksModel.getProjectSdk();
                    if (projectJdk == null) {
                        final int res = Messages.showYesNoDialog(myJdkPanel,
                                ProjectBundle.message("project.roots.no.jdk.on.project.message"),
                                ProjectBundle.message("project.roots.no.jdk.on.project.title"),
                                Messages.getInformationIcon());
                        if (res == Messages.YES) {
                            myJdksModel.setProjectSdk(jdk);
                            return true;
                        }
                    }
                    return false;
                }
            }, true);
    myJdkPanel.add(setUpButton, new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(0, 4, 7, 0), 0, 0));
    final JButton editButton = new JButton(ApplicationBundle.message("button.edit"));
    myCbModuleJdk.setEditButton(editButton, getRootModel().getModule().getProject(), new Computable<Sdk>() {
        @Override
        @Nullable
        public Sdk compute() {
            return getRootModel().getSdk();
        }
    });
    myJdkPanel.add(editButton, new GridBagConstraints(GridBagConstraints.RELATIVE, 0, 1, 1, 1.0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 4, 7, 0), 0, 0));
}

From source file:com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl.java

License:Apache License

@Override
public void projectOpened() {
    super.projectOpened();
    if (myProject.isDefault()) {
        return;//from   w  w w.ja  va  2 s .  c o m
    }
    StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() {
        @Override
        public void run() {
            /**
             * Set project to allow dynamic classpath for JUnit run. Still requires any junit run to specify dynamic classpath in
             * {@link com.twitter.intellij.pants.execution.PantsClasspathRunConfigurationExtension#updateJavaParameters}
             * IDEA's logic: {@link com.intellij.execution.configurations.CommandLineBuilder}
             */
            PropertiesComponent.getInstance(myProject).setValue("dynamic.classpath", true);

            if (PantsUtil.isSeedPantsProject(myProject)) {
                convertToPantsProject();
            }

            registerExternalBuilderListener();
            subscribeToRunConfigurationAddition();
            final AbstractExternalSystemSettings pantsSettings = ExternalSystemApiUtil.getSettings(myProject,
                    PantsConstants.SYSTEM_ID);
            final boolean resolverVersionMismatch = pantsSettings instanceof PantsSettings
                    && ((PantsSettings) pantsSettings).getResolverVersion() != PantsResolver.VERSION;
            if (resolverVersionMismatch && PantsUtil.isPantsProject(myProject)) {
                final int answer = Messages.showYesNoDialog(myProject,
                        PantsBundle.message("pants.project.generated.with.old.version", myProject.getName()),
                        PantsBundle.message("pants.name"), PantsIcons.Icon);
                if (answer == Messages.YES) {
                    PantsUtil.refreshAllProjects(myProject);
                }
            }
        }

        /**
         * To convert a seed Pants project to a full bloom pants project:
         * 1. Obtain the targets and project_path generated by `pants idea-plugin` from
         * workspace file `project.iws` via `PropertiesComponent` API.
         * 2. Generate a refresh spec based on the info above.
         * 3. Explicitly call {@link PantsUtil#refreshAllProjects}.
         */
        private void convertToPantsProject() {
            String serializedTargets = PropertiesComponent.getInstance(myProject).getValue("targets");
            String projectPath = PropertiesComponent.getInstance(myProject).getValue("project_path");
            if (serializedTargets == null || projectPath == null) {
                return;
            }

            /**
             * Generate the import spec for the next refresh.
             */
            final List<String> targetSpecs = PantsUtil.gson.fromJson(serializedTargets,
                    PantsUtil.TYPE_LIST_STRING);
            final PantsProjectSettings pantsProjectSettings = new PantsProjectSettings(targetSpecs, projectPath,
                    false, true);

            /**
             * Following procedures in {@link com.intellij.openapi.externalSystem.util.ExternalSystemUtil#refreshProjects}:
             * Make sure the setting is injected into the project for refresh.
             */
            ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil
                    .getManager(PantsConstants.SYSTEM_ID);
            if (manager == null) {
                return;
            }
            AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(myProject);
            settings.setLinkedProjectsSettings(Collections.singleton(pantsProjectSettings));
            PantsUtil.refreshAllProjects(myProject);

            prepareGuiComponents();
        }

        /**
         * Ensure GUI is set correctly because empty IntelliJ project (seed project in this case)
         * does not have these set by default.
         * 1. Make sure the project view is opened so view switch will follow.
         * 2. Pants tool window is initialized; otherwise no message can be shown when invoking `PantsCompile`.
         */
        private void prepareGuiComponents() {
            if (!ApplicationManager.getApplication().isUnitTestMode()) {
                if (ToolWindowManager.getInstance(myProject).getToolWindow("Project") != null) {
                    ToolWindowManager.getInstance(myProject).getToolWindow("Project").show(null);
                }
                ExternalSystemUtil.ensureToolWindowInitialized(myProject, PantsConstants.SYSTEM_ID);
            }
        }

        private void subscribeToRunConfigurationAddition() {
            RunManagerEx.getInstanceEx(myProject).addRunManagerListener(new RunManagerAdapter() {
                @Override
                public void runConfigurationAdded(@NotNull RunnerAndConfigurationSettings settings) {
                    super.runConfigurationAdded(settings);
                    if (!PantsUtil.isPantsProject(myProject) && !PantsUtil.isSeedPantsProject(myProject)) {
                        return;
                    }
                    if (!PantsSettings.getInstance(myProject).isUsePantsMakeBeforeRun()) {
                        return;
                    }
                    PantsMakeBeforeRun.replaceDefaultMakeWithPantsMake(myProject, settings);
                }
            });
        }
    });
}

From source file:de.fu_berlin.inf.dpp.intellij.ui.util.SafeDialogUtils.java

License:Open Source License

public static boolean showYesNoDialog(final String message, final String title) {

    final AtomicBoolean choice = new AtomicBoolean(false);

    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        @Override//from  www.java  2  s .  co  m
        public void run() {
            int returnValue = Messages.showYesNoDialog(saros.getProject(), message, title,
                    Messages.getQuestionIcon());
            if (returnValue == Messages.YES) {
                choice.set(true);
            }
        }
    });

    return choice.get();
}

From source file:net.groboclown.idea.p4ic.v2.ui.alerts.ClientNameMismatchHandler.java

License:Apache License

@Override
public void handleError(@NotNull final Date when) {
    LOG.warn("Cached client " + cachedClientName + " does not match p4 reported client " + p4ClientName);

    ApplicationManager.getApplication().assertIsDispatchThread();

    int result = Messages.showYesNoDialog(getProject(),
            P4Bundle.message("configuration.client-mismatch-ask", cachedClientName, p4ClientName),
            P4Bundle.message("configuration.check-connection"), Messages.getErrorIcon());
    if (result == Messages.YES) {
        // Signal to the API to try again only if
        // the user selected "okay".
        tryConfigChange();/*w ww  .  j a  v  a 2 s  . co  m*/
    } else {
        goOffline();
    }
}