List of usage examples for com.intellij.openapi.ui Messages showYesNoDialog
@YesNoResult public static int showYesNoDialog(@NotNull Component parent, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon)
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 {// ww w. j a v a 2 s. 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 {//from w w w .java 2 s .c om 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; }//w w w .j a v a 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 ww w .j a v a 2 s .com*/ 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); }//from w w w .jav a 2 s.c o m }
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 w w . j av a2s . c o 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()); } }
From source file:com.android.tools.idea.structure.AndroidModuleStructureConfigurable.java
License:Apache License
@Override protected boolean removeObject(Object editableObject) { if (editableObject != null && editableObject instanceof String) { final String moduleName = (String) editableObject; if (Iterables.contains(mySettingsFile.getModules(), moduleName)) { // TODO: This applies changes immediately. We need to save up changes and not apply them until the user confirms the dialog. // In the old dialog this is handled by the fact that we have a ModifiableRootModel that queues changes. // TODO: If removing a module, remove any dependencies on that module in other modules. Perhaps we should show this to the user // in the confirmation dialog, and ask if dependencies should be cleaned up? String question;//from w w w . ja v a2 s .c o m if (Iterables.size(mySettingsFile.getModules()) == 1) { question = ProjectBundle.message("module.remove.last.confirmation"); } else { question = ProjectBundle.message("module.remove.confirmation", moduleName); } int result = Messages.showYesNoDialog(myProject, question, ProjectBundle.message("module.remove.confirmation.title"), Messages.getQuestionIcon()); if (result != 0) { return false; } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { mySettingsFile.removeModule(moduleName); } }); return true; } } return false; }
From source file:com.android.tools.idea.structure.gradle.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. if (!REVISION_ANY.equals(gradleCoordinate.getFullRevision()) || !RepositoryUrlManager.EXTRAS_REPOSITORY.containsKey(gradleCoordinate.getArtifactId())) { // No installation needed, or it's not a local repository. return coordinateText; }// ww w.ja v a 2 s . c om 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<IPkgDesc> 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.getPackageDescription()); SdkQuickfixWizard wizard = new SdkQuickfixWizard(myProject, null, requested); wizard.init(); wizard.setTitle("Install Missing Components"); if (wizard.showAndGet()) { return RepositoryUrlManager.get().getLibraryCoordinate(gradleCoordinate.getArtifactId()); } else { // Installation wizard didn't complete - skip adding the dependency. return null; } }
From source file:com.android.tools.idea.structure.services.view.DeveloperServicePanel.java
License:Apache License
public DeveloperServicePanel(@NotNull DeveloperService service) { super(new BorderLayout()); myService = service;//from w ww .ja v a 2 s . c o m ServiceContext context = service.getContext(); DeveloperServiceMetadata developerServiceMetadata = service.getMetadata(); initializeHeaderPanel(developerServiceMetadata); myDetailsPanel.add(service.getPanel()); initializeFooterPanel(developerServiceMetadata); final SelectedProperty enabledCheckboxSelected = new SelectedProperty(myEnabledCheckbox); myBindings.bind(new VisibleProperty(myDetailsPanel), enabledCheckboxSelected.and(not(context.installed()))); // This definition might be modified from the user interacting with the service earlier but not // yet committing to install it. myBindings.bind(enabledCheckboxSelected, context.installed().or(context.modified())); myEnabledCheckbox.setName("enableService"); enabledCheckboxSelected.addListener(new InvalidationListener() { @Override public void onInvalidated(@NotNull ObservableValue<?> sender) { if (enabledCheckboxSelected.get()) { if (!myService.getContext().installed().get()) { // User just selected a service which was previously uninstalled. This means we are // ready to edit it. myService.getContext().beginEditing(); } } else { if (myService.getContext().installed().get()) { // User just deselected a service which was previous installed String message = String.format(DELETE_SERVICE_MESSAGE, myService.getMetadata().getName(), Joiner.on('\n').join(myService.getMetadata().getDependencies())); int answer = Messages.showYesNoDialog(myService.getModule().getProject(), message, DELETE_SERVICE_TITLE, null); if (answer == Messages.YES) { myService.uninstall(); } else { enabledCheckboxSelected.set(true); } } else { // User just deselected a service they were editing but hadn't installed yet myService.getContext().cancelEditing(); } } } }); add(myRootPanel); }
From source file:com.android.tools.idea.uibuilder.handlers.ViewEditorImpl.java
License:Apache License
@Override public void copyVectorAssetToMainModuleSourceSet(@NotNull String asset) { Project project = myScreen.getModel().getProject(); String message = "Do you want to copy vector asset " + asset + " to your main module source set?"; if (Messages.showYesNoDialog(project, message, "Copy Vector Asset", Messages.getQuestionIcon()) == Messages.NO) { return;/*from w w w . j a v a 2 s. co m*/ } try (InputStream in = GraphicGenerator.class.getClassLoader() .getResourceAsStream(MaterialDesignIcons.getPathForBasename(asset))) { createResourceFile(FD_RES_DRAWABLE, asset + DOT_XML, ByteStreams.toByteArray(in)); } catch (IOException exception) { Logger.getInstance(ViewEditorImpl.class).warn(exception); } }