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.community.intellij.plugins.communitycase.actions.RebaseActionBase.java
License:Apache License
/** * {@inheritDoc}//from www . ja v a 2 s . c om */ protected void perform(@NotNull final Project project, @NotNull final List<VirtualFile> Roots, @NotNull final VirtualFile defaultRoot, final Set<VirtualFile> affectedRoots, final List<VcsException> exceptions) throws VcsException { LineHandler h = createHandler(project, Roots, defaultRoot); if (h == null) { return; } final VirtualFile root = h.workingDirectoryFile(); RebaseEditorService service = RebaseEditorService.getInstance(); InteractiveRebaseEditorHandler editor = new InteractiveRebaseEditorHandler(service, project, root, h); RebaseLineListener resultListener = new RebaseLineListener(); h.addLineListener(resultListener); configureEditor(editor); affectedRoots.add(root); try { service.configureHandler(h, editor.getHandlerNo()); HandlerUtil.doSynchronously(h, Bundle.getString("rebasing.title"), h.printableCommandLine()); } finally { editor.close(); final RebaseLineListener.Result result = resultListener.getResult(); String messageId; boolean isError = true; switch (result.status) { case CONFLICT: messageId = "rebase.result.conflict"; break; case ERROR: messageId = "rebase.result.error"; break; case CANCELLED: isError = false; messageId = "rebase.result.cancelled"; // we do not need to show a message if editing was cancelled. exceptions.clear(); break; case EDIT: isError = false; messageId = "rebase.result.amend"; break; case FINISHED: default: messageId = null; } if (messageId != null) { String message = Bundle.message(messageId, result.current, result.total); String title = Bundle.message(messageId + ".title"); if (isError) { Messages.showErrorDialog(project, message, title); } else { Messages.showInfoMessage(project, message, title); } } } }
From source file:org.community.intellij.plugins.communitycase.actions.RepositoryAction.java
License:Apache License
/** * Get roots for the project. The method shows dialogs in the case when roots cannot be retrieved, so it should be called * from the event dispatch thread.//from w w w . ja v a2s .c o m * * @param project the project * @param vcs the Vcs * @return the list of the roots, or null */ @Nullable public static List<VirtualFile> getRoots(Project project, Vcs vcs) { List<VirtualFile> roots; try { roots = Util.getRoots(project, vcs); } catch (VcsException e) { Messages.showErrorDialog(project, e.getMessage(), Bundle.getString("repository.action.missing.roots.title")); return null; } return roots; }
From source file:org.community.intellij.plugins.communitycase.ui.TagDialog.java
License:Apache License
/** * Perform tagging according to selected options * * @param exceptions the list where exceptions are collected *//*from w ww . j av a 2 s .c o m*/ public void runAction(final List<VcsException> exceptions) { final String message = myMessageTextArea.getText(); final boolean hasMessage = message.trim().length() != 0; final File messageFile; if (hasMessage) { try { messageFile = FileUtil.createTempFile(MESSAGE_FILE_PREFIX, MESSAGE_FILE_SUFFIX); messageFile.deleteOnExit(); Writer out = new OutputStreamWriter(new FileOutputStream(messageFile), MESSAGE_FILE_ENCODING); try { out.write(message); } finally { out.close(); } } catch (IOException ex) { Messages.showErrorDialog(myProject, Bundle.message("tag.error.creating.message.file.message", ex.toString()), Bundle.getString("tag.error.creating.message.file.title")); return; } } else { messageFile = null; } try { SimpleHandler h = new SimpleHandler(myProject, getRoot(), Command.TAG); h.setRemote(true); if (hasMessage) { h.addParameters("-a"); } if (myForceCheckBox.isEnabled() && myForceCheckBox.isSelected()) { h.addParameters("-f"); } if (hasMessage) { h.addParameters("-F", messageFile.getAbsolutePath()); } h.addParameters(myTagNameTextField.getText()); String object = myCommitTextField.getText().trim(); if (object.length() != 0) { h.addParameters(object); } try { HandlerUtil.doSynchronously(h, Bundle.getString("tagging.title"), h.printableCommandLine()); UiUtil.notifySuccess(myProject, myTagNameTextField.getText(), "Created tag " + myTagNameTextField.getText() + " successfully."); } finally { exceptions.addAll(h.errors()); } } finally { if (messageFile != null) { //noinspection ResultOfMethodCallIgnored messageFile.delete(); } } }
From source file:org.community.intellij.plugins.communitycase.ui.UiUtil.java
License:Apache License
/** * Show error associated with the specified operation * * @param project the project//from w w w.java2 s.c om * @param message the error description * @param operation the operation name */ public static void showOperationError(final Project project, final String operation, final String message) { Messages.showErrorDialog(project, message, Bundle.message("error.occurred.during", operation)); }
From source file:org.community.intellij.plugins.communitycase.update.BaseRebaseProcess.java
License:Apache License
/** * Check if some roots are under the rebase operation and show a message in this case * * @param roots the roots to check//from w w w . j a v a 2 s. c om * @return true if some roots are being rebased */ private boolean areRootsUnderRebase(Set<VirtualFile> roots) { Set<VirtualFile> rebasingRoots = new TreeSet<VirtualFile>(Util.VIRTUAL_FILE_COMPARATOR); for (final VirtualFile root : roots) { if (RebaseUtils.isRebaseInTheProgress(root)) { rebasingRoots.add(root); } } if (!rebasingRoots.isEmpty()) { final StringBuilder files = new StringBuilder(); for (VirtualFile r : rebasingRoots) { files.append(Bundle.message("update.root.rebasing.item", r.getPresentableUrl())); //noinspection ThrowableInstanceNeverThrown myExceptions.add(new VcsException(Bundle.message("update.root.rebasing", r.getPresentableUrl()))); } com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(new Runnable() { public void run() { Messages.showErrorDialog(myProject, Bundle.message("update.root.rebasing.message", files.toString()), Bundle.message("update.root.rebasing.title")); } }); return true; } return false; }
From source file:org.community.intellij.plugins.communitycase.Vcs.java
License:Apache License
/** * Show errors as popup and as messages in vcs view. * * @param list a list of errors/*from www .j a va 2s .com*/ * @param action an action */ public void showErrors(@NotNull List<VcsException> list, @NotNull String action) { if (list.size() > 0) { StringBuffer buffer = new StringBuffer(); buffer.append("\n"); buffer.append(Bundle.message("error.list.title", action)); for (final VcsException exception : list) { buffer.append("\n"); buffer.append(exception.getMessage()); } final String msg = buffer.toString(); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { Messages.showErrorDialog(myProject, msg, Bundle.getString("error.dialog.title")); } }); } }
From source file:org.dylanfoundry.deft.library.LibraryAttachHandler.java
License:Apache License
@Nullable public static NewLibraryConfiguration chooseLibrary(final @NotNull Project project, JComponent parentComponent) { LibraryAttachDialog dialog = new LibraryAttachDialog(project); dialog.setTitle("Attach Library"); dialog.show();//from ww w . j ava 2 s. c o m if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) { return null; } NewLibraryConfiguration configuration = attachLibrary(project, dialog.getRegistryEntries()); if (configuration == null) { Messages.showErrorDialog(parentComponent, "No libraries attached", CommonBundle.getErrorTitle()); } return configuration; }
From source file:org.intellij.grammar.actions.BnfGenerateLexerAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext()); if (!(file instanceof BnfFile)) return;/*from w w w . j ava 2s . c o m*/ final Project project = file.getProject(); final BnfFile bnfFile = (BnfFile) file; final String flexFileName = getFlexFileName(bnfFile); Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, flexFileName, ProjectScope.getAllScope(project)); VirtualFile firstItem = ContainerUtil.getFirstItem(files); FileSaverDescriptor descriptor = new FileSaverDescriptor("Save JFlex Lexer", "", "flex"); VirtualFile baseDir = firstItem != null ? firstItem.getParent() : bnfFile.getVirtualFile().getParent(); VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, project) .save(baseDir, firstItem != null ? firstItem.getName() : flexFileName); if (fileWrapper == null) return; final VirtualFile virtualFile = fileWrapper.getVirtualFile(true); if (virtualFile == null) return; new WriteCommandAction.Simple(project) { @Override protected void run() throws Throwable { try { PsiDirectory psiDirectory = PsiManager.getInstance(project) .findDirectory(virtualFile.getParent()); assert psiDirectory != null; PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(psiDirectory); String packageName = aPackage == null ? null : aPackage.getQualifiedName(); String text = generateLexerText(bnfFile, packageName); VfsUtil.saveText(virtualFile, text); Notifications.Bus.notify( new Notification(BnfConstants.GENERATION_GROUP, virtualFile.getName() + " generated", "to " + virtualFile.getParent().getPath(), NotificationType.INFORMATION), project); associateFileTypeAndNavigate(project, virtualFile); } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, "Unable to create file " + flexFileName + "\n" + e.getLocalizedMessage(), "Create JFlex Lexer"); } }); } } }.execute(); }
From source file:org.intellij.grammar.actions.BnfGenerateParserUtilAction.java
License:Apache License
static String createClass(final String className, final PsiDirectory targetDirectory, final String baseClass, final String title, final Consumer<PsiClass> consumer) { final Project project = targetDirectory.getProject(); final Ref<PsiClass> resultRef = Ref.create(); new WriteCommandAction(project, title) { @Override/* w w w. j a v a2s . c o m*/ protected void run(Result result) throws Throwable { IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace(); PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory(); PsiJavaCodeReferenceElement ref = baseClass == null ? null : elementFactory.createReferenceElementByFQClassName(baseClass, GlobalSearchScope.allScope(project)); try { PsiClass resultClass = JavaDirectoryService.getInstance().createClass(targetDirectory, className); resultRef.set(resultClass); if (ref != null) { PsiElement baseClass = ref.resolve(); boolean isInterface = baseClass instanceof PsiClass && ((PsiClass) baseClass).isInterface(); PsiReferenceList targetReferenceList = isInterface ? resultClass.getImplementsList() : resultClass.getExtendsList(); assert targetReferenceList != null; targetReferenceList.add(ref); } if (consumer != null) { consumer.consume(resultClass); } } catch (final IncorrectOperationException e) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Messages.showErrorDialog(project, "Unable to create class " + className + "\n" + e.getLocalizedMessage(), title); } }); } } }.execute(); return resultRef.isNull() ? null : resultRef.get().getQualifiedName(); }
From source file:org.intellij.grammar.actions.BnfRunJFlexAction.java
License:Apache License
public static ActionCallback doGenerate(final Project project, VirtualFile flexFile, List<File> jflex, boolean forceNew) { FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); Document document = fileDocumentManager.getDocument(flexFile); if (document == null) return ActionCallback.REJECTED; final String commandName = "JFlex Generator"; String text = document.getText(); Matcher matcherClass = Pattern.compile("%class\\s+(\\w+)").matcher(text); final String lexerClassName = matcherClass.find() ? matcherClass.group(1) : null; Matcher matcherPackage = Pattern.compile("package\\s+([^;]+);|(%%)").matcher(text); final String lexerPackage = matcherPackage.find() ? StringUtil.trim(matcherPackage.group(1)) : null; if (lexerClassName == null) { String content = "Lexer class name option not found, use <pre>%class LexerClassName</pre>"; fail(project, flexFile, content); return ActionCallback.REJECTED; }// ww w .j av a 2s . c om try { final VirtualFile virtualDir = getTargetDirectoryFor(project, flexFile, lexerClassName + ".java", lexerPackage, false); File workingDir = VfsUtil.virtualToIoFile(flexFile).getParentFile().getAbsoluteFile(); SimpleJavaParameters javaParameters = new SimpleJavaParameters(); Sdk sdk = new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()); javaParameters.setWorkingDirectory(workingDir); javaParameters.setJdk(sdk); javaParameters.setJarPath(jflex.get(0).getAbsolutePath()); javaParameters.getVMParametersList().add("-Xmx512m"); javaParameters.getProgramParametersList() .addParametersString(StringUtil.nullize(Options.GEN_JFLEX_ARGS.get())); javaParameters.getProgramParametersList().add("-skel", jflex.get(1).getAbsolutePath()); javaParameters.getProgramParametersList().add("-d", VfsUtil.virtualToIoFile(virtualDir).getAbsolutePath()); javaParameters.getProgramParametersList().add(flexFile.getName()); OSProcessHandler processHandler = javaParameters.createOSProcessHandler(); RunContentDescriptor runContentDescriptor = createConsole(project, commandName, forceNew); ((ConsoleViewImpl) runContentDescriptor.getExecutionConsole()).attachToProcess(processHandler); final ActionCallback callback = new ActionCallback(); processHandler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(ProcessEvent event) { if (event.getExitCode() == 0) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { callback.setDone(); ensureLexerClassCreated(project, virtualDir, lexerClassName, commandName); } }, project.getDisposed()); } } }); processHandler.startNotify(); return callback; } catch (ExecutionException ex) { Messages.showErrorDialog(project, "Unable to run JFlex" + "\n" + ex.getLocalizedMessage(), commandName); return ActionCallback.REJECTED; } }