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

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

Introduction

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

Prototype

int OK

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

Click Source Link

Usage

From source file:com.android.tools.idea.run.editor.DeployTargetPickerDialog.java

License:Apache License

/**
 * Check the AVDs for missing system images and offer to download them.
 * @return true if the devices are able to launch, false if the user cancelled.
 *///  w  w w .  j a v a  2  s . co  m
private boolean canLaunchDevices(@NotNull List<AndroidDevice> devices) {
    Set<String> requiredPackages = Sets.newHashSet();
    for (AndroidDevice device : devices) {
        if (device instanceof LaunchableAndroidDevice) {
            LaunchableAndroidDevice avd = (LaunchableAndroidDevice) device;
            AvdInfo info = avd.getAvdInfo();
            if (AvdManagerConnection.isSystemImageDownloadProblem(info.getStatus())) {
                requiredPackages.add(AvdManagerConnection.getRequiredSystemImagePath(info));
            }
        }
    }
    if (requiredPackages.isEmpty()) {
        return true;
    }

    String title;
    StringBuilder message = new StringBuilder();
    if (requiredPackages.size() == 1) {
        title = "Download System Image";
        message.append("The system image: ").append(Iterables.getOnlyElement(requiredPackages))
                .append(" is missing.\n\n");
        message.append("Download it now?");
    } else {
        title = "Download System Images";
        message.append("The following system images are missing:\n");
        for (String packageName : requiredPackages) {
            message.append(packageName).append("\n");
        }
        message.append("\nDownload them now?");
    }
    int response = Messages.showOkCancelDialog(message.toString(), title, Messages.getQuestionIcon());
    if (response != Messages.OK) {
        return false;
    }
    ModelWizardDialog sdkQuickfixWizard = SdkQuickfixUtils
            .createDialogForPaths(myFacet.getModule().getProject(), requiredPackages);
    if (sdkQuickfixWizard == null) {
        return false;
    }
    sdkQuickfixWizard.show();
    myDevicePicker.refreshAvds(null);
    if (!sdkQuickfixWizard.isOK()) {
        return false;
    }
    AvdManagerConnection manager = AvdManagerConnection.getDefaultAvdManagerConnection();
    for (AndroidDevice device : devices) {
        if (device instanceof LaunchableAndroidDevice) {
            LaunchableAndroidDevice avd = (LaunchableAndroidDevice) device;
            AvdInfo info = avd.getAvdInfo();
            String problem;
            try {
                AvdInfo reloadedAvdInfo = manager.reloadAvd(info);
                problem = reloadedAvdInfo.getErrorMessage();
            } catch (AndroidLocation.AndroidLocationException e) {
                problem = "AVD cannot be loaded";
            }
            if (problem != null) {
                Messages.showErrorDialog(myFacet.getModule().getProject(), problem, "Emulator Launch Failed");
                return false;
            }
        }
    }
    return true;
}

From source file:com.android.tools.idea.updater.configure.SdkUpdaterConfigurable.java

License:Apache License

private static boolean confirmChange(HtmlBuilder message) {
    String[] options = { Messages.OK_BUTTON, Messages.CANCEL_BUTTON };
    Icon icon = AllIcons.General.Warning;

    // I would use showOkCancelDialog but Mac sheet panels do not gracefully handle long messages and their buttons can display offscreen
    return Messages.showIdeaMessageDialog(null, message.getHtml(), "Confirm Change", options, 0, icon,
            null) == Messages.OK;
}

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 ava 2  s  .co  m
    return button == Messages.OK;
}

From source file:com.goide.actions.tool.GoFmtCheckinFactory.java

License:Apache License

