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

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

Introduction

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

Prototype

public static int showDialog(String message, @Nls(capitalization = Nls.Capitalization.Title) String title,
        String @NotNull [] options, int defaultOptionIndex, @Nullable Icon icon,
        @Nullable DialogWrapper.DoNotAskOption doNotAskOption) 

Source Link

Document

Use this method only if you do not know project or component

Usage

From source file:com.headwire.aem.tooling.intellij.communication.MessageManager.java

License:Apache License

public void showAlert(@NotNull final NotificationType type, @NotNull final String title,
        @NotNull final String message) {
    // Make sure the Message is also placed inside the Log Console
    sendNotification(title, message, type);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
            Messages.showDialog(myProject, message, title, new String[] { Messages.OK_BUTTON }, 0,
                    getIcon(type));/*from   w  w w.j  a  v  a2  s.c o m*/
        }
    });
}

From source file:com.intellij.ide.ReopenProjectAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final int modifiers = e.getModifiers();
    final boolean forceOpenInNewFrame = (modifiers & InputEvent.CTRL_MASK) != 0
            || (modifiers & InputEvent.SHIFT_MASK) != 0;
    Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (!new File(myProjectPath).exists()) {
        if (Messages.showDialog(project, "The path " + FileUtil.toSystemDependentName(myProjectPath)
                + " does not exist.\n"
                + "If it is on a removable or network drive, please make sure that the drive is connected.",
                "Reopen Project", new String[] { "OK", "&Remove From List" }, 0,
                Messages.getErrorIcon()) == 1) {
            RecentProjectsManagerBase.getInstance().removePath(myProjectPath);
            ((WelcomeFrame) WelcomeFrame.getInstance()).getScreen().removeRecentProjectItem(this);
        }//from   w w w  .ja v  a 2 s. c o  m
        return;
    }
    RecentProjectsManagerBase.getInstance().doOpenProject(myProjectPath, project, forceOpenInNewFrame);
}

From source file:com.intellij.plugins.haxe.ide.HaxeFindUsagesHandlerFactory.java

License:Apache License

private String askWhetherToSearchForOverridingMethods(@NotNull PsiElement psiElement) {
    // TODO: Externalize the strings.
    int answer = Messages.showDialog(psiElement.getProject(),
            "Method is implemented in a base class or interface.  Would you like to find callers of the base class(es)?",
            "Find Method Callers", OVERRIDING_OPTIONS, 0, Messages.getQuestionIcon()); // XXX - Add "Don't ask again?  Have to store that and allow a reset if we do.
    if (-1 == answer) {
        throw new ProcessCanceledException(new Throwable("FindUsages canceled by user."));
    }//from  ww w.ja v a  2s .c o m
    return OVERRIDING_OPTIONS[answer];
}

From source file:com.intellij.usages.impl.SearchForUsagesRunnable.java

License:Apache License

