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

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

Introduction

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

Prototype

int YES

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

Click Source Link

Usage

From source file:com.android.tools.idea.gradle.project.sync.hyperlink.StopGradleDaemonsHyperlink.java

License:Apache License

@Override
protected void execute(@NotNull Project project) {
    String title = "Stop Gradle Daemons";
    String message = "Stopping all Gradle daemons will terminate any running Gradle builds (e.g. from the command line).\n"
            + "This action will also restart the IDE.\n\n" + "Do you want to continue?";
    int answer = Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon());
    if (answer == Messages.YES) {
        stopAllGradleDaemonsAndRestart();
    }//from  www  . ja va  2s.  c  o m
}

From source file:com.android.tools.idea.gradle.project.sync.SdkSync.java

License:Apache License

@VisibleForTesting
void syncIdeAndProjectAndroidSdk(@NotNull LocalProperties localProperties,
        @NotNull FindValidSdkPathTask findSdkPathTask, @Nullable Project project) {
    if (localProperties.hasAndroidDirProperty()) {
        // if android.dir is specified, we don't sync SDKs. User is working with SDK sources.
        return;//w w w .jav  a 2s. c  o m
    }

    File ideAndroidSdkPath = myIdeSdks.getAndroidSdkPath();
    File projectAndroidSdkPath = localProperties.getAndroidSdkPath();

    if (ideAndroidSdkPath != null) {
        if (projectAndroidSdkPath == null) {
            // If we have the IDE default SDK and we don't have a project SDK, update local.properties with default SDK path and exit.
            setProjectSdk(localProperties, ideAndroidSdkPath);
            return;
        }
        ValidationResult validationResult = validateAndroidSdk(projectAndroidSdkPath, true);
        if (!validationResult.success) {
            // If we have the IDE default SDK and we don't have a valid project SDK, update local.properties with default SDK path and exit.
            invokeAndWaitIfNeeded(new Runnable() {
                @Override
                public void run() {
                    if (!ApplicationManager.getApplication().isUnitTestMode()) {
                        String error = validationResult.message;
                        if (isEmpty(error)) {
                            error = String.format(
                                    "The path \n'%1$s'\n" + "does not refer to a valid Android SDK.",
                                    projectAndroidSdkPath.getPath());
                        }
                        String format = "%1$s\n\nAndroid Studio will use this Android SDK instead:\n'%2$s'\nand will modify the project's local.properties file.";
                        Messages.showErrorDialog(String.format(format, error, ideAndroidSdkPath.getPath()),
                                ERROR_DIALOG_TITLE);
                    }
                    setProjectSdk(localProperties, ideAndroidSdkPath);
                }
            });
            return;
        }
    } else {
        if (projectAndroidSdkPath == null || !myIdeSdks.isValidAndroidSdkPath(projectAndroidSdkPath)) {
            // We don't have any SDK (IDE or project.)
            File selectedPath = findSdkPathTask.selectValidSdkPath();
            if (selectedPath == null) {
                throw new ExternalSystemException("Unable to continue until an Android SDK is specified");
            }
            setIdeSdk(localProperties, selectedPath);
            return;
        }

        // If we have a valid project SDK but we don't have IDE default SDK, update IDE with project SDK path and exit.
        setIdeSdk(localProperties, projectAndroidSdkPath);
        return;
    }

    if (!filesEqual(ideAndroidSdkPath, projectAndroidSdkPath)) {
        String msg = String.format("The project and Android Studio point to different Android SDKs.\n\n"
                + "Android Studio's default SDK is in:\n" + "%1$s\n\n"
                + "The project's SDK (specified in local.properties) is in:\n" + "%2$s\n\n"
                + "To keep results consistent between IDE and command line builds, only one path can be used. "
                + "Do you want to:\n\n"
                + "[1] Use Android Studio's default SDK (modifies the project's local.properties file.)\n\n"
                + "[2] Use the project's SDK (modifies Android Studio's default.)\n\n"
                + "Note that switching SDKs could cause compile errors if the selected SDK doesn't have the "
                + "necessary Android platforms or build tools.", ideAndroidSdkPath.getPath(),
                projectAndroidSdkPath.getPath());
        invokeAndWaitIfNeeded(new Runnable() {
            @Override
            public void run() {
                // We need to pass the project, so on Mac, the "Mac sheet" showing this message shows inside the IDE during UI tests, otherwise
                // it will show outside and the UI testing infrastructure cannot see it. It is overall a good practice to pass the project when
                // showing a message, to ensure that the message shows in the IDE instance containing the project.
                int result = MessageDialogBuilder.yesNo("Android SDK Manager", msg)
                        .yesText("Use Android Studio's SDK").noText("Use Project's SDK").project(project)
                        .show();
                if (result == Messages.YES) {
                    // Use Android Studio's SDK
                    setProjectSdk(localProperties, ideAndroidSdkPath);
                } else {
                    // Use project's SDK
                    setIdeSdk(localProperties, projectAndroidSdkPath);
                }
                if (isGuiTestingMode() && !getGuiTestSuiteState().isSkipSdkMerge()) {
                    mergeIfNeeded(projectAndroidSdkPath, ideAndroidSdkPath);
                }
            }
        });
    }
}

