List of usage examples for com.intellij.openapi.ui Messages showErrorDialog
public static void showErrorDialog(String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title)
From source file:com.android.tools.idea.gradle.customizer.AndroidSdkModuleCustomizer.java
License:Apache License
private static void showErrorDialog(@NotNull String msg) { Messages.showErrorDialog(msg, "Android SDK Configuration"); }
From source file:com.android.tools.idea.gradle.eclipse.AdtImportLocationStep.java
License:Apache License
@Override public boolean validate() throws ConfigurationException { WizardContext context = getWizardContext(); GradleImport importer = AdtImportProvider.getImporter(context); if (importer != null) { List<String> errors = importer.getErrors(); if (!errors.isEmpty()) { throw new ConfigurationException(errors.get(0)); }//from w w w . ja v a2s . co m } // The following code is based on similar code in com.intellij.ide.util.newProjectWizard.ProjectNameStep String projectFileDirectory = getProjectFileDirectory(); if (projectFileDirectory.length() == 0) { throw new ConfigurationException( String.format("Enter %1$s file location", context.getPresentationName())); } boolean shouldPromptCreation = myIsPathChangedByUser; if (!ProjectWizardUtil.createDirectoryIfNotExists( String.format("The %1$s file directory\n", context.getPresentationName()), projectFileDirectory, shouldPromptCreation)) { return false; } boolean shouldContinue = true; File projectFile = new File(getProjectFileDirectory()); String title = "New Project"; if (projectFile.isFile()) { shouldContinue = false; String message = String.format("%s exists and is a file.\nPlease specify a different project location", projectFile.getAbsolutePath()); Messages.showErrorDialog(message, title); } else if (projectFile.isDirectory()) { File[] files = projectFile.listFiles(); if (files != null && files.length > 0) { String message = String.format( "%1$s folder already exists and is not empty.\nIts content may be overwritten.\nContinue?", projectFile.getAbsolutePath()); int answer = Messages.showYesNoDialog(message, title, Messages.getQuestionIcon()); shouldContinue = answer == 0; } } return shouldContinue; }
From source file:com.android.tools.idea.gradle.project.AndroidGradleProjectComponent.java
License:Apache License
public void configureGradleProject(boolean reImportProject) { if (myDisposable != null) { return;/*from ww w.j av a2 s . com*/ } myDisposable = new Disposable() { @Override public void dispose() { } }; listenForProjectChanges(myProject, myDisposable); GradleImportNotificationListener.attachToManager(); Projects.ensureExternalBuildIsEnabledForGradleProject(myProject); if (reImportProject) { Projects.setProjectBuildAction(myProject, Projects.BuildAction.SOURCE_GEN); try { // Prevent IDEA from refreshing project. We want to do it ourselves. myProject.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE); GradleProjectImporter.getInstance().reImportProject(myProject); } catch (ConfigurationException e) { Messages.showErrorDialog(e.getMessage(), e.getTitle()); LOG.info(e); } } }
From source file:com.android.tools.idea.gradle.project.SdkSync.java
License:Apache License
@VisibleForTesting static void syncIdeAndProjectAndroidSdks(@NotNull final LocalProperties localProperties, @NotNull FindValidSdkPathTask findSdkPathTask) { if (localProperties.hasAndroidDirProperty()) { // if android.dir is specified, we don't sync SDKs. User is working with SDK sources. return;// ww w .ja v a 2s. c o m } final File ideAndroidSdkPath = IdeSdks.getAndroidSdkPath(); final 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; } final 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 || !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)) { final 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() { int result = MessageDialogBuilder.yesNo("Android SDK Manager", msg) .yesText("Use Android Studio's SDK").noText("Use Project's SDK").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
@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;/*from w ww .j ava2 s. 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.service.notification.errors.NdkLocationNotFoundErrorHandler.java
License:Apache License
private static boolean setNdkPath(@NotNull Project project, @Nullable String ndkPath) { LocalProperties localProperties;//from w w w . j a v a2s . c o m try { localProperties = new LocalProperties(project); } catch (IOException e) { String msg = String.format("Unable to read local.properties file of Project '%1$s':\n%2$s", project.getName(), e.getMessage()); Messages.showErrorDialog(msg, ERROR_TITLE); return false; } try { localProperties.setAndroidNdkPath(ndkPath == null ? null : new File(ndkPath)); localProperties.save(); } catch (IOException e) { String msg = String.format("Unable to save local.properties file of Project '%1$s: %2$s", localProperties.getFilePath().getPath(), e.getMessage()); Messages.showErrorDialog(msg, ERROR_TITLE); return false; } return true; }
From source file:com.android.tools.idea.gradle.service.notification.FixGradleVersionInWrapperHyperlink.java
License:Apache License
@Override protected void execute(@NotNull Project project) { String gradleVersion = GradleUtil.GRADLE_MINIMUM_VERSION; try {/* ww w.j a v a2s . co m*/ GradleUtil.updateGradleDistributionUrl(gradleVersion, myWrapperPropertiesFile); try { GradleProjectImporter.getInstance().reImportProject(project, null); } catch (ConfigurationException e) { Messages.showErrorDialog(e.getMessage(), e.getTitle()); Logger.getInstance(FixGradleVersionInWrapperHyperlink.class).info(e); } } catch (IOException e) { String msg = String.format("Unable to update Gradle wrapper to use Gradle %1$s\n", gradleVersion); msg += e.getMessage(); Messages.showErrorDialog(project, msg, "Quick Fix Failed"); } }
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 {/*from w w w .j ava2s .c o m*/ 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 {/* w w w . ja v a2 s . co 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.IdeSdksConfigurable.java
License:Apache License
private void createNdkDownloadLink() { myNdkDownloadHyperlinkLabel = new HyperlinkLabel(); myNdkDownloadHyperlinkLabel.setHyperlinkText("", "Download", " Android NDK."); myNdkDownloadHyperlinkLabel.addHyperlinkListener(new HyperlinkAdapter() { @Override// ww w.j ava2 s . c o m protected void hyperlinkActivated(HyperlinkEvent e) { if (validateAndroidSdkPath() != null) { Messages.showErrorDialog(getContentPanel(), "Please select a valid SDK before downloading the NDK."); return; } List<String> requested = ImmutableList.of(FD_NDK); ModelWizardDialog dialog = createDialogForPaths(myWholePanel, requested, false); if (dialog != null && dialog.showAndGet()) { File ndk = IdeSdks.getInstance().getAndroidNdkPath(); if (ndk != null) { myNdkLocationTextField.setText(ndk.getPath()); } validateState(); } } }); }