List of usage examples for com.intellij.openapi.ui Messages showOkCancelDialog
@OkCancelResult public static int showOkCancelDialog(String message, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @NotNull String okText, @NotNull String cancelText, Icon icon, @Nullable DialogWrapper.DoNotAskOption doNotAskOption)
From source file:com.ccnode.codegenerator.service.SendToServerService.java
public static void post(Project project, ServerRequest request) { try {//from w w w .ja va 2s . co m List<String> errorList = Lists.newArrayList(); for (String s : LoggerWrapper.errorList) { if (StringUtils.isNotBlank(s)) { errorList.add(StringUtils.deleteWhitespace(s)); } } request.setErrorList(errorList); String s = HttpUtil.postJson(UrlManager.getPostUrl() + "&type=" + request.getRequestType(), request); LOGGER.info("ret:{}", s); if (StringUtils.isBlank(s) || !StringUtils.containsIgnoreCase(s, "success")) { return; } PostResponse serverMsg = JSONUtil.parseObject(s, PostResponse.class); if (serverMsg != null && serverMsg.getHasServerMsg()) { int result = Messages.showOkCancelDialog(project, serverMsg.getContent(), serverMsg.getTitle(), "OK", serverMsg.getButtonStr(), null); if (result == 2 && StringUtils.isNotBlank(serverMsg.getButtonUrl())) { BrowserLauncher.getInstance().browse(serverMsg.getButtonUrl(), WebBrowserManager.getInstance().getFirstActiveBrowser()); } SettingService.getSetting().geteKeyList().add(String.valueOf(serverMsg.getMsgId())); } } catch (Throwable ignored) { } }
From source file:com.chrisrm.idea.MTLafComponent.java
License:Open Source License
/** * Ask for resetting custom theme colors when the LafManager is switched from or to dark mode * * @param source// w w w . j av a2 s. c o m */ private void askResetCustomTheme(final LafManager source) { // If switched look and feel and asking for reset (default true) if (source.getCurrentLookAndFeel() != currentLookAndFeel && !MTCustomThemeConfig.getInstance().isDoNotAskAgain()) { final int dialog = Messages.showOkCancelDialog( MaterialThemeBundle.message("mt.resetCustomTheme.message"), MaterialThemeBundle.message("mt.resetCustomTheme.title"), CommonBundle.getOkButtonText(), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon(), new DialogWrapper.DoNotAskOption.Adapter() { @Override public void rememberChoice(final boolean isSelected, final int exitCode) { if (exitCode != -1) { MTCustomThemeConfig.getInstance().setDoNotAskAgain(isSelected); } } }); if (dialog == Messages.YES) { MTCustomThemeConfig.getInstance().setDefaultValues(); currentLookAndFeel = source.getCurrentLookAndFeel(); MTThemeManager.getInstance().activate(); } } currentLookAndFeel = source.getCurrentLookAndFeel(); }
From source file:com.goide.inspections.WrongModuleTypeNotificationProvider.java
License:Apache License
@NotNull private static EditorNotificationPanel createPanel(@NotNull final Project project, @NotNull final Module module) { EditorNotificationPanel panel = new EditorNotificationPanel(); panel.setText("'" + module.getName() + "' is not Go Module, some code insight might not work here"); panel.createActionLabel("Change module type to Go and reload project", new Runnable() { @Override//from ww w. j av a 2 s . c o m public void run() { int message = Messages.showOkCancelDialog(project, "Updating module type requires project reload. Proceed?", "Update Module Type", "Reload project", "Cancel", null); if (message == Messages.YES) { module.setOption(Module.ELEMENT_TYPE, GoModuleType.getInstance().getId()); project.save(); EditorNotifications.getInstance(project).updateAllNotifications(); ProjectManager.getInstance().reloadProject(project); } } }); panel.createActionLabel("Don't show again for this module", new Runnable() { @Override public void run() { Set<String> ignoredModules = getIgnoredModules(project); ignoredModules.add(module.getName()); PropertiesComponent.getInstance(project).setValue(DONT_ASK_TO_CHANGE_MODULE_TYPE_KEY, StringUtil.join(ignoredModules, ",")); EditorNotifications.getInstance(project).updateAllNotifications(); } }); return panel; }
From source file:com.google.gct.intellij.endpoints.action.GenerateEndpointAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { // TODO: check if app engine module in here as well PsiJavaFile psiJavaFile = getPsiJavaFileFromContext(e); final Project project = e.getProject(); final Module module = e.getData(LangDataKeys.MODULE); if (psiJavaFile == null || module == null) { Messages.showErrorDialog(project, "Please select a Java file to create an Endpoint for", ERROR_MESSAGE_TITLE);//from w w w. j a va2 s. c om return; } final AppEngineMavenProject appEngineMavenProject = AppEngineMavenProject.get(module); if (appEngineMavenProject == null) { Messages.showErrorDialog(project, "Please select a valid Maven enabled App Engine module", ERROR_MESSAGE_TITLE); return; } PsiClass entityClass = PsiUtils.getPublicAnnotatedClass(psiJavaFile, GctConstants.APP_ENGINE_ANNOTATION_ENTITY); if (entityClass == null) { Messages.showErrorDialog(project, "No JPA @Entity Class found in " + psiJavaFile.getName(), ERROR_MESSAGE_TITLE); return; } PsiField idField = PsiUtils.getAnnotatedFieldFromClass(entityClass, GctConstants.APP_ENGINE_ANNOTATION_ID); if (idField == null) { Messages.showErrorDialog(project, "No JPA @Id found in " + psiJavaFile.getName(), ERROR_MESSAGE_TITLE); return; } // TODO: this check is a little strange, but maybe necessary for information sake? if (idField.getType().getCanonicalText().equals(GctConstants.APP_ENGINE_TYPE_KEY)) { int retVal = Messages.showOkCancelDialog(project, "Endpoints with @Id of type " + GctConstants.APP_ENGINE_TYPE_KEY + " are not fully " + "compatible with the generation template and may require some user modification to work", "Warning", "Continue", "Cancel", Messages.getWarningIcon()); if (retVal != 0) { return; } } doAction(project, appEngineMavenProject, entityClass, idField); }
From source file:com.intellij.compiler.impl.CompileDriver.java
License:Apache License
private void startup(final CompileScope scope, final boolean isRebuild, final boolean forceCompile, final CompileStatusNotification callback, final CompilerMessage message, final boolean checkCachesVersion) { ApplicationManager.getApplication().assertIsDispatchThread(); ProblemsView.getInstance(myProject).clearOldMessages(null); final String contentName = forceCompile ? CompilerBundle.message("compiler.content.name.compile") : CompilerBundle.message("compiler.content.name.make"); final boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode(); final CompilerTask compileTask = new CompilerTask(myProject, contentName, isUnitTestMode, true, true, isCompilationStartedAutomatically(scope)); StatusBar.Info.set("", myProject, "Compiler"); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); FileDocumentManager.getInstance().saveAllDocuments(); final CompositeDependencyCache dependencyCache = createDependencyCache(); final CompileContextImpl compileContext = new CompileContextImpl(myProject, compileTask, scope, dependencyCache, !isRebuild && !forceCompile, isRebuild); for (Map.Entry<Pair<IntermediateOutputCompiler, Module>, Pair<VirtualFile, VirtualFile>> entry : myGenerationCompilerModuleToOutputDirMap .entrySet()) {//from w w w.j a va 2s. c o m final Pair<VirtualFile, VirtualFile> outputs = entry.getValue(); final Pair<IntermediateOutputCompiler, Module> key = entry.getKey(); final Module module = key.getSecond(); compileContext.assignModule(outputs.getFirst(), module, false, key.getFirst()); compileContext.assignModule(outputs.getSecond(), module, true, key.getFirst()); } attachAnnotationProcessorsOutputDirectories(compileContext); final Runnable compileWork = new Runnable() { @Override public void run() { if (compileContext.getProgressIndicator().isCanceled()) { if (callback != null) { callback.finished(true, 0, 0, compileContext); } return; } try { if (myProject.isDisposed()) { return; } LOG.info("COMPILATION STARTED"); if (message != null) { compileContext.addMessage(message); } else { if (!isUnitTestMode) { //FIXME [VISTALL] notifyDeprecatedImplementation(); } } TranslatingCompilerFilesMonitor.getInstance().ensureInitializationCompleted(myProject, compileContext.getProgressIndicator()); doCompile(compileContext, isRebuild, forceCompile, callback, checkCachesVersion); } finally { FileUtil.delete(CompilerPaths.getRebuildMarkerFile(myProject)); } } }; compileTask.start(compileWork, new Runnable() { @Override public void run() { if (isRebuild) { final int rv = Messages.showOkCancelDialog(myProject, "You are about to rebuild the whole project.\nRun 'Make Project' instead?", "Confirm Project Rebuild", "Make", "Rebuild", Messages.getQuestionIcon()); if (rv == 0 /*yes, please, do run make*/) { startup(scope, false, false, callback, null, checkCachesVersion); return; } } startup(scope, isRebuild, forceCompile, callback, message, checkCachesVersion); } }); }
From source file:com.intellij.conversion.impl.ui.ConvertProjectDialog.java
License:Apache License
private boolean checkReadOnlyFiles() throws IOException { List<File> files = getReadOnlyFiles(); if (!files.isEmpty()) { final String message = IdeBundle.message("message.text.unlock.read.only.files", ApplicationNamesInfo.getInstance().getFullProductName(), getFilesString(files)); final String[] options = { CommonBundle.getContinueButtonText(), CommonBundle.getCancelButtonText() }; if (Messages.showOkCancelDialog(myMainPanel, message, IdeBundle.message("dialog.title.convert.project"), options[0], options[1], null) != 0) { return false; }// w ww .j a va2s .co m unlockFiles(files); files = getReadOnlyFiles(); if (!files.isEmpty()) { showErrorMessage( IdeBundle.message("error.message.cannot.make.files.writable", getFilesString(files))); return false; } } return true; }
From source file:com.intellij.execution.ExecutableValidator.java
License:Apache License
private int showMessage(@Nullable Component parentComponent) { String okText = "Fix it"; String cancelText = CommonBundle.getCancelButtonText(); Icon icon = Messages.getErrorIcon(); String title = myNotificationErrorTitle; String description = myNotificationErrorDescription; return parentComponent != null ? Messages.showOkCancelDialog(parentComponent, description, title, okText, cancelText, icon) : Messages.showOkCancelDialog(myProject, description, title, okText, cancelText, icon); }
From source file:com.intellij.find.findUsages.JavaFindUsagesHandler.java
License:Apache License
private static boolean askWhetherShouldSearchForParameterInOverridingMethods(final PsiElement psiElement, final PsiParameter parameter) { return Messages.showOkCancelDialog(psiElement.getProject(), FindBundle.message("find.parameter.usages.in.overriding.methods.prompt", parameter.getName()), FindBundle.message("find.parameter.usages.in.overriding.methods.title"), CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText(), Messages.getQuestionIcon()) == Messages.OK; }
From source file:com.intellij.ide.util.DeleteHandler.java
License:Apache License
public static void deletePsiElement(final PsiElement[] elementsToDelete, final Project project, boolean needConfirmation) { if (elementsToDelete == null || elementsToDelete.length == 0) return;/* ww w.j a v a 2s . com*/ final PsiElement[] elements = PsiTreeUtil.filterAncestors(elementsToDelete); boolean safeDeleteApplicable = true; for (int i = 0; i < elements.length && safeDeleteApplicable; i++) { PsiElement element = elements[i]; safeDeleteApplicable = SafeDeleteProcessor.validElement(element); } final boolean dumb = DumbService.getInstance(project).isDumb(); if (safeDeleteApplicable && !dumb) { final Ref<Boolean> exit = Ref.create(false); final SafeDeleteDialog dialog = new SafeDeleteDialog(project, elements, new SafeDeleteDialog.Callback() { @Override public void run(final SafeDeleteDialog dialog) { if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(elements), true)) return; SafeDeleteProcessor.createInstance(project, new Runnable() { @Override public void run() { exit.set(true); dialog.close(DialogWrapper.OK_EXIT_CODE); } }, elements, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true) .run(); } }) { @Override protected boolean isDelete() { return true; } }; if (needConfirmation) { dialog.show(); if (!dialog.isOK() || exit.get()) return; } } else { @SuppressWarnings({ "UnresolvedPropertyKey" }) String warningMessage = DeleteUtil.generateWarningMessage(IdeBundle.message("prompt.delete.elements"), elements); boolean anyDirectories = false; String directoryName = null; for (PsiElement psiElement : elementsToDelete) { if (psiElement instanceof PsiDirectory && !PsiUtilBase.isSymLink((PsiDirectory) psiElement)) { anyDirectories = true; directoryName = ((PsiDirectory) psiElement).getName(); break; } } if (anyDirectories) { if (elements.length == 1) { warningMessage += IdeBundle.message("warning.delete.all.files.and.subdirectories", directoryName); } else { warningMessage += IdeBundle .message("warning.delete.all.files.and.subdirectories.in.the.selected.directory"); } } if (safeDeleteApplicable && dumb) { warningMessage += "\n\nWarning:\n Safe delete is not available while " + ApplicationNamesInfo.getInstance().getFullProductName() + " updates indices,\n no usages will be checked."; } if (needConfirmation) { int result = Messages.showOkCancelDialog(project, warningMessage, IdeBundle.message("title.delete"), ApplicationBundle.message("button.delete"), CommonBundle.getCancelButtonText(), Messages.getQuestionIcon()); if (result != Messages.OK) return; } } CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(elements), false)) { return; } // deleted from project view or something like that. if (CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext()) == null) { CommandProcessor.getInstance().markCurrentCommandAsGlobal(project); } for (final PsiElement elementToDelete : elements) { if (!elementToDelete.isValid()) continue; //was already deleted if (elementToDelete instanceof PsiDirectory) { VirtualFile virtualFile = ((PsiDirectory) elementToDelete).getVirtualFile(); if (virtualFile.isInLocalFileSystem() && !virtualFile.is(VFileProperty.SYMLINK)) { ArrayList<VirtualFile> readOnlyFiles = new ArrayList<VirtualFile>(); CommonRefactoringUtil.collectReadOnlyFiles(virtualFile, readOnlyFiles); if (!readOnlyFiles.isEmpty()) { String message = IdeBundle.message("prompt.directory.contains.read.only.files", virtualFile.getPresentableUrl()); int _result = Messages.showYesNoDialog(project, message, IdeBundle.message("title.delete"), Messages.getQuestionIcon()); if (_result != Messages.YES) continue; boolean success = true; for (VirtualFile file : readOnlyFiles) { success = clearReadOnlyFlag(file, project); if (!success) break; } if (!success) continue; } } } else if (!elementToDelete.isWritable() && !(elementToDelete instanceof PsiFileSystemItem && PsiUtilBase.isSymLink((PsiFileSystemItem) elementToDelete))) { final PsiFile file = elementToDelete.getContainingFile(); if (file != null) { final VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile.isInLocalFileSystem()) { int _result = MessagesEx.fileIsReadOnly(project, virtualFile) .setTitle(IdeBundle.message("title.delete")) .appendMessage(IdeBundle.message("prompt.delete.it.anyway")).askYesNo(); if (_result != Messages.YES) continue; boolean success = clearReadOnlyFlag(virtualFile, project); if (!success) continue; } } } try { elementToDelete.checkDelete(); } catch (IncorrectOperationException ex) { Messages.showMessageDialog(project, ex.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); continue; } ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { elementToDelete.delete(); } catch (final IncorrectOperationException ex) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showMessageDialog(project, ex.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } }); } } }); } } }, RefactoringBundle.message("safe.delete.command", RefactoringUIUtil.calculatePsiElementDescriptionList(elements)), null); }
From source file:com.intellij.ide.util.projectWizard.AbstractStepWithProgress.java
License:Apache License
public boolean validate() throws ConfigurationException { if (isProgressRunning()) { final int answer = Messages.showOkCancelDialog(getComponent(), myPromptStopSearch, IdeBundle.message("title.question"), IdeBundle.message("action.continue.searching"), IdeBundle.message("action.stop.searching"), Messages.getWarningIcon()); if (answer == 1) { // terminate cancelSearch();/*from ww w .j a va 2 s .co m*/ } return false; } return true; }