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:org.jetbrains.android.run.CreateAvdDialog.java

License:Apache License

@Override
protected void doOKAction() {
    if (myNameField.getText().length() == 0) {
        Messages.showErrorDialog(myPanel, AndroidBundle.message("specify.avd.name.error"));
        return;/*from  w  ww  .ja  va2  s.  c  o  m*/
    } else if (myTargetBox.getSelectedItem() == null) {
        Messages.showErrorDialog(myPanel, AndroidBundle.message("select.target.dialog.text"));
        return;
    }
    String avdName = myNameField.getText();
    AvdInfo info = myAvdManager.getAvd(avdName, false);
    if (info != null) {
        boolean replace = Messages.showYesNoDialog(myPanel,
                AndroidBundle.message("replace.avd.question", avdName),
                AndroidBundle.message("create.avd.dialog.title"), Messages.getQuestionIcon()) == 0;
        if (!replace)
            return;
    }
    File avdFolder;
    try {
        avdFolder = new File(AndroidLocation.getFolder() + FOLDER_AVD,
                avdName + AvdManager.AVD_FOLDER_EXTENSION);
    } catch (AndroidLocation.AndroidLocationException e) {
        Messages.showErrorDialog(myPanel, e.getMessage(), "Error");
        return;
    }
    super.doOKAction();
    IAndroidTarget selectedTarget = (IAndroidTarget) myTargetBox.getSelectedItem();
    String skin = (String) mySkinField.getSelectedItem();
    String abi = (String) myAbiCombo.getSelectedItem();
    String sdCard = getSdCardParameter();
    MessageBuildingSdkLog log = new MessageBuildingSdkLog();
    myCreatedAvd = myAvdManager.createAvd(avdFolder, avdName, selectedTarget, abi, skin, sdCard, null, true,
            false, false, log);
    if (log.getErrorMessage().length() > 0) {
        Messages.showErrorDialog(myProject, log.getErrorMessage(),
                AndroidBundle.message("android.avd.error.title"));
    }
}

From source file:org.jetbrains.android.sdk.AndroidSdkUtils.java

License:Apache License

public static boolean activateDdmsIfNecessary(@NotNull Project project,
        @NotNull Computable<AndroidDebugBridge> bridgeProvider) {
    if (AndroidEnableAdbServiceAction.isAdbServiceEnabled()) {
        AndroidDebugBridge bridge = bridgeProvider.compute();
        if (bridge != null && isDdmsCorrupted(bridge)) {
            LOG.info("DDMLIB is corrupted and will be restarted");
            restartDdmlib(project);//from w  ww  .  java  2  s .c  o  m
        }
    } else {
        final OSProcessHandler ddmsProcessHandler = AndroidRunDdmsAction.getDdmsProcessHandler();
        if (ddmsProcessHandler != null) {
            int r = Messages.showYesNoDialog(project,
                    "Monitor will be closed to enable ADB integration. Continue?", "ADB Integration",
                    Messages.getQuestionIcon());
            if (r != Messages.YES) {
                return false;
            }

            Runnable destroyingRunnable = new Runnable() {
                @Override
                public void run() {
                    if (!ddmsProcessHandler.isProcessTerminated()) {
                        OSProcessManager.getInstance().killProcessTree(ddmsProcessHandler.getProcess());
                        ddmsProcessHandler.waitFor();
                    }
                }
            };
            if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(destroyingRunnable,
                    "Closing Monitor", true, project)) {
                return false;
            }
            AndroidEnableAdbServiceAction.setAdbServiceEnabled(project, true);
            return true;
        }

        int result = Messages.showYesNoDialog(project, AndroidBundle.message("android.ddms.disabled.error"),
                AndroidBundle.message("android.ddms.disabled.dialog.title"), Messages.getQuestionIcon());
        if (result != Messages.YES) {
            return false;
        }
        AndroidEnableAdbServiceAction.setAdbServiceEnabled(project, true);
    }
    return true;
}

From source file:org.jetbrains.android.util.AndroidUtils.java

License:Apache License