private void endSearchForUsages(@NotNull final AtomicBoolean findStartedBalloonShown) {
    assert !ApplicationManager.getApplication().isDispatchThread() : Thread.currentThread();
    int usageCount = myUsageCountWithoutDefinition.get();
    if (usageCount == 0 && myProcessPresentation.isShowNotFoundMessage()) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override/*from www.  j  a  v a 2  s  .co m*/
            public void run() {
                if (myProcessPresentation.isCanceled()) {
                    notifyByFindBalloon(null, MessageType.WARNING, myProcessPresentation, myProject,
                            Arrays.asList("Usage search was canceled"));
                    findStartedBalloonShown.set(false);
                    return;
                }

                final List<Action> notFoundActions = myProcessPresentation.getNotFoundActions();
                final String message = UsageViewBundle.message("dialog.no.usages.found.in",
                        StringUtil.decapitalize(myPresentation.getUsagesString()),
                        myPresentation.getScopeText());

                if (notFoundActions.isEmpty()) {
                    List<String> lines = new ArrayList<String>();
                    lines.add(StringUtil.escapeXml(message));
                    if (myOutOfScopeUsages.get() != 0) {
                        lines.add(UsageViewManagerImpl.outOfScopeMessage(myOutOfScopeUsages.get(),
                                mySearchScopeToWarnOfFallingOutOf));
                    }
                    if (myProcessPresentation.isShowFindOptionsPrompt()) {
                        lines.add(createOptionsHtml(mySearchFor));
                    }
                    MessageType type = myOutOfScopeUsages.get() == 0 ? MessageType.INFO : MessageType.WARNING;
                    notifyByFindBalloon(createGotToOptionsListener(mySearchFor), type, myProcessPresentation,
                            myProject, lines);
                    findStartedBalloonShown.set(false);
                } else {
                    List<String> titles = new ArrayList<String>(notFoundActions.size() + 1);
                    titles.add(UsageViewBundle.message("dialog.button.ok"));
                    for (Action action : notFoundActions) {
                        Object value = action.getValue(FindUsagesProcessPresentation.NAME_WITH_MNEMONIC_KEY);
                        if (value == null)
                            value = action.getValue(Action.NAME);

                        titles.add((String) value);
                    }

                    int option = Messages.showDialog(myProject, message,
                            UsageViewBundle.message("dialog.title.information"),
                            ArrayUtil.toStringArray(titles), 0, Messages.getInformationIcon());

                    if (option > 0) {
                        notFoundActions.get(option - 1)
                                .actionPerformed(new ActionEvent(this, 0, titles.get(option)));
                    }
                }
            }
        }, ModalityState.NON_MODAL, myProject.getDisposed());
    } else if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
                Usage usage = myFirstUsage.get();
                if (usage.canNavigate()) {
                    usage.navigate(true);
                    flashUsageScriptaculously(usage);
                }
                List<String> lines = new ArrayList<String>();

                lines.add("Only one usage found.");
                if (myOutOfScopeUsages.get() != 0) {
                    lines.add(UsageViewManagerImpl.outOfScopeMessage(myOutOfScopeUsages.get(),
                            mySearchScopeToWarnOfFallingOutOf));
                }
                lines.add(createOptionsHtml(mySearchFor));
                MessageType type = myOutOfScopeUsages.get() == 0 ? MessageType.INFO : MessageType.WARNING;
                notifyByFindBalloon(createGotToOptionsListener(mySearchFor), type, myProcessPresentation,
                        myProject, lines);
            }
        }, ModalityState.NON_MODAL, myProject.getDisposed());
    } else {
        final UsageViewImpl usageView = myUsageViewRef.get();
        if (usageView != null) {
            usageView.drainQueuedUsageNodes();
            usageView.setSearchInProgress(false);
        }

        final List<String> lines;
        final HyperlinkListener hyperlinkListener;
        if (myOutOfScopeUsages.get() == 0 || getPsiElement(mySearchFor) == null) {
            lines = Collections.emptyList();
            hyperlinkListener = null;
        } else {
            lines = Arrays.asList(UsageViewManagerImpl.outOfScopeMessage(myOutOfScopeUsages.get(),
                    mySearchScopeToWarnOfFallingOutOf), createSearchInProjectHtml());
            hyperlinkListener = createSearchInProjectListener();
        }

        if (!myProcessPresentation.getLargeFiles().isEmpty() || myOutOfScopeUsages.get() != 0
                || myProcessPresentation.searchIncludingProjectFileUsages() != null) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    MessageType type = myOutOfScopeUsages.get() == 0 ? MessageType.INFO : MessageType.WARNING;
                    notifyByFindBalloon(hyperlinkListener, type, myProcessPresentation, myProject, lines);
                }
            }, ModalityState.NON_MODAL, myProject.getDisposed());
        }
    }

    if (myListener != null) {
        myListener.findingUsagesFinished(myUsageViewRef.get());
    }
}

From source file:io.flutter.run.LaunchState.java

License:Open Source License

private RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();

    // Set our FlutterLaunchMode up in the ExecutionEnvironment.
    if (RunMode.fromEnv(env).isProfiling()) {
        FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.PROFILE);
    }/* w  w w.j  a  v a2 s.c  om*/

    final Project project = getEnvironment().getProject();
    final FlutterDevice device = DeviceService.getInstance(project).getSelectedDevice();
    final FlutterApp app = callback.createApp(device);

    if (device == null) {
        Messages.showDialog(project,
                "No connected devices found; please connect a device, or see flutter.io/setup for getting started instructions.",
                "No Connected Devices Found", new String[] { Messages.OK_BUTTON }, 0,
                AllIcons.General.InformationDialog);

        return null;
    }

    // Cache for use in console configuration.
    FlutterApp.addToEnvironment(env, app);

    // Remember the run configuration that started this process.
    app.getProcessHandler().putUserData(FLUTTER_RUN_CONFIG_KEY, runConfig);

    final ExecutionResult result = setUpConsoleAndActions(app);

    // For Bazel run configurations,
    // where the console is not null,
    // and we find the expected process handler type,
    // print the command line command to the console.
    if (runConfig instanceof BazelRunConfig && app.getConsole() != null
            && app.getProcessHandler() instanceof OSProcessHandler) {
        final String commandLineString = ((OSProcessHandler) app.getProcessHandler()).getCommandLine().trim();
        if (StringUtil.isNotEmpty(commandLineString)) {
            app.getConsole().print(commandLineString + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
        }
    }

    device.bringToFront();

    // Check for and display any analysis errors when we launch an app.
    if (env.getRunProfile() instanceof SdkRunConfig) {
        final Class dartExecutionHelper = classForName(
                "com.jetbrains.lang.dart.ide.runner.DartExecutionHelper");
        if (dartExecutionHelper != null) {
            final String message = ("<a href='open.dart.analysis'>Analysis issues</a> may affect "
                    + "the execution of '" + env.getRunProfile().getName() + "'.");
            final SdkRunConfig config = (SdkRunConfig) env.getRunProfile();
            final SdkFields sdkFields = config.getFields();
            final MainFile mainFile = MainFile.verify(sdkFields.getFilePath(), env.getProject()).get();

            DartExecutionHelper.displayIssues(project, mainFile.getFile(), message,
                    env.getRunProfile().getIcon());
        }
    }

    final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(env);
    if (launchMode.supportsDebugConnection()) {
        return createDebugSession(env, app, result).getRunContentDescriptor();
    } else {
        return new RunContentBuilder(result, env).showRunContent(env.getContentToReuse());
    }
}

From source file:manuylov.maxim.ocaml.module.OCamlSourcesPathStep.java

License:Open Source License

public boolean validate() throws ConfigurationException {
    if (!super.validate()) {
        return false;
    }//  w w w .  ja  va 2s. co m

    if (myRbCreateSource.isSelected()) {
        final String sourceDirectoryPath = getSourceDirectoryPath();
        final String relativePath = myTfSourceDirectoryName.getText().trim();
        if (relativePath.length() == 0) {
            final String contentRoot = sourceDirectoryPath == null ? " "
                    : "\n\"" + FileUtil.toSystemDependentName(sourceDirectoryPath) + "\"\n";
            final String text = "Relative path to sources is empty.\nWould you like to mark the module content root"
                    + contentRoot + "as a source directory?";
            final int answer = Messages.showDialog(myTfSourceDirectoryName, text, "Mark source directory",
                    new String[] { "Mark", "Do Not Mark", CommonBundle.getCancelButtonText() }, 0,
                    Messages.getQuestionIcon());
            if (answer == 2) {
                return false; // cancel
            }
            if (answer == 1) { // don't mark
                myRbNoSource.doClick();
            }
        }
        if (sourceDirectoryPath != null) {
            final File rootDir = new File(getContentRootPath());
            final File srcDir = new File(sourceDirectoryPath);
            try {
                if (!FileUtil.isAncestor(rootDir, srcDir, false)) {
                    Messages.showErrorDialog(myTfSourceDirectoryName,
                            "Source directory should be under module content root directory",
                            CommonBundle.getErrorTitle());
                    return false;
                }
            } catch (IOException e) {
                Messages.showErrorDialog(myTfSourceDirectoryName, e.getMessage(), CommonBundle.getErrorTitle());
                return false;
            }
        }
    }
    return true;
}

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

License:Apache License

@Override
public void handleError(@NotNull final Date when) {
    LOG.warn("Disconnected from Perforce server");

    if (isInvalid() || isWorkingOnline()) {
        return;//from w ww  .  ja v a2 s.c  om
    }

    // We may need to switch to automatically work offline due
    // to a user setting.
    if (isAutoOffline()) {
        LOG.info("User running in auto-offline mode.  Will silently work disconnected.");
        return;
    }

    // Ask the user if they want to disconnect.
    LOG.info("Asking user to reconnect");
    int choice = Messages.showDialog(getProject(), P4Bundle.message("dialog.offline.message"),
            P4Bundle.message("dialog.offline.title"),
            new String[] { P4Bundle.message("dialog.offline.reconnect"),
                    P4Bundle.message("dialog.offline.offline-mode") },
            1, Messages.getErrorIcon());
    if (choice == 0) {
        connect();
    } else {
        goOffline();
    }
}

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

License:Apache License