@Override
@Nullable/*from w w  w  .  j  a v  a2 s.  c o  m*/
public CheckinHandler createHandler(@Nonnull CheckinProjectPanel panel, @Nonnull CommitContext commitContext) {
    if (!ModuleExtensionHelper.getInstance(panel.getProject()).hasModuleExtension(GoModuleExtension.class)) {
        return null;
    }
    return new CheckinHandler() {
        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            JCheckBox checkBox = new JCheckBox("Go fmt");
            return new RefreshableOnComponent() {
                @Override
                @Nonnull
                public JComponent getComponent() {
                    JPanel panel = new JPanel(new BorderLayout());
                    panel.add(checkBox, BorderLayout.WEST);
                    return panel;
                }

                @Override
                public void refresh() {
                }

                @Override
                public void saveState() {
                    PropertiesComponent.getInstance(panel.getProject()).setValue(GO_FMT,
                            Boolean.toString(checkBox.isSelected()));
                }

                @Override
                public void restoreState() {
                    checkBox.setSelected(enabled(panel));
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor,
                PairConsumer<Object, Object> additionalDataConsumer) {
            if (enabled(panel)) {
                Ref<Boolean> success = Ref.create(true);
                FileDocumentManager.getInstance().saveAllDocuments();
                for (PsiFile file : getPsiFiles()) {
                    VirtualFile virtualFile = file.getVirtualFile();
                    new GoFmtFileAction().doSomething(virtualFile, ModuleUtilCore.findModuleForPsiElement(file),
                            file.getProject(), "Go fmt", true, result -> {
                                if (!result)
                                    success.set(false);
                            });
                }
                if (!success.get()) {
                    return showErrorMessage(executor);
                }
            }
            return super.beforeCheckin();
        }

        @Nonnull
        private ReturnResult showErrorMessage(@Nullable CommitExecutor executor) {
            String[] buttons = new String[] { "&Details...", commitButtonMessage(executor, panel),
                    CommonBundle.getCancelButtonText() };
            int answer = Messages.showDialog(panel.getProject(),
                    "<html><body>GoFmt returned non-zero code on some of the files.<br/>"
                            + "Would you like to commit anyway?</body></html>\n",
                    "Go Fmt", null, buttons, 0, 1, UIUtil.getWarningIcon());
            if (answer == Messages.OK) {
                return ReturnResult.CLOSE_WINDOW;
            }
            if (answer == Messages.NO) {
                return ReturnResult.COMMIT;
            }
            return ReturnResult.CANCEL;
        }

        @Nonnull
        private List<PsiFile> getPsiFiles() {
            Collection<VirtualFile> files = panel.getVirtualFiles();
            List<PsiFile> psiFiles = ContainerUtil.newArrayList();
            PsiManager manager = PsiManager.getInstance(panel.getProject());
            for (VirtualFile file : files) {
                PsiFile psiFile = manager.findFile(file);
                if (psiFile instanceof GoFile) {
                    psiFiles.add(psiFile);
                }
            }
            return psiFiles;
        }
    };
}

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 ww  .  j  ava 2s .  co 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.google.cloud.tools.intellij.debugger.CloudDebuggerRunner.java

License:Apache License

private void ensureSingleDebugSession(Project project) throws RunCanceledByUserException {

    List<CloudDebugProcessState> backgroundSessions = getBackgroundDebugStates(project);
    if (backgroundSessions.size() > 0) {
        for (CloudDebugProcessState cdps : backgroundSessions) {
            cdps.setListenInBackground(false);
        }//from  ww  w.j  av  a2 s .  co m
    }

    List<CloudDebugProcess> activeDebugProcesses = getActiveDebugProcesses(project);
    if (activeDebugProcesses.size() > 0) {
        int result = Messages.showOkCancelDialog(project,
                GctBundle.getString("clouddebug.stop.and.create.new.session"),
                GctBundle.getString("clouddebug.message.title"), GoogleCloudToolsIcons.STACKDRIVER_DEBUGGER);
        if (result == Messages.OK) {
            for (CloudDebugProcess cdb : activeDebugProcesses) {
                cdb.getProcessHandler().detachProcess();
            }
        } else {
            throw new RunCanceledByUserException();
        }
    }
}

From source file:com.google.cloud.tools.intellij.settings.ExportSettings.java

License:Apache License

/**
 * Exports IDEA settings.// w  ww. ja va2s . c om
 */
public static void doExport(String path) {
    final Set<ExportableComponent> exportableComponents = new HashSet<ExportableComponent>(Arrays
            .asList(ApplicationManager.getApplication().getComponents(ExportableApplicationComponent.class)));
    exportableComponents.addAll(
            ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent.class));

    if (exportableComponents.isEmpty()) {
        return;
    }

    Set<File> exportFiles = new HashSet<File>();
    for (final ExportableComponent markedComponent : exportableComponents) {
        ContainerUtil.addAll(exportFiles, markedComponent.getExportFiles());
    }

    ApplicationManager.getApplication().saveSettings();

    final File saveFile = new File(path);
    try {
        if (saveFile.exists()) {
            final int ret = Messages.showOkCancelDialog(
                    IdeBundle.message("prompt.overwrite.settings.file",
                            FileUtil.toSystemDependentName(saveFile.getPath())),
                    IdeBundle.message("title.file.already.exists"), Messages.getWarningIcon());
            if (ret != Messages.OK) {
                return;
            }
        }

        final JarOutputStream output = new JarOutputStream(new FileOutputStream(saveFile));
        try {
            final File configPath = new File(PathManager.getConfigPath());
            final Set<String> writtenItemRelativePaths = new HashSet<String>();
            for (File file : exportFiles) {
                final String rPath = FileUtil.getRelativePath(configPath, file);
                assert rPath != null;
                final String relativePath = FileUtil.toSystemIndependentName(rPath);
                if (file.exists()) {
                    ZipUtil.addFileOrDirRecursively(output, saveFile, file, relativePath, null,
                            writtenItemRelativePaths);
                }
            }

            exportInstalledPlugins(saveFile, output, writtenItemRelativePaths);

            final File magicFile = new File(FileUtil.getTempDirectory(), SETTINGS_JAR_MARKER);
            FileUtil.createIfDoesntExist(magicFile);
            magicFile.deleteOnExit();
            ZipUtil.addFileToZip(output, magicFile, SETTINGS_JAR_MARKER, writtenItemRelativePaths, null);
        } finally {
            output.close();
        }
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.writing.settings", e1.toString()),
                IdeBundle.message("title.error.writing.file"));
    }

}

