List of usage examples for com.intellij.openapi.ui Messages showErrorDialog
public static void showErrorDialog(@Nullable Component component, String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title)
From source file:org.jetbrains.android.actions.CreateXmlResourceDialog.java
License:Apache License
@Override protected void doOKAction() { final String resourceName = getResourceName(); final String fileName = getFileName(); final List<String> dirNames = getDirNames(); final Module module = getModule(); if (resourceName.length() == 0) { Messages.showErrorDialog(myPanel, "Resource name is not specified", CommonBundle.getErrorTitle()); } else if (!AndroidResourceUtil.isCorrectAndroidResourceName(resourceName)) { Messages.showErrorDialog(myPanel, resourceName + " is not correct resource name", CommonBundle.getErrorTitle()); } else if (fileName.length() == 0) { Messages.showErrorDialog(myPanel, "File name is not specified", CommonBundle.getErrorTitle()); } else if (dirNames.size() == 0) { Messages.showErrorDialog(myPanel, "Directories are not selected", CommonBundle.getErrorTitle()); } else if (module == null) { Messages.showErrorDialog(myPanel, "Module is not specified", CommonBundle.getErrorTitle()); } else {//from w ww. j av a 2 s . c o m super.doOKAction(); } }
From source file:org.jetbrains.android.actions.RunAndroidSdkManagerAction.java
License:Apache License
@Override protected void doRunTool(@NotNull final Project project, @NotNull final String sdkPath) { ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override//from w ww .j ava2s . c o m public void run() { final String toolPath = sdkPath + File.separator + AndroidCommonUtils.toolPath(SdkConstants.androidCmdName()); GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(toolPath); commandLine.addParameter("sdk"); final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor(); try { if (AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForTime.getInstance(500)) == ExecutionStatus.TIMEOUT) { return; } } catch (ExecutionException e) { LOG.error(e); return; } final String message = processor.getMessage(); if (message.toLowerCase().contains("error")) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, "Cannot launch SDK manager.\nOutput:\n" + message, getName()); } }); } } }); }
From source file:org.jetbrains.android.compiler.AndroidCompileUtil.java
License:Apache License
public static void removeDuplicatingClasses(final Module module, @NotNull final String packageName, @NotNull String className, @Nullable File classFile, String sourceRootPath) { if (sourceRootPath == null) { return;//from ww w.j a v a 2s.c o m } VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByPath(sourceRootPath); if (sourceRoot == null) { return; } final Project project = module.getProject(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final String interfaceQualifiedName = packageName + '.' + className; PsiClass[] classes = facade.findClasses(interfaceQualifiedName, GlobalSearchScope.moduleScope(module)); final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex(); for (PsiClass c : classes) { PsiFile psiFile = c.getContainingFile(); if (className.equals(FileUtil.getNameWithoutExtension(psiFile.getName()))) { VirtualFile virtualFile = psiFile.getVirtualFile(); if (virtualFile != null && Comparing.equal(projectFileIndex.getSourceRootForFile(virtualFile), sourceRoot)) { final String path = virtualFile.getPath(); final File f = new File(path); if (!FileUtil.filesEqual(f, classFile) && f.exists()) { if (f.delete()) { virtualFile.refresh(true, false); } else { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, "Can't delete file " + path, CommonBundle.getErrorTitle()); } }, project.getDisposed()); } } } } } }
From source file:org.jetbrains.android.exportSignedPackage.ExportSignedPackageWizard.java
License:Apache License
private void showErrorInDispatchThread(final String message) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override/* w w w . ja v a 2 s . co m*/ public void run() { Messages.showErrorDialog(getProject(), "Error: " + message, CommonBundle.getErrorTitle()); } }, ModalityState.NON_MODAL); }
From source file:org.jetbrains.android.facet.AndroidFacet.java
License:Apache License
private boolean reloadAvds(AvdManager manager) { try {/*from w w w . ja v a 2 s. c o m*/ MessageBuildingSdkLog log = new MessageBuildingSdkLog(); manager.reloadAvds(log); if (log.getErrorMessage().length() > 0) { Messages.showErrorDialog(getModule().getProject(), AndroidBundle.message("cant.load.avds.error.prefix") + ' ' + log.getErrorMessage(), CommonBundle.getErrorTitle()); } return true; } catch (AndroidLocation.AndroidLocationException e) { Messages.showErrorDialog(getModule().getProject(), AndroidBundle.message("cant.load.avds.error"), CommonBundle.getErrorTitle()); } return false; }
From source file:org.jetbrains.android.inspections.lint.MoveToDebugManifestQuickFix.java
License:Apache License
@Override public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) { final XmlAttribute attribute = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class); if (attribute != null) { XmlTag parent = attribute.getParent(); if (parent != null && parent.getName().equals(TAG_USES_PERMISSION)) { Module module = getModule(parent); assert MOCK_LOCATION_PERMISSION.equals(parent.getAttributeValue(ATTR_NAME, ANDROID_URI)); parent.delete();/*from w ww .j ava2 s .c o m*/ if (module != null) { AndroidFacet facet = AndroidFacet.getInstance(module); if (facet != null) { VirtualFile mainManifest = facet.getMainIdeaSourceProvider().getManifestFile(); IdeaAndroidProject project = facet.getIdeaAndroidProject(); if (project != null && mainManifest != null && mainManifest.getParent() != null && mainManifest.getParent().getParent() != null) { final VirtualFile src = mainManifest.getParent().getParent(); for (BuildTypeContainer container : project.getDelegate().getBuildTypes()) { BuildType buildType = container.getBuildType(); if (buildType.isDebuggable()) { addManifest(module, src, buildType.getName()); return; } } Messages.showErrorDialog(module.getProject(), "Did not find a debug build type", "Move Permission"); } } } } } }
From source file:org.jetbrains.android.intentions.AndroidAddStringResourceAction.java
License:Apache License
protected static void doInvoke(Project project, Editor editor, PsiFile file, @Nullable String resName, PsiElement element) {//from w ww. java 2 s. c o m String value = getStringLiteralValue(project, element, file); assert value != null; final AndroidFacet facet = AndroidFacet.getInstance(file); assert facet != null; final String aPackage = getPackage(facet); if (aPackage == null) { Messages.showErrorDialog(project, AndroidBundle.message("package.not.found.error"), CommonBundle.getErrorTitle()); return; } if (resName == null) { final CreateXmlResourceDialog dialog = new CreateXmlResourceDialog(facet.getModule(), ResourceType.STRING, null, value, false); dialog.setTitle("Extract String Resource"); dialog.show(); if (!dialog.isOK()) { return; } final Module module = dialog.getModule(); if (module == null) { return; } resName = dialog.getResourceName(); if (!AndroidResourceUtil.createValueResource(module, resName, ResourceType.STRING, dialog.getFileName(), dialog.getDirNames(), value)) { return; } } else { assert ApplicationManager.getApplication().isUnitTestMode(); AndroidResourceUtil.createValueResource(facet.getModule(), resName, ResourceType.STRING, "strings.xml", Collections.singletonList("values"), value); } if (file instanceof PsiJavaFile) { createJavaResourceReference(facet.getModule(), editor, file, element, aPackage, resName, ResourceType.STRING.getName()); } else { final XmlAttribute attribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class); if (attribute != null) { attribute.setValue( ResourceValue.referenceTo('@', null, ResourceType.STRING.getName(), resName).toString()); } } PsiDocumentManager.getInstance(project).commitAllDocuments(); UndoUtil.markPsiFileForUndo(file); }
From source file:org.jetbrains.android.logcat.AndroidLogcatUtil.java
License:Apache License
public static void clearLogcat(final Project project, IDevice device) { try {//from ww w. jav a 2s .co m AndroidUtils.executeCommandOnDevice(device, "logcat -c", new LoggingReceiver(LOG), false); } catch (final Exception e) { LOG.info(e); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, "Error: " + e.getMessage(), AndroidBundle.message("android.logcat.error.dialog.title")); } }); } }
From source file:org.jetbrains.android.newProject.AndroidModuleBuilder.java
License:Apache License
private boolean createProjectByAndroidTool(final VirtualFile contentRoot, final VirtualFile sourceRoot, final AndroidFacet facet) { final Module module = facet.getModule(); Sdk sdk = getAndroidSdkForModule(module); if (sdk == null) { return true; }//from ww w . j a v a 2s .c o m AndroidPlatform platform = AndroidPlatform.parse(sdk); if (platform == null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { Messages.showErrorDialog(module.getProject(), "Cannot parse Android SDK", CommonBundle.getErrorTitle()); } return true; } final IAndroidTarget target = platform.getTarget(); final String androidToolPath = platform.getSdkData().getLocation() + File.separator + AndroidCommonUtils.toolPath(SdkConstants.androidCmdName()); if (!new File(androidToolPath).exists()) { return false; } final GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setExePath(FileUtil.toSystemDependentName(androidToolPath)); commandLine.addParameter("create"); switch (myProjectType) { case APPLICATION: commandLine.addParameter("project"); break; case LIBRARY: commandLine.addParameter("lib-project"); break; case TEST: commandLine.addParameter("test-project"); break; } commandLine.addParameters("--name"); commandLine.addParameter(getAntProjectName(module.getName())); commandLine.addParameters("--path"); File tempContentRoot; try { tempContentRoot = FileUtil.createTempDirectory("android_temp_content_root", "tmp"); } catch (IOException e) { LOG.error(e); return false; } final String targetDirectoryPath = tempContentRoot.getPath(); commandLine.addParameter(FileUtil.toSystemDependentName(targetDirectoryPath)); if (myProjectType == ProjectType.APPLICATION || myProjectType == ProjectType.LIBRARY) { String apiLevel = target.hashString(); commandLine.addParameter("--target"); commandLine.addParameter(apiLevel); commandLine.addParameter("--package"); commandLine.addParameter(myPackageName); } if (myProjectType == ProjectType.APPLICATION) { commandLine.addParameter("--activity"); commandLine.addParameter(myActivityName); } else if (myProjectType == ProjectType.TEST) { final AndroidFacet testedFacet = AndroidFacet.getInstance(myTestedModule); final VirtualFile moduleDir = testedFacet != null ? AndroidRootUtil.getMainContentRoot(testedFacet) : null; if (moduleDir == null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { Messages.showErrorDialog(module.getProject(), AndroidBundle .message("android.wizard.cannot.find.main.content.root.error", module.getName()), CommonBundle.getErrorTitle()); } return true; } commandLine.addParameter("--main"); commandLine.addParameter(FileUtil.toSystemDependentName(moduleDir.getPath())); } final File finalTempContentRoot = tempContentRoot; ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { final Project project = module.getProject(); final String androidToolOutput; final boolean androidToolSuccess; try { final Pair<String, Boolean> pair = runAndroidTool(commandLine); androidToolOutput = pair.getFirst(); androidToolSuccess = pair.getSecond(); copyGeneratedAndroidProject(finalTempContentRoot, contentRoot, sourceRoot); } finally { FileUtil.delete(finalTempContentRoot); } StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() { @Override public void run() { FileDocumentManager.getInstance().saveAllDocuments(); } }); VfsUtil.markDirtyAndRefresh(false, true, true, contentRoot); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (project.isDisposed() || module.isDisposed()) { return; } final boolean manifestGenerated = contentRoot.findChild(FN_ANDROID_MANIFEST_XML) != null; final String projectNotGeneratedError = "The project wasn't generated by 'android' tool."; if (androidToolOutput != null && androidToolOutput.length() > 0 && (!manifestGenerated || !androidToolSuccess || androidToolOutput.trim().toLowerCase().startsWith("error:"))) { final ConsoleViewContentType contentType = androidToolSuccess ? ConsoleViewContentType.NORMAL_OUTPUT : ConsoleViewContentType.ERROR_OUTPUT; AndroidUtils.activateConsoleToolWindow(project, new Runnable() { @Override public void run() { if (!manifestGenerated) { AndroidUtils.printMessageToConsole(project, projectNotGeneratedError, ConsoleViewContentType.ERROR_OUTPUT); } AndroidUtils.printMessageToConsole(project, androidToolOutput, contentType); } }); } else if (!manifestGenerated) { AndroidUtils.activateConsoleToolWindow(project, new Runnable() { @Override public void run() { AndroidUtils.printMessageToConsole(project, projectNotGeneratedError, ConsoleViewContentType.ERROR_OUTPUT); } }); } if (!manifestGenerated) { return; } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { if (project.isDisposed()) { return; } if (myProjectType == ProjectType.APPLICATION) { assignApplicationName(facet); configureManifest(facet, target); createChildDirectoryIfNotExist(project, contentRoot, SdkConstants.FD_ASSETS); createChildDirectoryIfNotExist(project, contentRoot, SdkConstants.FD_NATIVE_LIBS); } else if (myProjectType == ProjectType.LIBRARY && myPackageName != null) { final String[] dirs = myPackageName.split("\\."); VirtualFile file = sourceRoot; for (String dir : dirs) { if (file == null || dir.length() == 0) { break; } final VirtualFile childDir = file.findChild(dir); file = childDir != null ? childDir : file.createChildDirectory(project, dir); } } } catch (IOException e) { LOG.error(e); } } }); ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { if (project.isDisposed() || facet.getModule().isDisposed()) { return; } if (myTargetSelectionMode != null) { if (myProjectType == ProjectType.APPLICATION) { addRunConfiguration(facet, myTargetSelectionMode, myPreferredAvd); } else if (myProjectType == ProjectType.TEST) { addTestRunConfiguration(facet, myTargetSelectionMode, myPreferredAvd); } } } }); new ReformatCodeProcessor(project, module, false).run(); } }); } }); return true; }
From source file:org.jetbrains.android.newProject.AndroidModuleBuilder.java
License:Apache License
private void createManifestFileAndAntFiles(Project project, VirtualFile contentRoot, Module module) { VirtualFile existingManifestFile = contentRoot.findChild(FN_ANDROID_MANIFEST_XML); if (existingManifestFile != null) { return;/*from w ww. j a va 2 s . c om*/ } try { AndroidFileTemplateProvider.createFromTemplate(project, contentRoot, AndroidFileTemplateProvider.ANDROID_MANIFEST_TEMPLATE, FN_ANDROID_MANIFEST_XML); Sdk sdk = getAndroidSdkForModule(module); if (sdk == null) return; AndroidPlatform platform = AndroidPlatform.parse(sdk); if (platform == null) { Messages.showErrorDialog(project, "Cannot parse Android SDK: '" + SdkConstants.FN_PROJECT_PROPERTIES + "' won't be generated", CommonBundle.getErrorTitle()); return; } Properties properties = FileTemplateManager.getInstance().getDefaultProperties(project); properties.setProperty("TARGET", platform.getTarget().hashString()); AndroidFileTemplateProvider.createFromTemplate(project, contentRoot, AndroidFileTemplateProvider.DEFAULT_PROPERTIES_TEMPLATE, SdkConstants.FN_PROJECT_PROPERTIES, properties); } catch (Exception e) { LOG.error(e); } }