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

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

Introduction

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

Prototype

@OkCancelResult
public static int showOkCancelDialog(String message,
        @Nls(capitalization = Nls.Capitalization.Title) String title, String okText, String cancelText,
        Icon icon) 

Source Link

Document

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

Usage

From source file:com.android.tools.idea.welcome.install.CheckSdkOperation.java

License:Apache License

private static boolean retryPrompt() {
    int button = Messages.showOkCancelDialog(MESSAGE_CANT_RUN_TOOL, "Android Studio", "Retry", "Cancel",
            Messages.getErrorIcon());/*from   w w w  .j  a  v a2  s  .com*/
    return button == Messages.OK;
}

From source file:com.google.cloud.tools.intellij.appengine.cloud.CloudSdkAppEngineHelper.java

License:Apache License

@Override
public Path stageCredentials(String googleUserName) {
    Path credentials = doStageCredentials(googleUserName);
    if (credentials != null) {
        return credentials;
    }/*from  w  w w.  ja v a  2s  .c  o  m*/

    int addUserResult = Messages.showOkCancelDialog(
            GctBundle.message("appengine.staging.credentials.error.message"),
            GctBundle.message("appengine.staging.credentials.error.dialog.title"),
            GctBundle.message("appengine.staging.credentials.error.dialog.addaccount.button"),
            GctBundle.message("appengine.staging.credentials.error.dialog.cancel.button"),
            Messages.getWarningIcon());

    if (addUserResult == Messages.OK) {
        Services.getLoginService().logIn();
        return doStageCredentials(googleUserName);
    }

    return null;
}

From source file:com.intellij.find.findUsages.JavaFindUsagesHandler.java

License:Apache License

@Override
@NotNull//ww  w .  j  a v a  2s  . c o m
public PsiElement[] getSecondaryElements() {
    PsiElement element = getPsiElement();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return PsiElement.EMPTY_ARRAY;
    }
    if (element instanceof PsiField) {
        final PsiField field = (PsiField) element;
        PsiClass containingClass = field.getContainingClass();
        if (containingClass != null) {
            String fieldName = field.getName();
            final String propertyName = JavaCodeStyleManager.getInstance(getProject())
                    .variableNameToPropertyName(fieldName, VariableKind.FIELD);
            Set<PsiMethod> accessors = new THashSet<PsiMethod>();
            boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
            PsiMethod getter = PropertyUtil.findPropertyGetterWithType(propertyName, isStatic, field.getType(),
                    ContainerUtil.iterate(containingClass.getMethods()));
            if (getter != null) {
                accessors.add(getter);
            }
            PsiMethod setter = PropertyUtil.findPropertySetterWithType(propertyName, isStatic, field.getType(),
                    ContainerUtil.iterate(containingClass.getMethods()));
            if (setter != null) {
                accessors.add(setter);
            }
            accessors.addAll(PropertyUtil.getAccessors(containingClass, fieldName));
            if (!accessors.isEmpty()) {
                boolean containsPhysical = ContainerUtil.find(accessors, new Condition<PsiMethod>() {
                    @Override
                    public boolean value(PsiMethod psiMethod) {
                        return psiMethod.isPhysical();
                    }
                }) != null;
                final boolean doSearch = !containsPhysical || Messages.showOkCancelDialog(
                        FindBundle.message("find.field.accessors.prompt", fieldName),
                        FindBundle.message("find.field.accessors.title"), CommonBundle.getYesButtonText(),
                        CommonBundle.getNoButtonText(), Messages.getQuestionIcon()) == Messages.OK;
                if (doSearch) {
                    final Set<PsiElement> elements = new THashSet<PsiElement>();
                    for (PsiMethod accessor : accessors) {
                        ContainerUtil.addAll(elements,
                                SuperMethodWarningUtil.checkSuperMethods(accessor, ACTION_STRING));
                    }
                    return PsiUtilCore.toPsiElementArray(elements);
                }
            }
        }
    }
    return super.getSecondaryElements();
}

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

License:Apache License

/**
 * Start a new thread which downloads new list of plugins from the site in
 * the background and updates a list of plugins in the table.
 *//*from   w ww . ja v a 2  s  .  co m*/