From source file:com.android.tools.idea.gradle.project.sync.SdkSync.java

License:Apache License

private static void mergeIfNeeded(@NotNull File sourceSdk, @NotNull File destSdk) {
    if (SdkMerger.hasMergeableContent(sourceSdk, destSdk)) {
        String msg = String.format(
                "The Android SDK at\n\n%1$s\n\nhas packages not in your project's SDK at\n\n%2$s\n\n"
                        + "Would you like to copy into the project SDK?",
                sourceSdk.getPath(), destSdk.getPath());
        int result = MessageDialogBuilder.yesNo("Merge SDKs", msg).yesText("Copy").noText("Do not copy").show();
        if (result == Messages.YES) {
            new Task.Backgroundable(null, "Merging Android SDKs", false) {
                @Override//from  w w  w. ja v  a2s. c o m
                public void run(@NotNull ProgressIndicator indicator) {
                    SdkMerger.mergeSdks(sourceSdk, destSdk, indicator);
                }
            }.queue();
        }
    }
}

From source file:com.android.tools.idea.gradle.service.notification.hyperlink.StopGradleDaemonsAndSyncHyperlink.java

License:Apache License

@Override
protected void execute(@NotNull Project project) {
    String title = "Stop Gradle Daemons";
    String message = "Stopping all Gradle daemons will terminate any running Gradle builds (e.g. from the command line.)\n\n"
            + "Do you want to continue?";
    int answer = Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon());
    if (answer == Messages.YES) {
        try {/* w w w .  j av a  2 s.c om*/
            GradleUtil.stopAllGradleDaemons(true);
            GradleProjectImporter.getInstance().requestProjectSync(project, null);
        } catch (IOException error) {
            Messages.showErrorDialog(
                    "Failed to stop Gradle daemons. Please run 'gradle --stop' from the command line.\n\n"
                            + "Cause:\n" + error.getMessage(),
                    title);
        }
    }
}

From source file:com.android.tools.idea.gradle.service.notification.hyperlink.StopGradleDaemonsHyperlink.java

License:Apache License

@Override
protected void execute(@NotNull Project project) {
    String title = "Stop Gradle Daemons";
    String message = "Stopping all Gradle daemons will terminate any running Gradle builds (e.g. from the command line).\n"
            + "This action will also restart the IDE.\n\n" + "Do you want to continue?";
    int answer = Messages.showYesNoDialog(project, message, title, Messages.getQuestionIcon());
    if (answer == Messages.YES) {
        try {/*from  w  ww . j  ava2 s  . c o m*/
            GradleUtil.stopAllGradleDaemons(true);
            ApplicationManager.getApplication().restart();
        } catch (IOException error) {
            Messages.showErrorDialog(
                    "Failed to stop Gradle daemons. Please run 'gradle --stop' from the command line.\n\n"
                            + "Cause:\n" + error.getMessage(),
                    title);
        }
    }
}

From source file:com.android.tools.idea.gradle.structure.editors.ModuleDependenciesPanel.java

License:Apache License

private String installRepositoryIfNeeded(String coordinateText) {
    GradleCoordinate gradleCoordinate = GradleCoordinate.parseCoordinateString(coordinateText);
    assert gradleCoordinate != null; // Only allowed to click ok when the string is valid.
    SupportLibrary supportLibrary = SupportLibrary.forGradleCoordinate(gradleCoordinate);

    if (!REVISION_ANY.equals(gradleCoordinate.getRevision()) || supportLibrary == null) {
        // No installation needed, or it's not a local repository.
        return coordinateText;
    }/*from   ww w  .  ja va  2  s  .  com*/
    String message = "Library " + gradleCoordinate.getArtifactId() + " is not installed. Install repository?";
    if (Messages.showYesNoDialog(myProject, message, "Install Repository",
            Messages.getQuestionIcon()) != Messages.YES) {
        // User cancelled installation.
        return null;
    }
    List<String> requested = Lists.newArrayList();
    SdkMavenRepository repository;
    if (coordinateText.startsWith("com.android.support")) {
        repository = SdkMavenRepository.ANDROID;
    } else if (coordinateText.startsWith("com.google.android")) {
        repository = SdkMavenRepository.GOOGLE;
    } else {
        // Not a local repository.
        assert false; // EXTRAS_REPOSITORY.containsKey() should have returned false.
        return coordinateText + ':' + REVISION_ANY;
    }
    requested.add(repository.getPackageId());
    ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(myProject, requested);
    if (dialog != null) {
        dialog.setTitle("Install Missing Components");
        if (dialog.showAndGet()) {
            return RepositoryUrlManager.get().getLibraryStringCoordinate(supportLibrary, true);
        }
    }

    // Installation wizard didn't complete - skip adding the dependency.
    return null;
}

