List of usage examples for com.intellij.openapi.ui Messages getQuestionIcon
@NotNull public static Icon getQuestionIcon()
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.j a v a 2 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.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 w w w . j a v a 2 s.c o m 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.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 ww . ja v a2s . c o m }
From source file:com.android.tools.idea.run.AndroidRunConfigurationBase.java
License:Apache License
@Override public RunProfileState getState(@NotNull final Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { validateBeforeRun(executor);/*from w w w .j av a 2s. com*/ final Module module = getConfigurationModule().getModule(); assert module != null : "Enforced by fatal validation check in checkConfiguration."; final AndroidFacet facet = AndroidFacet.getInstance(module); assert facet != null : "Enforced by fatal validation check in checkConfiguration."; Project project = env.getProject(); boolean forceColdswap = !InstantRunUtils.isInvokedViaHotswapAction(env); boolean couldHaveHotswapped = false; boolean debug = false; if (executor instanceof DefaultDebugExecutor) { if (!AndroidSdkUtils.activateDdmsIfNecessary(facet.getModule().getProject())) { throw new ExecutionException( "Unable to obtain debug bridge. Please check if there is a different tool using adb that is active."); } debug = true; } DeviceFutures deviceFutures = null; AndroidSessionInfo info = AndroidSessionInfo.findOldSession(project, null, getUniqueID()); // note: we look for this run config with any executor if (info != null && supportsInstantRun()) { // if there is an existing previous session, then see if we can detect devices to fast deploy to deviceFutures = getFastDeployDevices(executor, facet, info); // HACK: We also need to support re-run // In the case of re-run, we need to pick the devices from the previous run, but then terminate the app. // This call to destroyProcess doesn't really belong here in the overall flow, but everything else in the flow just fits // without any changes if we can recover the device first and then terminate the process. The alternative would be for // the ReRun action itself to pass in the device just like it happens for the restart device, but that has the complication // that the ReRun is now a global action and doesn't really know much details about each run (and doing that seems like a hack too.) if (InstantRunUtils.isReRun(env)) { killSession(info); info = null; } } if (info != null && deviceFutures == null) { // If we should not be fast deploying, but there is an existing session, then terminate those sessions. Otherwise, we might end up // with 2 active sessions of the same launch, especially if we first think we can do a fast deploy, then end up doing a full launch boolean continueLaunch = promptAndKillSession(executor, project, info); if (!continueLaunch) { return null; } } else if (info != null && forceColdswap) { // the user could have invoked the hotswap action in this scenario, but they chose to force a coldswap (by pressing run) couldHaveHotswapped = true; // forcibly kill app in case of run action (which forces a cold swap) // normally, installing the apk will force kill the app, but we need to forcibly kill it in the case that there were no changes killSession(info); } // If we are not fast deploying, then figure out (prompting user if needed) where to deploy if (deviceFutures == null) { DeployTarget deployTarget = getDeployTarget(executor, env, debug, facet); if (deployTarget == null) { return null; } DeployTargetState deployTargetState = getDeployTargetContext().getCurrentDeployTargetState(); if (deployTarget.hasCustomRunProfileState(executor)) { return deployTarget.getRunProfileState(executor, env, deployTargetState); } deviceFutures = deployTarget.getDevices(deployTargetState, facet, getDeviceCount(debug), debug, getUniqueID()); if (deviceFutures == null) { // The user deliberately canceled, or some error was encountered and exposed by the chooser. Quietly exit. return null; } } if (deviceFutures.get().isEmpty()) { throw new ExecutionException(AndroidBundle.message("deployment.target.not.found")); } ApplicationIdProvider applicationIdProvider = getApplicationIdProvider(facet); InstantRunContext instantRunContext = null; if (supportsInstantRun() && InstantRunSettings.isInstantRunEnabled()) { InstantRunGradleSupport gradleSupport = canInstantRun(module, deviceFutures.getDevices()); if (gradleSupport == TARGET_PLATFORM_NOT_INSTALLED) { AndroidVersion version = deviceFutures.getDevices().get(0).getVersion(); String message = AndroidBundle.message("instant.run.quickfix.missing.platform", SdkVersionInfo.getVersionWithCodename(version)); int result = Messages.showYesNoDialog(project, message, "Instant Run", "Install and Continue", // yes button "Proceed without Instant Run", // no button Messages.getQuestionIcon()); if (result == Messages.OK) { // if ok, install platform and continue with instant run ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, ImmutableList.of(DetailsTypes.getPlatformPath(version))); if (dialog == null) { LOG.warn( "Unable to get quick fix wizard to install missing platform required for instant run."); } else if (dialog.showAndGet()) { gradleSupport = SUPPORTED; } } } if (gradleSupport == SUPPORTED) { if (!AndroidEnableAdbServiceAction.isAdbServiceEnabled()) { throw new ExecutionException( "Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled."); } InstantRunUtils.setInstantRunEnabled(env, true); instantRunContext = InstantRunGradleUtils.createGradleProjectContext(facet); } else { InstantRunManager.LOG .warn("Instant Run enabled, but not doing an instant run build since: " + gradleSupport); String notificationText = gradleSupport.getUserNotification(); if (notificationText != null) { InstantRunNotificationTask.showNotification(env.getProject(), null, notificationText); } } } else { String msg = "Not using instant run for this launch: "; if (InstantRunSettings.isInstantRunEnabled()) { msg += getType().getDisplayName() + " does not support instant run"; } else { msg += "instant run is disabled"; } InstantRunManager.LOG.info(msg); } // Store the chosen target on the execution environment so before-run tasks can access it. AndroidRunConfigContext runConfigContext = new AndroidRunConfigContext(); env.putCopyableUserData(AndroidRunConfigContext.KEY, runConfigContext); runConfigContext.setTargetDevices(deviceFutures); runConfigContext .setSameExecutorAsPreviousSession(info != null && executor.getId().equals(info.getExecutorId())); runConfigContext.setCleanRerun(InstantRunUtils.isCleanReRun(env)); runConfigContext.setForceColdSwap(forceColdswap, couldHaveHotswapped); // Save the instant run context so that before-run task can access it env.putCopyableUserData(InstantRunContext.KEY, instantRunContext); if (debug) { String error = canDebug(deviceFutures, facet, module.getName()); if (error != null) { throw new ExecutionException(error); } } LaunchOptions launchOptions = getLaunchOptions().setDebug(debug).build(); ProcessHandler processHandler = null; if (info != null && info.getExecutorId().equals(executor.getId())) { processHandler = info.getProcessHandler(); } ApkProvider apkProvider = getApkProvider(facet, applicationIdProvider); LaunchTasksProviderFactory providerFactory = new AndroidLaunchTasksProviderFactory(this, env, facet, applicationIdProvider, apkProvider, deviceFutures, launchOptions, processHandler, instantRunContext); InstantRunStatsService.get(project).notifyBuildStarted(); return new AndroidRunState(env, getName(), module, applicationIdProvider, getConsoleProvider(), deviceFutures, providerFactory, processHandler); }
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 va 2s.c o 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.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 . j a 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; }/* www . 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.testartifacts.instrumented.AndroidTestRunConfiguration.java
License:Apache License
@NotNull @Override/*from w w w .j a v a 2s . co m*/ public List<ValidationError> checkConfiguration(@NotNull AndroidFacet facet) { List<ValidationError> errors = Lists.newArrayList(); Module module = facet.getModule(); JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject()); switch (TESTING_TYPE) { case TEST_ALL_IN_PACKAGE: final PsiPackage testPackage = facade.findPackage(PACKAGE_NAME); if (testPackage == null) { errors.add(ValidationError .warning(ExecutionBundle.message("package.does.not.exist.error.message", PACKAGE_NAME))); } break; case TEST_CLASS: PsiClass testClass = null; try { testClass = getConfigurationModule().checkModuleAndClassName(CLASS_NAME, ExecutionBundle.message("no.test.class.specified.error.text")); } catch (RuntimeConfigurationException e) { errors.add(ValidationError.fromException(e)); } if (testClass != null && !JUnitUtil.isTestClass(testClass)) { errors.add(ValidationError .warning(ExecutionBundle.message("class.isnt.test.class.error.message", CLASS_NAME))); } break; case TEST_METHOD: errors.addAll(checkTestMethod()); break; } if (INSTRUMENTATION_RUNNER_CLASS.length() > 0) { if (facade.findClass(INSTRUMENTATION_RUNNER_CLASS, module.getModuleWithDependenciesAndLibrariesScope(true)) == null) { errors.add(ValidationError .fatal(AndroidBundle.message("instrumentation.runner.class.not.specified.error"))); } } final AndroidFacetConfiguration configuration = facet.getConfiguration(); if (!facet.requiresAndroidModel() && !configuration.getState().PACK_TEST_CODE) { final int count = getTestSourceRootCount(module); if (count > 0) { final String shortMessage = "Test code not included into APK"; final String fixMessage = "Code and resources under test source " + (count > 1 ? "roots" : "root") + " aren't included into debug APK.\nWould you like to include them and recompile " + module.getName() + " module?" + "\n(You may change this option in Android facet settings later)"; Runnable quickFix = new Runnable() { @Override public void run() { final int result = Messages.showYesNoCancelDialog(getProject(), fixMessage, shortMessage, Messages.getQuestionIcon()); if (result == Messages.YES) { configuration.getState().PACK_TEST_CODE = true; } } }; errors.add(ValidationError.fatal(shortMessage, quickFix)); } } return errors; }
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;// ww w. java 2 s . c om } 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); } }
From source file:com.android.tools.idea.uibuilder.handlers.ViewEditorImpl.java
License:Apache License
@Override public void copyLayoutToMainModuleSourceSet(@NotNull String layout, @Language("XML") @NotNull String xml) { String message = "Do you want to copy layout " + layout + " to your main module source set?"; if (Messages.showYesNoDialog(myScreen.getModel().getProject(), message, "Copy Layout", Messages.getQuestionIcon()) == Messages.NO) { return;/*w w w . j a v a 2s .co m*/ } createResourceFile(FD_RES_LAYOUT, layout + DOT_XML, xml.getBytes(StandardCharsets.UTF_8)); }