From source file:com.google.cloud.tools.intellij.settings.ImportSettings.java

License:Apache License

/**
 * Parse and update the IDEA settings in the jar at <code>path</code>. Note: This function might
 * require a restart of the application.
 *
 * @param path The location of the jar with the new IDEA settings.
 *//*from w w  w  .  jav  a 2 s.c  o  m*/
public static void doImport(String path) {
    final File saveFile = new File(path);
    ZipFile saveZipFile = null;
    try {
        if (!saveFile.exists()) {
            Messages.showErrorDialog(IdeBundle.message("error.cannot.find.file", presentableFileName(saveFile)),
                    DIALOG_TITLE);
            return;
        }

        // What is this file used for?
        saveZipFile = new ZipFile(saveFile);
        final ZipEntry magicEntry = saveZipFile.getEntry(SETTINGS_JAR_MARKER);
        if (magicEntry == null) {
            Messages.showErrorDialog(
                    "The file " + presentableFileName(saveFile) + " contains no settings to import",
                    DIALOG_TITLE);
            return;
        }

        final List<ExportableComponent> registeredComponents = new ArrayList<ExportableComponent>(Arrays.asList(
                ApplicationManager.getApplication().getComponents(ExportableApplicationComponent.class)));
        registeredComponents.addAll(ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT,
                ExportableComponent.class));

        List<ExportableComponent> storedComponents = getComponentsStored(saveFile, registeredComponents);

        Set<String> relativeNamesToExtract = new HashSet<String>();
        for (final ExportableComponent exportableComponent : storedComponents) {
            final File[] exportFiles = exportableComponent.getExportFiles();
            for (File exportFile : exportFiles) {
                final File configPath = new File(PathManager.getConfigPath());
                final String rPath = FileUtil.getRelativePath(configPath, exportFile);
                assert rPath != null;
                final String relativePath = FileUtil.toSystemIndependentName(rPath);
                relativeNamesToExtract.add(relativePath);
            }
        }

        relativeNamesToExtract.add(PluginManager.INSTALLED_TXT);

        final File tempFile = new File(PathManager.getPluginTempPath() + "/" + saveFile.getName());
        FileUtil.copy(saveFile, tempFile);
        File outDir = new File(PathManager.getConfigPath());
        final ImportSettingsFilenameFilter filenameFilter = new ImportSettingsFilenameFilter(
                relativeNamesToExtract);
        StartupActionScriptManager.ActionCommand unzip = new StartupActionScriptManager.UnzipCommand(tempFile,
                outDir, filenameFilter);
        StartupActionScriptManager.addActionCommand(unzip);

        // remove temp file
        StartupActionScriptManager.ActionCommand deleteTemp = new StartupActionScriptManager.DeleteCommand(
                tempFile);
        StartupActionScriptManager.addActionCommand(deleteTemp);

        UpdateSettings.getInstance().forceCheckForUpdateAfterRestart();

        String key = ApplicationManager.getApplication().isRestartCapable()
                ? "message.settings.imported.successfully.restart"
                : "message.settings.imported.successfully";
        final int ret = Messages.showOkCancelDialog(
                IdeBundle.message(key, ApplicationNamesInfo.getInstance().getProductName(),
                        ApplicationNamesInfo.getInstance().getFullProductName()),
                IdeBundle.message("title.restart.needed"), Messages.getQuestionIcon());
        if (ret == Messages.OK) {
            ((ApplicationEx) ApplicationManager.getApplication()).restart(true);
        }
    } catch (ZipException e1) {
        Messages.showErrorDialog(
                "Error reading file " + presentableFileName(saveFile) + ".\\nThere was " + e1.getMessage(),
                DIALOG_TITLE);
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.reading.settings.file.2",
                presentableFileName(saveFile), e1.getMessage()), DIALOG_TITLE);
    } finally {
        try {
            if (saveZipFile != null) {
                saveZipFile.close();
            }
        } catch (IOException e1) {
            Messages.showErrorDialog(GctBundle.message("settings.error.closing.file",
                    presentableFileName(saveFile), e1.getMessage()), DIALOG_TITLE);
        }
    }
}