protected void loadPluginsFromHostInBackground() {
    setDownloadStatus(true);

    new SwingWorker() {
        List<IdeaPluginDescriptor> list = null;
        List<String> errorMessages = new ArrayList<String>();

        @Override
        public Object construct() {
            try {
                list = RepositoryHelper.loadPluginsFromRepository(null);
            } catch (Exception e) {
                LOG.info(e);
                errorMessages.add(e.getMessage());
            }
            for (String host : UpdateSettings.getInstance().getStoredPluginHosts()) {
                if (!acceptHost(host))
                    continue;
                final ArrayList<PluginDownloader> downloaded = new ArrayList<PluginDownloader>();
                try {
                    UpdateChecker.checkPluginsHost(host, downloaded, false, null);
                    for (PluginDownloader downloader : downloaded) {
                        final PluginNode pluginNode = PluginDownloader.createPluginNode(host, downloader);
                        if (pluginNode != null) {
                            if (list == null)
                                list = new ArrayList<IdeaPluginDescriptor>();
                            list.add(pluginNode);
                        }
                    }
                } catch (ProcessCanceledException ignore) {
                } catch (Exception e) {
                    LOG.info(e);
                    errorMessages.add(e.getMessage());
                }
            }
            return list;
        }

        @Override
        public void finished() {
            UIUtil.invokeLaterIfNeeded(new Runnable() {
                @Override
                public void run() {
                    setDownloadStatus(false);
                    if (list != null) {
                        modifyPluginsList(list);
                        propagateUpdates(list);
                    }
                    if (!errorMessages.isEmpty()) {
                        if (Messages.OK == Messages.showOkCancelDialog(
                                IdeBundle.message("error.list.of.plugins.was.not.loaded",
                                        StringUtil.join(errorMessages, ", ")),
                                IdeBundle.message("title.plugins"), CommonBundle.message("button.retry"),
                                CommonBundle.getCancelButtonText(), Messages.getErrorIcon())) {
                            loadPluginsFromHostInBackground();
                        }
                    }
                }
            });
        }
    }.start();
}

From source file:com.intellij.ide.ui.laf.LafManagerImpl.java

License:Apache License

private boolean checkLookAndFeel(final UIManager.LookAndFeelInfo lafInfo, final boolean confirm) {
    String message = null;//from  w  ww .  j a v  a2s  .  co  m

    if (lafInfo.getName().contains("GTK") && SystemInfo.isXWindow
            && !SystemInfo.isJavaVersionAtLeast("1.6.0_12")) {
        message = IdeBundle.message("warning.problem.laf.1");
    }

    if (message != null) {
        if (confirm) {
            final String[] options = { IdeBundle.message("confirm.set.look.and.feel"),
                    CommonBundle.getCancelButtonText() };
            final int result = Messages.showOkCancelDialog(message, CommonBundle.getWarningTitle(), options[0],
                    options[1], Messages.getWarningIcon());
            if (result == 0) {
                myLastWarning = message;
                return true;
            }
            return false;
        }

        if (!message.equals(myLastWarning)) {
            Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "L&F Manager",
                    message, NotificationType.WARNING, NotificationListener.URL_OPENING_LISTENER));
            myLastWarning = message;
        }
    }

    return true;
}

From source file:com.magnet.plugin.r2m.helpers.AsyncHelper.java

License:Open Source License

private void showOverrideConfirmationDialog(final List<String> list) {
    this.result = false;
    StringBuilder sb = new StringBuilder("\n");
    for (String e : list) {
        sb.append(e).append("\n");
    }/*from w  w  w  .  j  av a2 s .c om*/
    int option = Messages.showOkCancelDialog(R2MMessages.getMessage("CONFIRM_OVERRIDE_FILES", sb.toString()),
            R2MMessages.getMessage("CONFIRM_OVERRIDE_FILES_TITLE"),
            R2MMessages.getMessage("CONFIRM_OVERRIDE_FILES_BUTTON_TEXT"), Messages.CANCEL_BUTTON,
            Messages.getWarningIcon());
    if (option == 0) {
        onActionSuccess(GenerateActions.START_FILE_OPERATIONS);
    } else {
        this.result = true;
        onActionSuccess(GenerateActions.FILE_OPERATION_SUCCESS);
    }
}