public static void addRunConfiguration(@NotNull final AndroidFacet facet, @Nullable final String activityClass,
        final boolean ask, @Nullable final TargetSelectionMode targetSelectionMode,
        @Nullable final String preferredAvdName) {
    final Module module = facet.getModule();
    final Project project = module.getProject();

    final Runnable r = new Runnable() {
        @Override//  w  w  w .  ja v a 2  s .  c  o  m
        public void run() {
            final RunManagerEx runManager = RunManagerEx.getInstanceEx(project);
            final RunnerAndConfigurationSettings settings = runManager.createRunConfiguration(module.getName(),
                    AndroidRunConfigurationType.getInstance().getFactory());
            final AndroidRunConfiguration configuration = (AndroidRunConfiguration) settings.getConfiguration();
            configuration.setModule(module);

            if (activityClass != null) {
                configuration.MODE = AndroidRunConfiguration.LAUNCH_SPECIFIC_ACTIVITY;
                configuration.ACTIVITY_CLASS = activityClass;
            } else {
                configuration.MODE = AndroidRunConfiguration.LAUNCH_DEFAULT_ACTIVITY;
            }

            if (targetSelectionMode != null) {
                configuration.setTargetSelectionMode(targetSelectionMode);
            }
            if (preferredAvdName != null) {
                configuration.PREFERRED_AVD = preferredAvdName;
            }
            runManager.addConfiguration(settings, false);
            runManager.setActiveConfiguration(settings);
        }
    };
    if (!ask) {
        r.run();
    } else {
        UIUtil.invokeLaterIfNeeded(new Runnable() {
            @Override
            public void run() {
                final String moduleName = facet.getModule().getName();
                final int result = Messages.showYesNoDialog(project,
                        AndroidBundle.message("create.run.configuration.question", moduleName),
                        AndroidBundle.message("create.run.configuration.title"), Messages.getQuestionIcon());
                if (result == 0) {
                    r.run();
                }
            }
        });
    }
}

From source file:org.jetbrains.idea.maven.importing.MavenProjectImporter.java

License:Apache License

private boolean deleteObsoleteModules() {
    final List<Module> obsoleteModules = collectObsoleteModules();
    if (obsoleteModules.isEmpty()) {
        return false;
    }/*www.  ja va2  s  .  c  om*/

    setMavenizedModules(obsoleteModules, false);

    final int[] result = new int[1];
    MavenUtil.invokeAndWait(myProject, myModelsProvider.getModalityStateForQuestionDialogs(), new Runnable() {
        @Override
        public void run() {
            result[0] = Messages.showYesNoDialog(myProject,
                    ProjectBundle.message("maven.import.message.delete.obsolete",
                            formatModules(obsoleteModules)),
                    ProjectBundle.message("maven.project.import.title"), Messages.getQuestionIcon());
        }
    });

    if (result[0] == Messages.NO) {
        return false;// NO
    }

    for (Module each : obsoleteModules) {
        if (!each.isDisposed()) {
            myModuleModel.disposeModule(each);
        }
    }

    return true;
}

From source file:org.jetbrains.idea.maven.navigator.actions.RemoveMavenRunConfigurationAction.java

License:Apache License

@RequiredUIAccess
@Override/* www. j a  v  a2s  .  c  o m*/
public void actionPerformed(@Nonnull AnActionEvent e) {
    Project project = e.getProject();
    RunnerAndConfigurationSettings settings = e.getData(MavenDataKeys.RUN_CONFIGURATION);

    assert settings != null && project != null;

    int res = Messages.showYesNoDialog(project, "Delete \"" + settings.getName() + "\"?", "Confirmation",
            Messages.getQuestionIcon());
    if (res == Messages.YES) {
        ((RunManagerEx) RunManager.getInstance(project)).removeConfiguration(settings);
    }
}

From source file:org.jetbrains.idea.svn.actions.CreateBranchOrTagAction.java

License:Apache License

