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.sdk.wizard.SdkQuickfixUtils.java
License:Apache License
private static AndroidSdkHandler getSdkHandler() { AndroidSdkData data = AndroidSdks.getInstance().tryToChooseAndroidSdk(); if (data == null) { String title = "SDK Problem"; String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>"; Messages.showErrorDialog(msg, title); return null; }/* w ww . j a v a 2 s .c om*/ return data.getSdkHandler(); }
From source file:com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.java
License:Apache License
@VisibleForTesting @Nullable/* w ww .ja va 2 s . c om*/ static ModelWizardDialog createDialog(@Nullable Project project, @Nullable Component parent, @Nullable Collection<String> requestedPaths, @Nullable Collection<UpdatablePackage> requestedPackages, @Nullable Collection<LocalPackage> requestedUninstalls, @Nullable AndroidSdkHandler sdkHandler, boolean backgroundable) { if (sdkHandler == null) { return null; } RepoManager mgr = sdkHandler.getSdkManager(REPO_LOGGER); if (mgr.getLocalPath() == null) { String title = "SDK Problem"; String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>"; Messages.showErrorDialog(msg, title); return null; } List<String> unknownPaths = new ArrayList<>(); List<UpdatablePackage> resolvedPackages; mgr.loadSynchronously(0, new StudioLoggerProgressIndicator(SdkQuickfixUtils.class), new StudioDownloader(), StudioSettingsController.getInstance()); RepositoryPackages packages = mgr.getPackages(); if (requestedPackages == null) { requestedPackages = new ArrayList<>(); } requestedPackages.addAll(lookupPaths(requestedPaths, packages, unknownPaths)); try { resolvedPackages = resolve(requestedPackages, packages); } catch (PackageResolutionException e) { Messages.showErrorDialog(e.getMessage(), "Error Resolving Packages"); return null; } Set<LocalPackage> resolvedUninstalls = new HashSet<>(); if (requestedUninstalls != null) { resolvedUninstalls.addAll(requestedUninstalls); // We don't want to uninstall something required by a package we're installing resolvedPackages.forEach(updatable -> resolvedUninstalls.remove(updatable.getLocal())); } List<UpdatablePackage> unavailableDownloads = Lists.newArrayList(); verifyAvailability(resolvedPackages, unavailableDownloads); // If there were requests we didn't understand or can't download, show an error. if (!unknownPaths.isEmpty() || !unavailableDownloads.isEmpty()) { String title = "Packages Unavailable"; HtmlBuilder builder = new HtmlBuilder(); builder.openHtmlBody() .add(String.format("%1$s packages are not available for download!", resolvedPackages.isEmpty() ? "All" : "Some")) .newline().newline().add("The following packages are not available:").beginList(); for (UpdatablePackage p : unavailableDownloads) { builder.listItem().add(p.getRepresentative().getDisplayName()); } for (String p : unknownPaths) { builder.listItem().add("Package id " + p); } builder.endList().closeHtmlBody(); Messages.showErrorDialog(builder.getHtml(), title); } // If everything was removed, don't continue. if (resolvedPackages.isEmpty() && resolvedUninstalls.isEmpty()) { return null; } List<RemotePackage> installRequests = resolvedPackages.stream().map(UpdatablePackage::getRemote) .collect(Collectors.toList()); ModelWizard.Builder wizardBuilder = new ModelWizard.Builder(); wizardBuilder .addStep(new LicenseAgreementStep(new LicenseAgreementModel(mgr.getLocalPath()), installRequests)); InstallSelectedPackagesStep installStep = new InstallSelectedPackagesStep(resolvedPackages, resolvedUninstalls, sdkHandler, backgroundable); wizardBuilder.addStep(installStep); ModelWizard wizard = wizardBuilder.build(); String title = "SDK Quickfix Installation"; return new StudioWizardDialogBuilder(wizard, title, parent).setProject(project) .setModalityType(DialogWrapper.IdeModalityType.IDE) .setCancellationPolicy(ModelWizardDialog.CancellationPolicy.CAN_CANCEL_UNTIL_CAN_FINISH).build(); }
From source file:com.android.tools.idea.structure.AndroidModuleStructureConfigurable.java
License:Apache License
@Override public void apply() throws ConfigurationException { super.apply(); try {//from w w w. j a v a2 s. co m GradleProjectImporter.getInstance().reImportProject(myProject, null); } catch (ConfigurationException ex) { Messages.showErrorDialog(ex.getMessage(), ex.getTitle()); LOG.info(ex); } }
From source file:com.android.tools.idea.templates.Template.java
License:Apache License
/** * Calculate the correct version of the support library and generate the corresponding maven URL * @param minApiLevel the minimum api level specified by the template (-1 if no minApiLevel specified) * @return a maven url for the android support library *//*from w ww.j ava 2 s . co m*/ @Nullable private String getSupportMavenUrl(int minApiLevel) { String suffix = SUFFIX_V4; if (minApiLevel >= 13) { suffix = SUFFIX_V13; } // Read the support repository and find the latest version available String sdkLocation = AndroidSdkUtils.tryToChooseAndroidSdk().getLocation(); String path = FileUtil .toSystemIndependentName(sdkLocation + SUPPORT_REPOSITORY_PATH + suffix + MAVEN_METADATA_PATH); File supportMetadataFile = new File(path); if (!supportMetadataFile.exists()) { Messages.showErrorDialog("You must install the Android Support Library though the SDK Manager.", "Support Repository Not Found"); return null; } String version = getLatestVersionFromMavenMetadata(supportMetadataFile); return SUPPORT_BASE_URL + suffix + ":" + version; }
From source file:com.android.tools.idea.ui.TextFieldWithLaunchBrowserButton.java
License:Apache License
public TextFieldWithLaunchBrowserButton(String url) { myUrl = url;/* w w w. java2s .c o m*/ addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { Desktop.getDesktop().browse(URI.create(myUrl)); } else { Messages.showErrorDialog("Please visit \n" + myUrl + "\n to retrieve this value", "Could Not Open Web Browser"); } } catch (IOException error) { LOG.error(error); } } }); }
From source file:com.android.tools.idea.welcome.install.FirstRunWizardDefaults.java
License:Apache License
/** * @return Default Android SDK install location */// w w w . j a v a 2 s .c om @NotNull private static File getDefaultSdkLocation() { String path = System.getenv(SdkConstants.ANDROID_HOME_ENV); if (Strings.isNullOrEmpty(path)) { String userHome = System.getProperty("user.home"); if (SystemInfo.isWindows) { path = FileUtil.join(userHome, "AppData", "Local", "Android", "Sdk"); } else if (SystemInfo.isMac) { path = FileUtil.join(userHome, "Library", "Android", "sdk"); } else if (SystemInfo.isLinux) { path = FileUtil.join(userHome, "Android", "Sdk"); } else { Messages.showErrorDialog( "Your OS is not officially supported.\n" + "You can continue, but it is likely you will encounter further problems.", "Unsupported OS"); path = ""; } } return new File(path); }
From source file:com.android.tools.idea.wizard.NewAndroidModulePath.java
License:Apache License
@Override public void createModule() { // For historical reasons, this class handles project creation for both Java and Android module templates if (myProject != null) { try {//www. ja va 2 s .co m myWizardState.populateDirectoryParameters(); File projectRoot = new File(myProject.getBasePath()); File moduleRoot = new File(projectRoot, myWizardState.getString(FormFactorUtils.ATTR_MODULE_NAME)); // TODO: handle return type of "mkdirs". projectRoot.mkdirs(); myWizardState.updateParameters(); Template template = myWizardState.myTemplate; template.render(projectRoot, moduleRoot, myWizardState.myParameters, myProject); if (NewModuleWizardState.isAndroidTemplate(template.getMetadata())) { if (myAssetSetStep.isStepVisible() && myWizardState.getBoolean(TemplateMetadata.ATTR_CREATE_ICONS)) { AssetStudioAssetGenerator assetGenerator = new AssetStudioAssetGenerator(myWizardState); assetGenerator.outputImagesIntoDefaultVariant(moduleRoot); } if (myActivityTemplateParameterStep.isStepVisible() && myWizardState.getBoolean(NewModuleWizardState.ATTR_CREATE_ACTIVITY)) { TemplateWizardState activityTemplateState = myWizardState.getActivityTemplateState(); activityTemplateState.populateRelativePackage(null); Template activityTemplate = activityTemplateState.getTemplate(); assert activityTemplate != null; activityTemplate.render(moduleRoot, moduleRoot, activityTemplateState.myParameters, myProject); } } } catch (Exception e) { Messages.showErrorDialog(e.getMessage(), "New Module"); LOG.error(e); } } }
From source file:com.android.tools.idea.wizard.NewModuleWizardDynamic.java
License:Apache License
@Override public void init() { if (!AndroidSdkUtils.isAndroidSdkAvailable() || !TemplateManager.templatesAreValid()) { String title = "SDK problem"; String msg = "<html>Your Android SDK is missing, out of date, or is missing templates.<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>"; Messages.showErrorDialog(msg, title); return;//from w w w . j a v a2 s.c o m } addPaths(); ConfigureAndroidProjectPath.putSdkDependentParams(getState()); initState(); super.init(); }
From source file:com.android.tools.idea.wizard.NewProjectWizard.java
License:Apache License
@Override protected void init() { if (!TemplateManager.templatesAreValid()) { String title = "SDK problem"; String msg = "<html>Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later.<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>"; Messages.showErrorDialog(msg, title); throw new IllegalStateException(msg); }//from w w w. ja v a2s .com myWizardState = new NewProjectWizardState(); myWizardState.convertApisToInt(); myWizardState.put(TemplateMetadata.ATTR_GRADLE_VERSION, TemplateMetadata.GRADLE_VERSION); myWizardState.put(TemplateMetadata.ATTR_GRADLE_PLUGIN_VERSION, TemplateMetadata.GRADLE_PLUGIN_VERSION); myWizardState.put(TemplateMetadata.ATTR_V4_SUPPORT_LIBRARY_VERSION, TemplateMetadata.V4_SUPPORT_LIBRARY_VERSION); myConfigureAndroidModuleStep = new ConfigureAndroidModuleStep(myWizardState, myProject, NewProjectSidePanel, this); myLauncherIconStep = new LauncherIconStep(myWizardState.getLauncherIconState(), myProject, NewProjectSidePanel, this); myChooseActivityStep = new ChooseTemplateStep(myWizardState.getActivityTemplateState(), CATEGORY_ACTIVITIES, myProject, NewProjectSidePanel, this, null); myActivityParameterStep = new TemplateParameterStep(myWizardState.getActivityTemplateState(), myProject, NewProjectSidePanel, this); mySteps.add(myConfigureAndroidModuleStep); mySteps.add(myLauncherIconStep); mySteps.add(myChooseActivityStep); mySteps.add(myActivityParameterStep); myInitializationComplete = true; super.init(); }
From source file:com.android.tools.idea.wizard.NewProjectWizard.java
License:Apache License
public void createProject() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override/*from w w w . j a v a 2 s . c om*/ public void run() { try { myWizardState.populateDirectoryParameters(); String projectName = (String) myWizardState.get(NewProjectWizardState.ATTR_MODULE_NAME); File projectRoot = new File( (String) myWizardState.get(NewProjectWizardState.ATTR_PROJECT_LOCATION)); File moduleRoot = new File(projectRoot, projectName); projectRoot.mkdirs(); createGradleWrapper(projectRoot); Sdk sdk = getSdk((Integer) myWizardState.get(ATTR_BUILD_API)); LocalProperties.createFile(new File(projectRoot, FN_LOCAL_PROPERTIES), sdk); if ((Boolean) myWizardState.get(TemplateMetadata.ATTR_CREATE_ICONS)) { myWizardState.getLauncherIconState().outputImages(moduleRoot); } myWizardState.updateParameters(); myWizardState.myTemplate.render(projectRoot, moduleRoot, myWizardState.myParameters); if ((Boolean) myWizardState.get(NewProjectWizardState.ATTR_CREATE_ACTIVITY)) { myWizardState.getActivityTemplateState().getTemplate().render(moduleRoot, moduleRoot, myWizardState.getActivityTemplateState().myParameters); } else { // Ensure that at least the Java source directory exists. We could create other directories but this is the most used. // TODO: We should perhaps instantiate this from the Freemarker template, but trying to use the copy command to copy // empty directories is problematic, and we don't have a primitive command to create a directory. File javaSrcDir = new File(moduleRoot, JAVA_SRC_PATH); File packageDir = new File(javaSrcDir, ((String) myWizardState.get(ATTR_PACKAGE_NAME)).replace('.', File.separatorChar)); packageDir.mkdirs(); } GradleProjectImporter projectImporter = GradleProjectImporter.getInstance(); projectImporter.importProject(projectName, projectRoot, sdk, null); } catch (Exception e) { String title; if (e instanceof ConfigurationException) { title = ((ConfigurationException) e).getTitle(); } else { title = "New Project Wizard"; } Messages.showErrorDialog(e.getMessage(), title); LOG.error(e); } } }); }