From source file:com.google.gct.idea.settings.ExportSettings.java

License:Apache License

public static void doExport(String path) {
    final Set<ExportableComponent> exportableComponents = new HashSet<ExportableComponent>(Arrays
            .asList(ApplicationManager.getApplication().getComponents(ExportableApplicationComponent.class)));
    exportableComponents.addAll(/*from   w  w w . j a  v  a2s  . co  m*/
            ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent.class));

    if (exportableComponents.isEmpty()) {
        return;
    }

    Set<File> exportFiles = new HashSet<File>();
    for (final ExportableComponent markedComponent : exportableComponents) {
        ContainerUtil.addAll(exportFiles, markedComponent.getExportFiles());
    }

    ApplicationManager.getApplication().saveSettings();

    final File saveFile = new File(path);
    try {
        if (saveFile.exists()) {
            final int ret = Messages.showOkCancelDialog(
                    IdeBundle.message("prompt.overwrite.settings.file",
                            FileUtil.toSystemDependentName(saveFile.getPath())),
                    IdeBundle.message("title.file.already.exists"), Messages.getWarningIcon());
            if (ret != Messages.OK)
                return;
        }

        final JarOutputStream output = new JarOutputStream(new FileOutputStream(saveFile));
        try {
            final File configPath = new File(PathManager.getConfigPath());
            final HashSet<String> writtenItemRelativePaths = new HashSet<String>();
            for (File file : exportFiles) {
                final String rPath = FileUtil.getRelativePath(configPath, file);
                assert rPath != null;
                final String relativePath = FileUtil.toSystemIndependentName(rPath);
                if (file.exists()) {
                    ZipUtil.addFileOrDirRecursively(output, saveFile, file, relativePath, null,
                            writtenItemRelativePaths);
                }
            }

            exportInstalledPlugins(saveFile, output, writtenItemRelativePaths);

            final File magicFile = new File(FileUtil.getTempDirectory(), SETTINGS_JAR_MARKER);
            FileUtil.createIfDoesntExist(magicFile);
            magicFile.deleteOnExit();
            ZipUtil.addFileToZip(output, magicFile, SETTINGS_JAR_MARKER, writtenItemRelativePaths, null);
        } finally {
            output.close();
        }
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.writing.settings", e1.toString()),
                IdeBundle.message("title.error.writing.file"));
    }

}