protected void perform(final Project project, final SvnVcs activeVcs, VirtualFile file, DataContext context)
        throws VcsException {
    CreateBranchOrTagDialog dialog = new CreateBranchOrTagDialog(project, true, new File(file.getPath()));
    dialog.show();/*  ww w .ja v  a  2  s  . c o  m*/
    if (dialog.isOK()) {
        final String dstURL = dialog.getToURL();
        final SVNRevision revision = dialog.getRevision();
        final String comment = dialog.getComment();
        final Ref<Exception> exception = new Ref<Exception>();
        final boolean isSrcFile = dialog.isCopyFromWorkingCopy();
        final File srcFile = new File(dialog.getCopyFromPath());
        final SVNURL srcUrl;
        final SVNURL dstSvnUrl;
        final SVNURL parentUrl;
        try {
            srcUrl = SVNURL.parseURIEncoded(dialog.getCopyFromUrl());
            dstSvnUrl = SVNURL.parseURIEncoded(dstURL);
            parentUrl = dstSvnUrl.removePathTail();

            if (!dirExists(activeVcs, project, parentUrl)) {
                int rc = Messages.showYesNoDialog(project,
                        "The repository path '" + parentUrl + "' does not exist. Would you like to create it?",
                        "Branch or Tag", Messages.getQuestionIcon());
                if (rc == Messages.NO) {
                    return;
                }
            }

        } catch (SVNException e) {
            throw new VcsException(e);
        }

        Runnable copyCommand = new Runnable() {
            public void run() {
                try {
                    ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
                    CommitEventHandler handler = null;
                    if (progress != null) {
                        progress.setText(SvnBundle.message("progress.text.copy.to", dstURL));
                        handler = new IdeaCommitHandler(progress);
                    }
                    checkCreateDir(parentUrl, activeVcs, comment);

                    SvnTarget source = isSrcFile ? SvnTarget.fromFile(srcFile, revision)
                            : SvnTarget.fromURL(srcUrl, revision);
                    long newRevision = activeVcs.getFactory(source).createCopyMoveClient().copy(source,
                            SvnTarget.fromURL(dstSvnUrl), revision, true, comment, handler);

                    updateStatusBar(newRevision, project);
                } catch (Exception e) {
                    exception.set(e);
                }
            }
        };
        ProgressManager.getInstance().runProcessWithProgressSynchronously(copyCommand,
                SvnBundle.message("progress.title.copy"), false, project);
        if (!exception.isNull()) {
            throw new VcsException(exception.get());
        }

        if (dialog.isCopyFromWorkingCopy() && dialog.isSwitchOnCreate()) {
            SingleRootSwitcher switcher = new SingleRootSwitcher(project,
                    VcsUtil.getFilePath(srcFile, srcFile.isDirectory()), dstSvnUrl.toDecodedString());

            AutoSvnUpdater.run(switcher, SvnBundle.message("action.name.switch"));
        }
    }
}

From source file:org.jetbrains.idea.svn.actions.MarkLocallyDeletedTreeConflictResolvedAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    final MyLocallyDeletedChecker locallyDeletedChecker = new MyLocallyDeletedChecker(e);
    if (!locallyDeletedChecker.isEnabled())
        return;//from  www .  ja v  a  2  s. co  m

    final String markText = SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.title");
    final Project project = locallyDeletedChecker.getProject();
    final int result = Messages.showYesNoDialog(project,
            SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.text"), markText,
            Messages.getQuestionIcon());
    if (result == Messages.YES) {
        final Ref<VcsException> exception = new Ref<VcsException>();
        ProgressManager.getInstance()
                .run(new Task.Backgroundable(project, markText, true, BackgroundFromStartOption.getInstance()) {
                    public void run(@NotNull ProgressIndicator indicator) {
                        resolveLocallyDeletedTextConflict(locallyDeletedChecker, exception);
                    }
                });
        if (!exception.isNull()) {
            AbstractVcsHelper.getInstance(project).showError(exception.get(), markText);
        }
    }
}

From source file:org.jetbrains.idea.svn.actions.MarkTreeConflictResolvedAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final MyChecker checker = new MyChecker(e);
    if (!checker.isEnabled())
        return;/*ww w  .j a  v  a  2s .c o m*/

    final String markText = SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.title");
    final int result = Messages.showYesNoDialog(checker.getProject(),
            SvnBundle.message("action.mark.tree.conflict.resolved.confirmation.text"), markText,
            Messages.getQuestionIcon());
    if (result == Messages.YES) {
        final Ref<VcsException> exception = new Ref<VcsException>();
        ProgressManager.getInstance().run(new Task.Backgroundable(checker.getProject(), markText, true,
                BackgroundFromStartOption.getInstance()) {
            public void run(@NotNull ProgressIndicator indicator) {
                final ConflictedSvnChange change = checker.getChange();
                final FilePath path = change.getTreeConflictMarkHolder();
                SvnVcs vcs = SvnVcs.getInstance(checker.getProject());

                try {
                    vcs.getFactory(path.getIOFile()).createConflictClient().resolve(path.getIOFile(),
                            SVNDepth.EMPTY, false, false, true);
                } catch (VcsException e) {
                    exception.set(e);
                }
                VcsDirtyScopeManager.getInstance(checker.getProject()).filePathsDirty(getDistinctFiles(change),
                        null);
            }
        });
        if (!exception.isNull()) {
            AbstractVcsHelper.getInstance(checker.getProject()).showError(exception.get(), markText);
        }
    }
}

From source file:org.jetbrains.idea.svn.actions.ShareProjectAction.java

License:Apache License