From source file:com.magnet.plugin.r2m.ui.AddControllerForm.java

License:Open Source License

private void showCloseDialog(File file) {
    String path = file.getAbsolutePath();
    String folder = path.substring(0, path.lastIndexOf(File.separator));
    String className = path.substring(path.lastIndexOf(File.separator) + 1);
    int option = Messages.showOkCancelDialog(
            R2MMessages.getMessage("SOURCE_AVAILABLE_CONTINUE_EDITING_QUESTION", className, folder),
            R2MMessages.getMessage("SUCCESS"), R2MMessages.getMessage("CLOSE_AND_SHOW_CODE_BUTTON_TEXT"),
            R2MMessages.getMessage("CONTINUE_EDITING_BUTTON_TEXT"), Messages.getQuestionIcon());
    if (option != 0) {
        getThis().setVisible(true);//from   ww  w.j  av  a 2s .co m
    } else {
        dispose();
    }
}

From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.PluginManagerMain.java

License:Apache License

/**
 * Start a new thread which downloads new list of plugins from the site in
 * the background and updates a list of plugins in the table.
 *///from   ww w .  j  a  va2 s .co  m
protected void loadPluginsFromHostInBackground() {
    setDownloadStatus(true);

    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override
        public void run() {
            final List<IdeaPluginDescriptor> list = ContainerUtil.newArrayList();
            final Map<String, String> errors = ContainerUtil.newLinkedHashMap();
            ProgressIndicator indicator = new EmptyProgressIndicator();

            List<String> hosts = RepositoryHelper.getPluginHosts();
            Set<PluginId> unique = ContainerUtil.newHashSet();
            for (String host : hosts) {
                try {
                    if (host == null || acceptHost(host)) {
                        List<IdeaPluginDescriptor> plugins = RepositoryHelper.loadPlugins(host, indicator);
                        for (IdeaPluginDescriptor plugin : plugins) {
                            if (unique.add(plugin.getPluginId())) {
                                list.add(plugin);
                            }
                        }
                    }
                } catch (FileNotFoundException e) {
                    LOG.info(host, e);
                } catch (IOException e) {
                    LOG.info(host, e);
                    if (host != ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl()) {
                        errors.put(host, String.format("'%s' for '%s'", e.getMessage(), host));
                    }
                }
            }

            UIUtil.invokeLaterIfNeeded(new Runnable() {
                @Override
                public void run() {
                    setDownloadStatus(false);

                    if (!list.isEmpty()) {
                        InstalledPluginsState state = InstalledPluginsState.getInstance();
                        for (IdeaPluginDescriptor descriptor : list) {
                            state.onDescriptorDownload(descriptor);
                        }

                        modifyPluginsList(list);
                        propagateUpdates(list);
                    }

                    if (!errors.isEmpty()) {
                        String message = IdeBundle.message("error.list.of.plugins.was.not.loaded",
                                StringUtil.join(errors.keySet(), ", "),
                                StringUtil.join(errors.values(), ",\n"));
                        String title = IdeBundle.message("title.plugins");
                        String ok = CommonBundle.message("button.retry"),
                                cancel = CommonBundle.getCancelButtonText();
                        if (Messages.showOkCancelDialog(message, title, ok, cancel,
                                Messages.getErrorIcon()) == Messages.OK) {
                            loadPluginsFromHostInBackground();
                        }
                    }
                }
            });
        }
    });
}

From source file:com.perl5.lang.perl.idea.refactoring.rename.PerlRenamePolyReferencedElementProcessor.java

License:Apache License

@NotNull
private PsiElement suggestSuperMethod(@NotNull PerlSubBase subBase) {
    PerlSubBase topLevelSuperMethod = PerlSubUtil.getTopLevelSuperMethod(subBase);

    if (topLevelSuperMethod == subBase)
        return subBase;

    int dialogResult = Messages.showOkCancelDialog(
            "This method overrides SUPER method: " + topLevelSuperMethod.getCanonicalName() + ".",
            "Method Rename", "Rename SUPER method", "Rename this one", PerlIcons.PERL_LANGUAGE_ICON);

    return dialogResult == Messages.OK ? topLevelSuperMethod : subBase;
}