From source file:com.android.tools.idea.gradle.util.GradleUtil.java

License:Apache License

public static void clearStoredGradleJvmArgs(@NotNull Project project) {
    GradleSettings settings = GradleSettings.getInstance(project);
    String existingJvmArgs = settings.getGradleVmOptions();
    settings.setGradleVmOptions(null);/*from  w w  w  .java 2  s.c o m*/
    if (!isEmptyOrSpaces(existingJvmArgs)) {
        invokeAndWaitIfNeeded((Runnable) () -> {
            String jvmArgs = existingJvmArgs.trim();
            String msg = String.format(
                    "Starting with version 1.3, Android Studio no longer supports IDE-specific Gradle JVM arguments.\n\n"
                            + "Android Studio will now remove any stored Gradle JVM arguments.\n\n"
                            + "Would you like to copy these JVM arguments:\n%1$s\n"
                            + "to the project's gradle.properties file?\n\n"
                            + "(Any existing JVM arguments in the gradle.properties file will be overwritten.)",
                    jvmArgs);

            int result = Messages.showYesNoDialog(project, msg, "Gradle Settings", getQuestionIcon());
            if (result == Messages.YES) {
                try {
                    GradleProperties gradleProperties = new GradleProperties(project);
                    gradleProperties.setJvmArgs(jvmArgs);
                    gradleProperties.save();
                } catch (IOException e) {
                    String err = String.format(
                            "Failed to copy JVM arguments '%1$s' to the project's gradle.properties file.",
                            existingJvmArgs);
                    LOG.info(err, e);

                    String cause = e.getMessage();
                    if (isNotEmpty(cause)) {
                        err += String.format("<br>\nCause: %1$s", cause);
                    }

                    AndroidGradleNotification.getInstance(project).showBalloon("Gradle Settings", err, ERROR);
                }
            } else {
                String text = String.format(
                        "JVM arguments<br>\n'%1$s'<br>\nwere not copied to the project's gradle.properties file.",
                        existingJvmArgs);
                AndroidGradleNotification.getInstance(project).showBalloon("Gradle Settings", text, WARNING);
            }
        });
    }
}

From source file:com.android.tools.idea.rendering.RenderErrorContributor.java

License:Apache License

private static void askAndRebuild(Project project) {
    final int r = Messages.showYesNoDialog(project,
            "You have to rebuild project to see the fixed preview. Would you like to do it?", "Rebuild Project",
            Messages.getQuestionIcon());
    if (r == Messages.YES) {
        CompilerManager.getInstance(project).rebuild(null);
    }//w  w w.  ja  v  a 2s  . co m
}

From source file:com.android.tools.idea.rendering.webp.ConvertFromWebpAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getProject();//from   ww w. j  a  va 2  s  . co m
    if (project == null) {
        return;
    }

    int answer = Messages.showYesNoCancelDialog(project, "Delete .webp files after saving as .png?", TITLE,
            null);
    if (answer == Messages.CANCEL) {
        return;
    }
    boolean delete = answer == Messages.YES;
    VirtualFile[] files = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    perform(project, files, delete);
}

From source file:com.android.tools.idea.run.ValidationUtil.java

License:Apache License

public static void promptAndQuickFixErrors(@NotNull Project project,
        @NotNull Collection<ValidationError> errors) throws ExecutionException {
    if (errors.isEmpty()) {
        return;// w  ww  . ja  v a  2  s.  co  m
    }

    for (ValidationError error : errors) {
        if (error.getQuickfix() != null) {
            if (Messages.showYesNoDialog(project, error.getMessage() + " - do you want to fix it?", "Quick fix",
                    null) == Messages.YES) {
                error.getQuickfix().run();
                continue;
            }
        }
        throw new ExecutionException(error.getMessage());
    }
}