private static boolean performImpl(final Project project, final SvnVcs activeVcs, final VirtualFile file)
        throws VcsException {
    final ShareDialog shareDialog = new ShareDialog(project, file.getName());
    shareDialog.show();/*from ww  w.  j a  v  a 2 s. c o  m*/

    final String parent = shareDialog.getSelectedURL();
    if (shareDialog.isOK() && parent != null) {
        final Ref<Boolean> actionStarted = new Ref<Boolean>(Boolean.TRUE);
        final Exception[] error = new Exception[1];

        final ShareDialog.ShareTarget shareTarget = shareDialog.getShareTarget();
        final ProgressManager progressManager = ProgressManager.getInstance();

        if (ShareDialog.ShareTarget.useSelected.equals(shareTarget)) {
            final boolean folderEmpty = checkRemoteFolder(project, activeVcs, parent, progressManager);

            if (!folderEmpty) {
                final int promptAnswer = Messages.showYesNoDialog(project,
                        "Remote folder \"" + parent + "\" is not empty.\nDo you want to continue sharing?",
                        "Share directory", Messages.getWarningIcon());
                if (Messages.YES != promptAnswer)
                    return false;
            }
        }

        final WorkingCopyFormat format = SvnCheckoutProvider
                .promptForWCopyFormat(VfsUtilCore.virtualToIoFile(file), project);
        actionStarted.set(format != WorkingCopyFormat.UNKNOWN);
        // means operation cancelled
        if (format == WorkingCopyFormat.UNKNOWN) {
            return true;
        }

        ExclusiveBackgroundVcsAction.run(project, new Runnable() {
            public void run() {
                progressManager.runProcessWithProgressSynchronously(new Runnable() {
                    public void run() {
                        try {
                            final ProgressIndicator indicator = ProgressManager.getInstance()
                                    .getProgressIndicator();
                            final File path = new File(file.getPath());

                            SvnWorkingCopyFormatHolder.setPresetFormat(format);

                            final SVNURL parenUrl = SVNURL.parseURIEncoded(parent);
                            final SVNURL checkoutUrl;
                            final SVNRevision revision;
                            final String commitText = shareDialog.getCommitText();
                            if (ShareDialog.ShareTarget.useSelected.equals(shareTarget)) {
                                checkoutUrl = parenUrl;
                                revision = SVNRevision.HEAD;
                            } else if (ShareDialog.ShareTarget.useProjectName.equals(shareTarget)) {
                                final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl,
                                        file.getName(), commitText);
                                revision = pair.getFirst();
                                checkoutUrl = pair.getSecond();
                            } else {
                                final Pair<SVNRevision, SVNURL> pair = createRemoteFolder(activeVcs, parenUrl,
                                        file.getName(), commitText);
                                final Pair<SVNRevision, SVNURL> trunkPair = createRemoteFolder(activeVcs,
                                        pair.getSecond(), "trunk", commitText);
                                checkoutUrl = trunkPair.getSecond();
                                revision = trunkPair.getFirst();

                                if (shareDialog.createStandardStructure()) {
                                    createRemoteFolder(activeVcs, pair.getSecond(), "branches", commitText);
                                    createRemoteFolder(activeVcs, pair.getSecond(), "tags", commitText);
                                }
                            }

                            if (indicator != null) {
                                indicator.checkCanceled();
                                indicator.setText(SvnBundle.message(
                                        "share.directory.checkout.back.progress.text", checkoutUrl.toString()));
                            }

                            final ClientFactory factory = SvnCheckoutProvider.getFactory(activeVcs, format);

                            factory.createCheckoutClient().checkout(SvnTarget.fromURL(checkoutUrl), path,
                                    revision, SVNDepth.INFINITY, false, false, format, null);
                            addRecursively(activeVcs, factory, file);
                        } catch (SVNException e) {
                            error[0] = e;
                        } catch (VcsException e) {
                            error[0] = e;
                        } finally {
                            activeVcs.invokeRefreshSvnRoots();
                            SvnWorkingCopyFormatHolder.setPresetFormat(null);
                        }
                    }
                }, SvnBundle.message("share.directory.title"), true, project);
            }
        });

        if (Boolean.TRUE.equals(actionStarted.get())) {
            if (error[0] != null) {
                throw new VcsException(error[0].getMessage());
            }
            Messages.showInfoMessage(project, SvnBundle.message("share.directory.info.message", file.getName()),
                    SvnBundle.message("share.directory.title"));
        }
        return true;
    }
    return false;
}

From source file:org.jetbrains.idea.svn.SvnAuthenticationManager.java

License:Apache License

/**
 * Shows a yes/no question whether user wants to store his password in plain text and returns his answer.
 * @param title   title of the questioning dialog.
 * @param message questioning message to be displayed.
 * @return true if user agrees to store his password in plaintext, false if he doesn't.
 *//* www.  ja v a 2s .c om*/
@CalledInAwt
private boolean askToStoreUnencrypted(String title, String message) {
    final int answer = Messages.showYesNoDialog(myProject, message, title, Messages.getQuestionIcon());
    return answer == Messages.YES;
}