From source file:org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataService.java

License:Apache License

@Nullable
private ExternalProject importExternalProject(@NotNull final Project project,
        @NotNull final ProjectSystemId projectSystemId, @NotNull final File projectRootDir) {
    final Boolean result = UIUtil.invokeAndWaitIfNeeded(new Computable<Boolean>() {
        @Override/*w  ww.j av a2 s.  co  m*/
        public Boolean compute() {
            final Ref<Boolean> result = new Ref<Boolean>(false);
            if (project.isDisposed()) {
                return false;
            }

            final String linkedProjectPath = FileUtil.toCanonicalPath(projectRootDir.getPath());
            final ExternalProjectSettings projectSettings = ExternalSystemApiUtil
                    .getSettings(project, projectSystemId).getLinkedProjectSettings(linkedProjectPath);
            if (projectSettings == null) {
                LOG.warn("Unable to get project settings for project path: " + linkedProjectPath);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Available projects paths: " + ContainerUtil.map(
                            ExternalSystemApiUtil.getSettings(project, projectSystemId)
                                    .getLinkedProjectsSettings(),
                            new Function<ExternalProjectSettings, String>() {
                                @Override
                                public String fun(ExternalProjectSettings settings) {
                                    return settings.getExternalProjectPath();
                                }
                            }));
                }
                return false;
            }

            final File projectFile = new File(linkedProjectPath);
            final String projectName;
            if (projectFile.isFile()) {
                projectName = projectFile.getParentFile().getName();
            } else {
                projectName = projectFile.getName();
            }

            // ask a user for the project import if auto-import is disabled
            if (!projectSettings.isUseAutoImport()) {
                String message = String.format(
                        "Project '%s' require synchronization with %s configuration. \nImport the project?",
                        projectName, projectSystemId.getReadableName());
                int returnValue = Messages.showOkCancelDialog(message, "Import Project",
                        CommonBundle.getOkButtonText(), CommonBundle.getCancelButtonText(),
                        Messages.getQuestionIcon());
                if (returnValue != Messages.OK) {
                    return false;
                }
            }

            final String title = ExternalSystemBundle.message("progress.import.text", linkedProjectPath,
                    projectSystemId.getReadableName());
            new Task.Modal(project, title, false) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    if (project.isDisposed()) {
                        return;
                    }

                    ExternalSystemNotificationManager.getInstance(project).clearNotifications(null,
                            NotificationSource.PROJECT_SYNC, projectSystemId);
                    ExternalSystemResolveProjectTask task = new ExternalSystemResolveProjectTask(
                            projectSystemId, project, linkedProjectPath, false);
                    task.execute(indicator, ExternalSystemTaskNotificationListener.EP_NAME.getExtensions());
                    if (project.isDisposed()) {
                        return;
                    }

                    final Throwable error = task.getError();
                    if (error != null) {
                        ExternalSystemNotificationManager.getInstance(project)
                                .processExternalProjectRefreshError(error, projectName, projectSystemId);
                        return;
                    }
                    final DataNode<ProjectData> projectDataDataNode = task.getExternalProject();
                    if (projectDataDataNode == null) {
                        return;
                    }

                    final Collection<DataNode<ExternalProject>> nodes = ExternalSystemApiUtil
                            .findAll(projectDataDataNode, KEY);
                    if (nodes.size() != 1) {
                        throw new IllegalArgumentException(
                                String.format("Expected to get a single external project but got %d: %s",
                                        nodes.size(), nodes));
                    }

                    ProjectRootManagerEx.getInstanceEx(myProject).mergeRootsChangesDuring(new Runnable() {
                        @Override
                        public void run() {
                            myProjectDataManager.importData(KEY, nodes, project, true);
                        }
                    });

                    result.set(true);
                }
            }.queue();

            return result.get();
        }
    });

    return result ? getRootExternalProject(projectSystemId, projectRootDir) : null;
}