List of usage examples for com.intellij.openapi.ui Messages showOkCancelDialog
@OkCancelResult @Deprecated public static int showOkCancelDialog(@NotNull Component parent, String message, @Nls(capitalization = Nls.Capitalization.Title) String title, Icon icon)
From source file:com.intellij.codeInspection.i18n.JavaI18nizeQuickFixDialog.java
License:Apache License
public static boolean isAvailable(PsiFile file) { final Project project = file.getProject(); final String title = CodeInsightBundle.message("i18nize.dialog.error.jdk.title"); try {/*w w w . j a v a 2 s .c o m*/ return ResourceBundleManager.getManager(file) != null; } catch (ResourceBundleManager.ResourceBundleNotFoundException e) { final IntentionAction fix = e.getFix(); if (fix != null) { if (Messages.showOkCancelDialog(project, e.getMessage(), title, Messages.getErrorIcon()) == OK_EXIT_CODE) { try { fix.invoke(project, null, file); return false; } catch (IncorrectOperationException e1) { LOG.error(e1); } } } Messages.showErrorDialog(project, e.getMessage(), title); return false; } }
From source file:com.intellij.codeInspection.inferNullity.InferNullityAnnotationsAction.java
License:Apache License
@Override protected void analyze(@NotNull final Project project, final AnalysisScope scope) { final ProgressManager progressManager = ProgressManager.getInstance(); final int totalFiles = scope.getFileCount(); final Set<Module> modulesWithoutAnnotations = new HashSet<Module>(); final Set<Module> modulesWithLL = new HashSet<Module>(); if (!progressManager.runProcessWithProgressSynchronously(new Runnable() { @Override//from w w w . j a va2s . c o m public void run() { scope.accept(new PsiElementVisitor() { private int myFileCount = 0; final private Set<Module> processed = new HashSet<Module>(); @Override public void visitFile(PsiFile file) { myFileCount++; final ProgressIndicator progressIndicator = ProgressManager.getInstance() .getProgressIndicator(); if (progressIndicator != null) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile != null) { progressIndicator .setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project)); } progressIndicator.setFraction(((double) myFileCount) / totalFiles); } final Module module = ModuleUtil.findModuleForPsiElement(file); if (module != null && !processed.contains(module)) { processed.add(module); if (JavaPsiFacade.getInstance(project).findClass( NullableNotNullManager.getInstance(project).getDefaultNullable(), GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)) == null) { modulesWithoutAnnotations.add(module); } if (PsiUtil.getLanguageLevel(file).compareTo(LanguageLevel.JDK_1_5) < 0) { modulesWithLL.add(module); } } } }); } }, "Check applicability...", true, project)) { return; } if (!modulesWithLL.isEmpty()) { Messages.showErrorDialog(project, "Infer Nullity Annotations requires the project language level be set to 1.5 or greater.", INFER_NULLITY_ANNOTATIONS); return; } if (!modulesWithoutAnnotations.isEmpty()) { final Library annotationsLib = LibraryUtil .findLibraryByClass(NullableNotNullManager.getInstance(project).getDefaultNullable(), project); if (annotationsLib != null) { String message = "Module" + (modulesWithoutAnnotations.size() == 1 ? " " : "s "); message += StringUtil.join(modulesWithoutAnnotations, new Function<Module, String>() { @Override public String fun(Module module) { return module.getName(); } }, ", "); message += (modulesWithoutAnnotations.size() == 1 ? " doesn't" : " don't"); message += " refer to the existing '" + annotationsLib.getName() + "' library with IDEA nullity annotations. Would you like to add the dependenc"; message += (modulesWithoutAnnotations.size() == 1 ? "y" : "ies") + " now?"; if (Messages.showOkCancelDialog(project, message, INFER_NULLITY_ANNOTATIONS, Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (Module module : modulesWithoutAnnotations) { ModuleRootModificationUtil.addDependency(module, annotationsLib); } } }); } } else if (Messages.showOkCancelDialog(project, "Infer Nullity Annotations requires that the nullity annotations" + " be available in all your project sources.\n\nYou will need to add annotations.jar as a library. " + "It is possible to configure custom jar in e.g. Constant Conditions & Exceptions inspection or use JetBrains annotations available in installation. " + " IntelliJ IDEA nullity annotations are freely usable and redistributable under the Apache 2.0 license. Would you like to do it now?", INFER_NULLITY_ANNOTATIONS, Messages.getErrorIcon()) == DialogWrapper.OK_EXIT_CODE) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { final LocateLibraryDialog dialog = new LocateLibraryDialog( modulesWithoutAnnotations.iterator().next(), PathManager.getLibPath(), "annotations.jar", QuickFixBundle.message("add.library.annotations.description")); dialog.show(); if (dialog.isOK()) { final String path = dialog.getResultingLibraryPath(); new WriteCommandAction(project) { @Override protected void run(final Result result) throws Throwable { for (Module module : modulesWithoutAnnotations) { OrderEntryFix.addBundledJarToRoots(project, null, module, null, AnnotationUtil.NOT_NULL, path); } } }.execute(); } } }); } return; } if (scope.checkScopeWritable(project)) return; PsiDocumentManager.getInstance(project).commitAllDocuments(); final NullityInferrer inferrer = new NullityInferrer(myAnnotateLocalVariablesCb.isSelected(), project); final PsiManager psiManager = PsiManager.getInstance(project); if (!progressManager.runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { scope.accept(new PsiElementVisitor() { int myFileCount = 0; @Override public void visitFile(final PsiFile file) { myFileCount++; final VirtualFile virtualFile = file.getVirtualFile(); final FileViewProvider viewProvider = psiManager.findViewProvider(virtualFile); final Document document = viewProvider == null ? null : viewProvider.getDocument(); if (document == null || virtualFile.getFileType().isBinary()) return; //do not inspect binary files final ProgressIndicator progressIndicator = ProgressManager.getInstance() .getProgressIndicator(); if (progressIndicator != null) { if (virtualFile != null) { progressIndicator .setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project)); } progressIndicator.setFraction(((double) myFileCount) / totalFiles); } if (file instanceof PsiJavaFile) { inferrer.collect(file); } } }); } }, INFER_NULLITY_ANNOTATIONS, true, project)) { return; } final Runnable applyRunnable = new Runnable() { @Override public void run() { new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) { @Override protected void run(Result result) throws Throwable { if (!inferrer.nothingFoundMessage(project)) { final SequentialModalProgressTask progressTask = new SequentialModalProgressTask( project, INFER_NULLITY_ANNOTATIONS, false); progressTask.setMinIterationTime(200); progressTask.setTask(new AnnotateTask(project, inferrer, progressTask)); ProgressManager.getInstance().run(progressTask); } } }.execute(); } }; SwingUtilities.invokeLater(applyRunnable); }
From source file:com.intellij.compiler.impl.CompilerUtil.java
License:Apache License
public static boolean askUserToContinueWithNoClearing(Project project, Collection<VirtualFile> affectedOutputPaths) { final StringBuilder paths = new StringBuilder(); for (final VirtualFile affectedOutputPath : affectedOutputPaths) { if (paths.length() > 0) { paths.append(",\n"); }//from w w w . j a v a2 s .co m paths.append(affectedOutputPath.getPath().replace('/', File.separatorChar)); } final int answer = Messages.showOkCancelDialog(project, CompilerBundle.message("warning.sources.under.output.paths", paths.toString()), CommonBundle.getErrorTitle(), Messages.getWarningIcon()); if (answer == Messages.OK) { // ok return true; } else { return false; } }
From source file:com.intellij.debugger.settings.ArrayRendererConfigurable.java
License:Apache License
private void applyTo(ArrayRenderer renderer, boolean showBigRangeWarning) { int newStartIndex = getInt(myStartIndex); int newEndIndex = getInt(myEndIndex); int newLimit = getInt(myEntriesLimit); if (newStartIndex >= 0 && newEndIndex >= 0) { if (newStartIndex >= newEndIndex) { int currentStartIndex = renderer.START_INDEX; int currentEndIndex = renderer.END_INDEX; newEndIndex = newStartIndex + (currentEndIndex - currentStartIndex); }//from w ww.j a v a 2s. co m if (newLimit <= 0) { newLimit = 1; } if (showBigRangeWarning && (newEndIndex - newStartIndex > 10000)) { final int answer = Messages.showOkCancelDialog(myPanel.getRootPane(), DebuggerBundle.message("warning.range.too.big", ApplicationNamesInfo.getInstance().getProductName()), DebuggerBundle.message("title.range.too.big"), Messages.getWarningIcon()); if (answer != DialogWrapper.OK_EXIT_CODE) { return; } } } renderer.START_INDEX = newStartIndex; renderer.END_INDEX = newEndIndex; renderer.ENTRIES_LIMIT = newLimit; }
From source file:com.intellij.execution.testframework.export.ExportTestResultsAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); LOG.assertTrue(project != null);//from w w w.j a va 2 s .c o m final ExportTestResultsConfiguration config = ExportTestResultsConfiguration.getInstance(project); final String name = ExecutionBundle.message("export.test.results.filename", PathUtil.suggestFileName(myRunConfiguration.getName())); String filename = name + "." + config.getExportFormat().getDefaultExtension(); boolean showDialog = true; while (showDialog) { final ExportTestResultsDialog d = new ExportTestResultsDialog(project, config, filename); d.show(); if (!d.isOK()) { return; } filename = d.getFileName(); showDialog = getOutputFile(config, project, filename).exists() && Messages.showOkCancelDialog(project, ExecutionBundle.message("export.test.results.file.exists.message", filename), ExecutionBundle.message("export.test.results.file.exists.title"), Messages.getQuestionIcon()) != DialogWrapper.OK_EXIT_CODE; } final String filename_ = filename; ProgressManager.getInstance().run(new Task.Backgroundable(project, ExecutionBundle.message("export.test.results.task.name"), false, new PerformInBackgroundOption() { @Override public boolean shouldStartInBackground() { return true; } @Override public void processSentToBackground() { } }) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); final File outputFile = getOutputFile(config, project, filename_); final String outputText; try { outputText = getOutputText(config); if (outputText == null) { return; } } catch (IOException ex) { LOG.warn(ex); showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ex.getMessage()), null); return; } catch (TransformerException ex) { LOG.warn(ex); showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ex.getMessage()), null); return; } catch (SAXException ex) { LOG.warn(ex); showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ex.getMessage()), null); return; } catch (RuntimeException ex) { ExportTestResultsConfiguration c = new ExportTestResultsConfiguration(); c.setExportFormat(ExportTestResultsConfiguration.ExportFormat.Xml); c.setOpenResults(false); try { String xml = getOutputText(c); LOG.error(LogMessageEx.createEvent("Failed to export test results", ExceptionUtil.getThrowableText(ex), null, null, new Attachment("dump.xml", xml))); } catch (Throwable ignored) { LOG.error("Failed to export test results", ex); } return; } final Ref<VirtualFile> result = new Ref<VirtualFile>(); final Ref<String> error = new Ref<String>(); ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { result.set( ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() { @Override public VirtualFile compute() { outputFile.getParentFile().mkdirs(); final VirtualFile parent = LocalFileSystem.getInstance() .refreshAndFindFileByIoFile(outputFile.getParentFile()); if (parent == null || !parent.isValid()) { error.set(ExecutionBundle.message("failed.to.create.output.file", outputFile.getPath())); return null; } try { VirtualFile result = parent.createChildData(this, outputFile.getName()); VfsUtil.saveText(result, outputText); return result; } catch (IOException e) { LOG.warn(e); error.set(e.getMessage()); return null; } } })); } }, ModalityState.defaultModalityState()); if (!result.isNull()) { if (config.isOpenResults()) { openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml); } else { HyperlinkListener listener = new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { openEditorOrBrowser(result.get(), project, config .getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml); } } }; showBalloon(project, MessageType.INFO, ExecutionBundle.message("export.test.results.succeeded", outputFile.getName()), listener); } } else { showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", error.get()), null); } } }); }
From source file:com.intellij.find.replaceInProject.ReplaceInProjectManager.java
License:Apache License
private boolean ensureUsagesWritable(ReplaceContext replaceContext, Collection<Usage> selectedUsages) { Set<VirtualFile> readOnlyFiles = null; for (final Usage usage : selectedUsages) { final VirtualFile file = ((UsageInFile) usage).getFile(); if (file != null && !file.isWritable()) { if (readOnlyFiles == null) readOnlyFiles = new HashSet<VirtualFile>(); readOnlyFiles.add(file);/* w ww. jav a 2 s .c om*/ } } if (readOnlyFiles != null) { ReadonlyStatusHandler.getInstance(myProject) .ensureFilesWritable(VfsUtilCore.toVirtualFileArray(readOnlyFiles)); } if (hasReadOnlyUsages(selectedUsages)) { int result = Messages.showOkCancelDialog(replaceContext.getUsageView().getComponent(), FindBundle.message("find.replace.occurrences.in.read.only.files.prompt"), FindBundle.message("find.replace.occurrences.in.read.only.files.title"), Messages.getWarningIcon()); if (result != Messages.OK) { return false; } } return true; }
From source file:com.intellij.ide.actions.CreateLauncherScriptAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { if (!isAvailable()) return;/* w w w. j a v a 2s .c o m*/ Project project = e.getProject(); CreateLauncherScriptDialog dialog = new CreateLauncherScriptDialog(project); dialog.show(); if (!dialog.isOK()) { return; } String path = dialog.myPathField.getText(); if (!path.startsWith("/")) { final String home = System.getenv("HOME"); if (home != null && new File(home).isDirectory()) { if (path.startsWith("~")) { path = home + path.substring(1); } else { path = home + "/" + path; } } } final File target = new File(path, dialog.myNameField.getText()); if (target.exists()) { int rc = Messages.showOkCancelDialog(project, ApplicationBundle.message("launcher.script.overwrite", target), "Create Launcher Script", Messages.getQuestionIcon()); if (rc != 0) { return; } } createLauncherScript(project, target.getAbsolutePath()); }
From source file:com.intellij.ide.actions.ReloadFromDiskAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext); if (editor == null) return;//w w w .j ava 2 s.c o m final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (psiFile == null) return; int res = Messages.showOkCancelDialog(project, IdeBundle.message("prompt.reload.file.from.disk", psiFile.getVirtualFile().getPresentableUrl()), IdeBundle.message("title.reload.file"), Messages.getWarningIcon()); if (res != 0) return; CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { PsiManager.getInstance(project).reloadFromDisk(psiFile); } }); } }, IdeBundle.message("command.reload.from.disk"), null); }
From source file:com.intellij.ide.actions.SaveAsDirectoryBasedFormatAction.java
License:Apache License
public void actionPerformed(AnActionEvent e) { final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); if (project instanceof ProjectEx) { final IProjectStore projectStore = ((ProjectEx) project).getStateStore(); if (StorageScheme.DIRECTORY_BASED != projectStore.getStorageScheme()) { final int result = Messages.showOkCancelDialog(project, "Project will be saved and reopened in new Directory-Based format.\nAre you sure you want to continue?", "Save project to Directory-Based format", Messages.getWarningIcon()); if (result == 0) { final VirtualFile baseDir = project.getBaseDir(); assert baseDir != null; File ideaDir = new File(baseDir.getPath(), ProjectEx.DIRECTORY_STORE_FOLDER + File.separatorChar); final boolean ok = (ideaDir.exists() && ideaDir.isDirectory()) || createDir(ideaDir); if (ok) { LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ideaDir); final StateStorageManager storageManager = projectStore.getStateStorageManager(); final Collection<String> storageFileNames = new ArrayList<String>( storageManager.getStorageFileNames()); for (String file : storageFileNames) { storageManager.clearStateStorage(file); }//from w w w. j a v a 2s. com projectStore.setProjectFilePath(baseDir.getPath()); project.save(); ProjectUtil.closeAndDispose(project); ProjectUtil.openOrImport(baseDir.getPath(), null, false); } else { Messages.showErrorDialog(project, String.format("Unable to create '.idea' directory (%s)", ideaDir), "Error saving project!"); } } } } }
From source file:com.intellij.ide.plugins.InstalledPluginsManagerMain.java
License:Apache License
private void checkInstalledPluginDependencies(IdeaPluginDescriptorImpl pluginDescriptor) { final Set<PluginId> notInstalled = new HashSet<PluginId>(); final Set<PluginId> disabledIds = new HashSet<PluginId>(); final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds(); final PluginId[] optionalDependentPluginIds = pluginDescriptor.getOptionalDependentPluginIds(); for (PluginId id : dependentPluginIds) { if (ArrayUtilRt.find(optionalDependentPluginIds, id) > -1) continue; final boolean disabled = ((InstalledPluginsTableModel) pluginsModel).isDisabled(id); final boolean enabled = ((InstalledPluginsTableModel) pluginsModel).isEnabled(id); if (!enabled && !disabled) { notInstalled.add(id);/*from www . j a va 2 s .co m*/ } else if (disabled) { disabledIds.add(id); } } if (!notInstalled.isEmpty()) { Messages.showWarningDialog("Plugin " + pluginDescriptor.getName() + " depends on unknown plugin" + (notInstalled.size() > 1 ? "s " : " ") + StringUtil.join(notInstalled, new Function<PluginId, String>() { @Override public String fun(PluginId id) { return id.toString(); } }, ", "), CommonBundle.getWarningTitle()); } if (!disabledIds.isEmpty()) { final Set<IdeaPluginDescriptor> dependencies = new HashSet<IdeaPluginDescriptor>(); for (IdeaPluginDescriptor ideaPluginDescriptor : pluginsModel.getAllPlugins()) { if (disabledIds.contains(ideaPluginDescriptor.getPluginId())) { dependencies.add(ideaPluginDescriptor); } } final String disabledPluginsMessage = "disabled plugin" + (dependencies.size() > 1 ? "s " : " "); String message = "Plugin " + pluginDescriptor.getName() + " depends on " + disabledPluginsMessage + StringUtil.join(dependencies, new Function<IdeaPluginDescriptor, String>() { @Override public String fun(IdeaPluginDescriptor ideaPluginDescriptor) { return ideaPluginDescriptor.getName(); } }, ", ") + ". Enable " + disabledPluginsMessage.trim() + "?"; if (Messages.showOkCancelDialog(myActionsPanel, message, CommonBundle.getWarningTitle(), Messages.getWarningIcon()) == Messages.OK) { ((InstalledPluginsTableModel) pluginsModel).enableRows( dependencies.toArray(new IdeaPluginDescriptor[dependencies.size()]), Boolean.TRUE); } } }