@Override
public void handleError(@NotNull final Date when) {
    LOG.warn("Login problem", getException());

    if (isInvalid()) {
        return;//from   w  w  w .  j a va2s.  c  o m
    }

    boolean handleEndSeparately = false;

    if (beginAction(config)) {
        try {
            int result = Messages.showDialog(getProject(),
                    P4Bundle.message("configuration.login-problem-ask", getExceptionMessage()),
                    P4Bundle.message("configuration.login-problem.title"),
                    new String[] { P4Bundle.message("configuration.login-problem.yes"),
                            P4Bundle.message("configuration.login-problem.no"),
                            P4Bundle.message("configuration.login-problem.cancel") },
                    0, Messages.getErrorIcon());
            if (result == 0) { // first option: re-enter password
                // This needs to run in another event, otherwise the
                // message dialog will stay active forever.
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            PasswordManager.getInstance().askPassword(getProject(), config);
                            connect();
                        } catch (PasswordStoreException e) {
                            AlertManager.getInstance().addWarning(getProject(),
                                    P4Bundle.message("password.store.error.title"),
                                    P4Bundle.message("password.store.error"), e, new FilePath[0]);
                        } finally {
                            endAction(config);
                        }
                    }
                });
                handleEndSeparately = true;
            } else if (result == 1) { // 2nd option: update server config
                tryConfigChange();
            } else { // 3rd option: work offline
                goOffline();
            }
        } finally {
            if (!handleEndSeparately) {
                endAction(config);
            }
        }
    } else {
        LOG.info("Already handling login for config " + config);
    }
}

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

License:Apache License

@Override
public void handleError(@NotNull final Date when) {
    LOG.warn("Server refused authentication too many times");

    boolean handleEndSeparately = false;

    if (beginAction(config)) {
        try {//from w  w  w  .j  a  v  a 2s. c o  m
            int result = Messages.showDialog(getProject(),
                    P4Bundle.message("configuration.retry-auth-problem-ask", getExceptionMessage()),
                    P4Bundle.message("configuration.retry-auth-problem.title"),
                    new String[] { P4Bundle.message("configuration.retry-auth-problem.retry"),
                            P4Bundle.message("configuration.retry-auth-problem.config-change"),
                            P4Bundle.message("configuration.retry-auth-problem.offline") },
                    0, Messages.getErrorIcon());
            if (result == 0) { // first option: re-enter password
                // This needs to run in another event, otherwise the
                // message dialog will stay active forever.
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            connect();
                        } finally {
                            endAction(config);
                        }
                    }
                });
                handleEndSeparately = true;
            } else if (result == 1) { // 2nd option: update server config
                tryConfigChange();
            } else { // 3rd option: work offline
                goOffline();
            }
        } finally {
            if (!handleEndSeparately) {
                endAction(config);
            }
        }
    } else {
        LOG.info("Already handling login for config " + config);
    }
}

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

License:Apache License

@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
private boolean initializeDdmlib(@NotNull Project project) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    while (true) {
        final MyInitializeDdmlibTask task = new MyInitializeDdmlibTask(project);

        AdbErrors.clear();//from  w  w w  .ja va2s  .  c  om

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                doInitializeDdmlib();
                task.finish();
            }
        });

        t.start();

        boolean retryWas = false;

        while (!task.isFinished()) {
            ProgressManager.getInstance().run(task);

            boolean finished = task.isFinished();

            if (task.isCanceled()) {
                myAdbCrashed = !finished;
                forceInterrupt(t);
                return false;
            }

            myAdbCrashed = false;

            if (!finished) {
                final String adbErrorString = combine(AdbErrors.getErrors());
                final int result = Messages.showDialog(project,
                        "ADB not responding. You can wait more, or kill \"" + SdkConstants.FN_ADB
                                + "\" process manually and click 'Restart'"
                                + (adbErrorString.length() > 0 ? "\nErrors from ADB:\n" + adbErrorString : ""),
                        CommonBundle.getErrorTitle(), new String[] { "&Wait more", "&Restart", "&Cancel" }, 0,
                        Messages.getErrorIcon());
                if (result == 2) {
                    // cancel
                    myAdbCrashed = true;
                    forceInterrupt(t);
                    return false;
                } else if (result == 1) {
                    // restart
                    myAdbCrashed = true;
                    retryWas = true;
                }
            }
        }

        // task finished, but if we had problems, ddmlib can be still initialized incorrectly, so we invoke initialize once again
        if (!retryWas) {
            break;
        }
    }

    return true;
}