From source file:com.google.gct.idea.settings.ImportSettings.java

License:Apache License

/**
 * Parse and update the IDEA settings in the jar at <code>path</code>.
 * Note: This function might require a restart of the application.
 * @param path The location of the jar with the new IDEA settings.
 */// w  ww.  j  a va2s.c  om
public static void doImport(String path) {
    final File saveFile = new File(path);
    try {
        if (!saveFile.exists()) {
            Messages.showErrorDialog(IdeBundle.message("error.cannot.find.file", presentableFileName(saveFile)),
                    DIALOG_TITLE);
            return;
        }

        // What is this file used for?
        final ZipEntry magicEntry = new ZipFile(saveFile).getEntry(SETTINGS_JAR_MARKER);
        if (magicEntry == null) {
            Messages.showErrorDialog(
                    "The file " + presentableFileName(saveFile) + " contains no settings to import",
                    DIALOG_TITLE);
            return;
        }

        final ArrayList<ExportableComponent> registeredComponents = new ArrayList<ExportableComponent>(
                Arrays.asList(ApplicationManager.getApplication()
                        .getComponents(ExportableApplicationComponent.class)));
        registeredComponents.addAll(ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT,
                ExportableComponent.class));

        List<ExportableComponent> storedComponents = getComponentsStored(saveFile, registeredComponents);

        Set<String> relativeNamesToExtract = new HashSet<String>();
        for (final ExportableComponent aComponent : storedComponents) {
            final File[] exportFiles = aComponent.getExportFiles();
            for (File exportFile : exportFiles) {
                final File configPath = new File(PathManager.getConfigPath());
                final String rPath = FileUtil.getRelativePath(configPath, exportFile);
                assert rPath != null;
                final String relativePath = FileUtil.toSystemIndependentName(rPath);
                relativeNamesToExtract.add(relativePath);
            }
        }

        relativeNamesToExtract.add(PluginManager.INSTALLED_TXT);

        final File tempFile = new File(PathManager.getPluginTempPath() + "/" + saveFile.getName());
        FileUtil.copy(saveFile, tempFile);
        File outDir = new File(PathManager.getConfigPath());
        final ImportSettingsFilenameFilter filenameFilter = new ImportSettingsFilenameFilter(
                relativeNamesToExtract);
        StartupActionScriptManager.ActionCommand unzip = new StartupActionScriptManager.UnzipCommand(tempFile,
                outDir, filenameFilter);
        StartupActionScriptManager.addActionCommand(unzip);

        // remove temp file
        StartupActionScriptManager.ActionCommand deleteTemp = new StartupActionScriptManager.DeleteCommand(
                tempFile);
        StartupActionScriptManager.addActionCommand(deleteTemp);

        UpdateSettings.getInstance().forceCheckForUpdateAfterRestart();

        String key = ApplicationManager.getApplication().isRestartCapable()
                ? "message.settings.imported.successfully.restart"
                : "message.settings.imported.successfully";
        final int ret = Messages.showOkCancelDialog(
                IdeBundle.message(key, ApplicationNamesInfo.getInstance().getProductName(),
                        ApplicationNamesInfo.getInstance().getFullProductName()),
                IdeBundle.message("title.restart.needed"), Messages.getQuestionIcon());
        if (ret == Messages.OK) {
            ((ApplicationEx) ApplicationManager.getApplication()).restart(true);
        }
    } catch (ZipException e1) {
        Messages.showErrorDialog(
                "Error reading file " + presentableFileName(saveFile) + ".\\nThere was " + e1.getMessage(),
                DIALOG_TITLE);
    } catch (IOException e1) {
        Messages.showErrorDialog(IdeBundle.message("error.reading.settings.file.2",
                presentableFileName(saveFile), e1.getMessage()), DIALOG_TITLE);
    }
}