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
@Deprecated
public static int showOkCancelDialog(String message,
        @Nls(capitalization = Nls.Capitalization.Title) String title, 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.avdmanager.InstallSystemImageAction.java

License:Apache License

@Override
public void actionPerformed(ActionEvent actionEvent) {
    String path = getPackagePath();
    assert path != null;
    List<String> requested = ImmutableList.of(path);
    int response = Messages.showOkCancelDialog("The corresponding system image is missing.\n\nDownload it now?",
            "Download System Image", Messages.getQuestionIcon());
    if (response != Messages.OK) {
        return;/*from w  ww . j a  v a  2s.  c  o  m*/
    }
    ModelWizardDialog sdkQuickfixWizard = SdkQuickfixUtils.createDialogForPaths(getProject(), requested);
    if (sdkQuickfixWizard != null) {
        sdkQuickfixWizard.show();
        refreshAvds();
    }
}

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.
 *///from   ww  w .j  a va2s.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.google.cloud.tools.intellij.appengine.cloud.AppEngineDeploymentRuntime.java

License:Apache License

@Override
public void undeploy(@NotNull final UndeploymentTaskCallback callback) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//  w  ww. j a v a2 s .c o  m
        public void run() {
            int doStop = Messages.showOkCancelDialog(
                    GctBundle.message("appengine.stop.modules.version.confirmation.message",
                            STOP_CONFIRMATION_URI_OPEN_TAG, STOP_CONFIRMATION_URI_CLOSE_TAG),
                    GctBundle.message("appengine.stop.modules.version.confirmation.title"), General.Warning);

            if (doStop == Messages.YES) {
                stop(callback);
            } else {
                callback.errorOccurred(GctBundle.message("appengine.stop.modules.version.canceled.message"));
            }
        }
    });
}

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

License:Apache License

/**
 * Exports IDEA settings.//  www.  ja  va  2s. 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  ww .j a  v  a2s . 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(//ww w .  j  a v a2  s  . c om
            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.
 *//*from  w  w w  .  ja  va 2s  .c  o m*/
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);
    }
}

From source file:com.google.idea.blaze.java.settings.BlazeJavaUserSettingsContributor.java

License:Open Source License

BlazeJavaUserSettingsContributor() {
    useJarCache = new JCheckBox();
    useJarCache.setText(String.format(
            "Use a local jar cache. More robust, but we can miss %s changes made outside the IDE.",
            Blaze.defaultBuildSystemName()));

    attachSourcesByDefault = new JCheckBox();
    attachSourcesByDefault.setSelected(false);
    attachSourcesByDefault//from  w  ww  . j  av  a2 s .  com
            .setText("Automatically attach sources on project sync (WARNING: increases index time by 100%+)");

    attachSourcesByDefault.addActionListener((event) -> {
        BlazeJavaUserSettings settings = BlazeJavaUserSettings.getInstance();
        if (attachSourcesByDefault.isSelected() && !settings.getAttachSourcesByDefault()) {
            int result = Messages.showOkCancelDialog(
                    "You are turning on source jars by default. " + "This setting increases indexing time by "
                            + ">100%, can cost ~1GB RAM, and will increase "
                            + "project reopen time significantly. " + "Are you sure you want to proceed?",
                    "Turn On Sources By Default?", null);
            if (result != Messages.OK) {
                attachSourcesByDefault.setSelected(false);
            }
        }
    });

    attachSourcesOnDemand = new JCheckBox();
    attachSourcesOnDemand.setSelected(false);
    attachSourcesOnDemand.setText("Automatically attach sources when you open decompiled source");

    components = ImmutableList.of(useJarCache, attachSourcesOnDemand, attachSourcesByDefault);
}

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

License:Apache License

public int showAlertWithOptions(@Nullable NotificationType type, @NotNull final String messageId,
        Object... arguments) {/*from   w  w w .j  a v a 2s . co  m*/
    String title = getTitle(messageId);
    String message = getMessage(messageId, arguments);
    // Make sure the Message is also placed inside the Log Console
    sendNotification(title, message, type);
    List<String> selections = new ArrayList<String>();
    for (int i = 0; i < 3; i++) {
        String selectionText = AEMBundle.message(messageId + "." + i);
        if (StringUtils.isNotBlank(selectionText)) {
            selections.add(selectionText);
        }
    }
    int ret = 0;
    if (selections.isEmpty()) {
        ret = Messages.showOkCancelDialog(message, title, getIcon(type));
    } else {
        String[] options = selections.toArray(new String[selections.size()]);
        ret = Messages.showDialog(myProject, message, title, options, 0, getIcon(type));
    }
    return ret;
}

From source file:com.intellij.execution.junit.JUnit4Framework.java

License:Apache License

@Override
@Nullable// w  ww  . jav a 2 s. c  om
protected PsiMethod findOrCreateSetUpMethod(PsiClass clazz) throws IncorrectOperationException {
    PsiMethod method = findSetUpMethod(clazz);
    if (method != null)
        return method;

    PsiManager manager = clazz.getManager();
    PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();

    method = createSetUpPatternMethod(factory);
    PsiMethod existingMethod = clazz.findMethodBySignature(method, false);
    if (existingMethod != null) {
        int exit = ApplicationManager.getApplication().isUnitTestMode() ? DialogWrapper.OK_EXIT_CODE
                : Messages.showOkCancelDialog(
                        "Method setUp already exist but is not annotated as @Before. Annotate?",
                        CommonBundle.getWarningTitle(), Messages.getWarningIcon());
        if (exit == DialogWrapper.OK_EXIT_CODE) {
            new AddAnnotationFix(JUnitUtil.BEFORE_ANNOTATION_NAME, existingMethod)
                    .invoke(existingMethod.getProject(), null, existingMethod.getContainingFile());
            return existingMethod;
        }
    }
    final PsiMethod testMethod = JUnitUtil.findFirstTestMethod(clazz);
    if (testMethod != null) {
        method = (PsiMethod) clazz.addBefore(method, testMethod);
    } else {
        method = (PsiMethod) clazz.add(method);
    }
    JavaCodeStyleManager.getInstance(manager.getProject()).shortenClassReferences(method);

    return method;
}