Example usage for com.intellij.openapi.ui Messages showErrorDialog

List of usage examples for com.intellij.openapi.ui Messages showErrorDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showErrorDialog.

Prototype

public static void showErrorDialog(@Nullable Component component, String message,
            @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Usage

From source file:com.intellij.debugger.actions.InspectAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    final DebuggerTreeNodeImpl node = getSelectedNode(e.getDataContext());
    if (node == null)
        return;/*from  www  .  ja  va2 s  .c o m*/
    final NodeDescriptorImpl descriptor = node.getDescriptor();
    final DebuggerStateManager stateManager = getContextManager(e.getDataContext());
    if (!(descriptor instanceof ValueDescriptorImpl) || stateManager == null)
        return;
    final DebuggerContextImpl context = stateManager.getContext();

    if (!canInspect((ValueDescriptorImpl) descriptor, context)) {
        return;
    }
    context.getDebugProcess().getManagerThread().schedule(new DebuggerContextCommandImpl(context) {
        public void threadAction() {
            try {
                final TextWithImports evaluationText = DebuggerTreeNodeExpression.createEvaluationText(node,
                        context);

                final NodeDescriptorImpl inspectDescriptor;
                if (descriptor instanceof WatchItemDescriptor) {
                    inspectDescriptor = (NodeDescriptorImpl) ((WatchItemDescriptor) descriptor).getModifier()
                            .getInspectItem(project);
                } else {
                    inspectDescriptor = descriptor;
                }

                DebuggerInvocationUtil.swingInvokeLater(project, new Runnable() {
                    public void run() {
                        final InspectDialog dialog = new InspectDialog(project, stateManager,
                                ActionsBundle.actionText(DebuggerActions.INSPECT) + " '" + evaluationText + "'",
                                inspectDescriptor);
                        dialog.show();
                    }
                });
            } catch (final EvaluateException e1) {
                DebuggerInvocationUtil.swingInvokeLater(project, new Runnable() {
                    public void run() {
                        Messages.showErrorDialog(project, e1.getMessage(),
                                ActionsBundle.actionText(DebuggerActions.INSPECT));
                    }
                });
            }
        }
    });
}

From source file:com.intellij.diagnostic.SubmitPerformanceReportAction.java

License:Apache License

@Override
public void actionPerformed(final AnActionEvent e) {
    String reportFileName = "perf_" + ApplicationInfo.getInstance().getBuild().asString() + "_"
            + SystemProperties.getUserName() + "_" + myDateFormat.format(new Date()) + ".zip";
    final File reportPath = new File(SystemProperties.getUserHome(), reportFileName);
    final File logDir = new File(PathManager.getLogPath());
    final Project project = e.getData(CommonDataKeys.PROJECT);

    final boolean[] archiveCreated = new boolean[1];
    final boolean completed = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        @Override//from  w  w  w  .j  ava2s .c  om
        public void run() {
            try {
                ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(reportPath));
                ZipUtil.addDirToZipRecursively(zip, reportPath, logDir, "", new FileFilter() {
                    @Override
                    public boolean accept(final File pathname) {
                        ProgressManager.checkCanceled();

                        if (logDir.equals(pathname.getParentFile())) {
                            return pathname.getPath().contains("threadDumps");
                        }
                        return true;
                    }
                }, null);
                zip.close();
                archiveCreated[0] = true;
            } catch (final IOException ex) {
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        Messages.showErrorDialog(project,
                                "Failed to create performance report archive: " + ex.getMessage(),
                                MESSAGE_TITLE);
                    }
                });
            }
        }
    }, "Collecting Performance Report data", true, project);

    if (!completed || !archiveCreated[0]) {
        return;
    }

    int rc = Messages.showYesNoDialog(project,
            "The performance report has been saved to\n" + reportPath
                    + "\n\nWould you like to submit it to JetBrains?",
            MESSAGE_TITLE, Messages.getQuestionIcon());
    if (rc == Messages.YES) {
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Uploading Performance Report") {
            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                final String error = uploadFileToFTP(reportPath, "ftp.intellij.net", ".uploads", indicator);
                if (error != null) {
                    ApplicationManager.getApplication().invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            Messages.showErrorDialog(error, MESSAGE_TITLE);
                        }
                    });
                }
            }
        });
    }
}

From source file:com.intellij.diff.tools.external.ExternalDiffTool.java

License:Apache License

public static void show(@Nullable final Project project, @NotNull final DiffRequestChain chain,
        @NotNull final DiffDialogHints hints) {
    try {/* w w  w  .j  a  va2s  . c  o m*/
        //noinspection unchecked
        final Ref<List<DiffRequest>> requestsRef = new Ref<List<DiffRequest>>();
        final Ref<Throwable> exceptionRef = new Ref<Throwable>();
        ProgressManager.getInstance().run(new Task.Modal(project, "Loading Requests", true) {
            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                try {
                    requestsRef.set(collectRequests(project, chain, indicator));
                } catch (Throwable e) {
                    exceptionRef.set(e);
                }
            }
        });

        if (!exceptionRef.isNull())
            throw exceptionRef.get();

        List<DiffRequest> showInBuiltin = new ArrayList<DiffRequest>();
        for (DiffRequest request : requestsRef.get()) {
            if (canShow(request)) {
                showRequest(project, request);
            } else {
                showInBuiltin.add(request);
            }
        }

        if (!showInBuiltin.isEmpty()) {
            DiffManagerEx.getInstance().showDiffBuiltin(project, new SimpleDiffRequestChain(showInBuiltin),
                    hints);
        }
    } catch (ProcessCanceledException ignore) {
    } catch (Throwable e) {
        LOG.error(e);
        Messages.showErrorDialog(project, e.getMessage(), "Can't Show Diff In External Tool");
    }
}

From source file:com.intellij.dvcs.DvcsCommitAdditionalComponent.java

License:Apache License

private void loadMessagesInModalTask(@NotNull Project project) {
    try {//  ww  w.  j a va  2  s . co m
        myMessagesForRoots = ProgressManager.getInstance().runProcessWithProgressSynchronously(
                new ThrowableComputable<Map<VirtualFile, String>, VcsException>() {
                    @Override
                    public Map<VirtualFile, String> compute() throws VcsException {
                        return getLastCommitMessages();
                    }
                }, "Reading commit message...", false, project);
    } catch (VcsException e) {
        Messages.showErrorDialog(getComponent(),
                "Couldn't load commit message of the commit to amend.\n" + e.getMessage(),
                "Commit Message not Loaded");
        log.info(e);
    }
}

From source file:com.intellij.execution.runners.ExecutionUtil.java

License:Apache License

public static void handleExecutionError(@NotNull final Project project, @NotNull final String toolWindowId,
        @NotNull String taskName, @NotNull ExecutionException e) {
    if (e instanceof RunCanceledByUserException) {
        return;//from  ww  w. ja  v  a 2s. c o  m
    }

    LOG.debug(e);

    String description = e.getMessage();
    if (description == null) {
        LOG.warn("Execution error without description", e);
        description = "Unknown error";
    }

    HyperlinkListener listener = null;
    if ((description.contains("87") || description.contains("111") || description.contains("206"))
            && e instanceof ProcessNotCreatedException
            && !PropertiesComponent.getInstance(project).isTrueValue("dynamic.classpath")) {
        final String commandLineString = ((ProcessNotCreatedException) e).getCommandLine()
                .getCommandLineString();
        if (commandLineString.length() > 1024 * 32) {
            description = "Command line is too long. In order to reduce its length classpath file can be used.<br>"
                    + "Would you like to enable classpath file mode for all run configurations of your project?<br>"
                    + "<a href=\"\">Enable</a>";

            listener = new HyperlinkListener() {
                @Override
                public void hyperlinkUpdate(HyperlinkEvent event) {
                    PropertiesComponent.getInstance(project).setValue("dynamic.classpath", "true");
                }
            };
        }
    }
    final String title = ExecutionBundle.message("error.running.configuration.message", taskName);
    final String fullMessage = title + ":<br>" + description;

    if (ApplicationManager.getApplication().isUnitTestMode()) {
        LOG.error(fullMessage, e);
    }

    if (listener == null && e instanceof HyperlinkListener) {
        listener = (HyperlinkListener) e;
    }

    final HyperlinkListener finalListener = listener;
    final String finalDescription = description;
    UIUtil.invokeLaterIfNeeded(new Runnable() {
        @Override
        public void run() {
            if (project.isDisposed()) {
                return;
            }

            ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
            if (toolWindowManager.canShowNotification(toolWindowId)) {
                //noinspection SSBasedInspection
                toolWindowManager.notifyByBalloon(toolWindowId, MessageType.ERROR, fullMessage, null,
                        finalListener);
            } else {
                Messages.showErrorDialog(project, UIUtil.toHtml(fullMessage), "");
            }
            NotificationListener notificationListener = finalListener == null ? null
                    : new NotificationListener() {
                        @Override
                        public void hyperlinkUpdate(@NotNull Notification notification,
                                @NotNull HyperlinkEvent event) {
                            finalListener.hyperlinkUpdate(event);
                        }
                    };
            ourNotificationGroup
                    .createNotification(title, finalDescription, NotificationType.ERROR, notificationListener)
                    .notify(project);
        }
    });
}

From source file:com.intellij.execution.util.ExecutionErrorDialog.java

License:Apache License

public static void show(final ExecutionException e, final String title, final Project project) {
    if (e instanceof RunCanceledByUserException) {
        return;/*from   w ww .j a v a2 s  .  c o m*/
    }

    if (ApplicationManager.getApplication().isUnitTestMode()) {
        throw new RuntimeException(e.getLocalizedMessage());
    }
    final String message = e.getMessage();
    if (message == null || message.length() < 100) {
        Messages.showErrorDialog(project, message == null ? "exception was thrown" : message, title);
        return;
    }
    final DialogBuilder builder = new DialogBuilder(project);
    builder.setTitle(title);
    final JTextArea textArea = new JTextArea();
    textArea.setEditable(false);
    textArea.setForeground(UIUtil.getLabelForeground());
    textArea.setBackground(UIUtil.getLabelBackground());
    textArea.setFont(UIUtil.getLabelFont());
    textArea.setText(message);
    textArea.setWrapStyleWord(false);
    textArea.setLineWrap(true);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(textArea);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    final JPanel panel = new JPanel(new BorderLayout(10, 0));
    panel.setPreferredSize(new Dimension(500, 200));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.add(new JLabel(Messages.getErrorIcon()), BorderLayout.WEST);
    builder.setCenterPanel(panel);
    builder.setButtonsAlignment(SwingConstants.CENTER);
    builder.addOkAction();
    builder.show();
}

From source file:com.intellij.find.FindUtil.java

License:Apache License

private static void doReplace(Project project, final Editor editor, final FindModel aModel,
        final Document document, int caretOffset, boolean toPrompt, ReplaceDelegate delegate) {
    FindManager findManager = FindManager.getInstance(project);
    final FindModel model = aModel.clone();
    int occurrences = 0;

    List<Pair<TextRange, String>> rangesToChange = new ArrayList<Pair<TextRange, String>>();

    boolean replaced = false;
    boolean reallyReplaced = false;

    int offset = caretOffset;
    while (offset >= 0 && offset < editor.getDocument().getTextLength()) {
        caretOffset = offset;//w  ww  .ja va  2s.  com
        FindResult result = doSearch(project, editor, offset, !replaced, model, toPrompt);
        if (result == null) {
            break;
        }
        int startResultOffset = result.getStartOffset();
        model.setFromCursor(true);

        int startOffset = result.getStartOffset();
        int endOffset = result.getEndOffset();
        String foundString = document.getCharsSequence().subSequence(startOffset, endOffset).toString();
        String toReplace;
        try {
            CharSequence textToMatch = document.getCharsSequence().subSequence(offset,
                    document.getTextLength());
            toReplace = findManager.getStringToReplace(foundString, model, startOffset - offset, textToMatch);
        } catch (FindManager.MalformedReplacementStringException e) {
            if (!ApplicationManager.getApplication().isUnitTestMode()) {
                Messages.showErrorDialog(project, e.getMessage(),
                        FindBundle.message("find.replace.invalid.replacement.string.title"));
            }
            break;
        }

        if (toPrompt) {
            int promptResult = findManager.showPromptDialog(model,
                    FindBundle.message("find.replace.dialog.title"));
            if (promptResult == FindManager.PromptResult.SKIP) {
                offset = model.isForward() ? result.getEndOffset() : startResultOffset;
                continue;
            }
            if (promptResult == FindManager.PromptResult.CANCEL) {
                break;
            }
            if (promptResult == FindManager.PromptResult.ALL) {
                toPrompt = false;
            }
        }
        int newOffset;
        if (delegate == null || delegate.shouldReplace(result, toReplace)) {
            if (toPrompt) {
                //[SCR 7258]
                if (!reallyReplaced) {
                    editor.getCaretModel().moveToOffset(0);
                    reallyReplaced = true;
                }
            }
            TextRange textRange = doReplace(project, document, model, result, toReplace, toPrompt,
                    rangesToChange);
            replaced = true;
            newOffset = model.isForward() ? textRange.getEndOffset() : textRange.getStartOffset();
            occurrences++;
        } else {
            newOffset = model.isForward() ? result.getEndOffset() : result.getStartOffset();
        }

        if (newOffset == offset) {
            newOffset += model.isForward() ? 1 : -1;
        }
        offset = newOffset;
    }

    if (replaced) {
        if (!toPrompt) {
            CharSequence text = document.getCharsSequence();
            final StringBuilder newText = new StringBuilder(document.getTextLength());
            Collections.sort(rangesToChange, new Comparator<Pair<TextRange, String>>() {
                @Override
                public int compare(Pair<TextRange, String> o1, Pair<TextRange, String> o2) {
                    return o1.getFirst().getStartOffset() - o2.getFirst().getStartOffset();
                }
            });
            int offsetBefore = 0;
            for (Pair<TextRange, String> pair : rangesToChange) {
                TextRange range = pair.getFirst();
                String replace = pair.getSecond();
                newText.append(text, offsetBefore, range.getStartOffset()); //before change
                if (delegate == null || delegate.shouldReplace(range, replace)) {
                    newText.append(replace);
                } else {
                    newText.append(text.subSequence(range.getStartOffset(), range.getEndOffset()));
                }
                offsetBefore = range.getEndOffset();
                if (offsetBefore < caretOffset) {
                    caretOffset += replace.length() - range.getLength();
                }
            }
            newText.append(text, offsetBefore, text.length()); //tail
            if (caretOffset > newText.length()) {
                caretOffset = newText.length();
            }
            final int finalCaretOffset = caretOffset;
            CommandProcessor.getInstance().executeCommand(project, new Runnable() {
                @Override
                public void run() {
                    ApplicationManager.getApplication().runWriteAction(new Runnable() {
                        @Override
                        public void run() {
                            document.setText(newText);
                            editor.getCaretModel().moveToOffset(finalCaretOffset);
                            if (model.isGlobal()) {
                                editor.getSelectionModel().removeSelection();
                            }
                        }
                    });
                }
            }, null, document);
        } else {
            if (reallyReplaced) {
                if (caretOffset > document.getTextLength()) {
                    caretOffset = document.getTextLength();
                }
                editor.getCaretModel().moveToOffset(caretOffset);
            }
        }
    }

    ReplaceInProjectManager.reportNumberReplacedOccurrences(project, occurrences);
}

From source file:com.intellij.gwt.actions.GwtCreateActionBase.java

License:Apache License

@Override
@Nonnull//w  ww .  ja  v  a2s.  com
protected final PsiElement[] invokeDialog(final Project project, final PsiDirectory directory) {
    Module module = ModuleUtil.findModuleForFile(directory.getVirtualFile(), project);
    if (module == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    GoogleGwtModuleExtension facet = ModuleUtilCore.getExtension(module, GoogleGwtModuleExtension.class);
    if (facet == null) {
        return PsiElement.EMPTY_ARRAY;
    }

    if (requireGwtModule()) {
        final GwtModule gwtModule = findGwtModule(project, directory);
        if (gwtModule == null) {
            final String message = GwtBundle.message(
                    "error.message.this.action.is.allowed.only.for.client.side.packages.of.a.gwt.module");
            Messages.showErrorDialog(project, message, CommonBundle.getErrorTitle());
            return PsiElement.EMPTY_ARRAY;
        }
    }

    MyInputValidator validator = new MyInputValidator(project, directory);
    Messages.showInputDialog(project, getDialogPrompt(), getDialogTitle(), Messages.getQuestionIcon(), "",
            validator);

    return validator.getCreatedElements();
}

From source file:com.intellij.history.integration.ui.views.HistoryDialog.java

License:Apache License

public void showError(String s) {
    Messages.showErrorDialog(myProject, s, CommonBundle.getErrorTitle());
}

From source file:com.intellij.ide.actions.CreateFileFromTemplateAction.java

License:Apache License

@SuppressWarnings("DialogTitleCapitalization")
@Nullable//from w ww.  j ava2  s.  c  om
public static PsiFile createFileFromTemplate(@Nullable String name, @NotNull FileTemplate template,
        @NotNull PsiDirectory dir, @Nullable String defaultTemplateProperty) {
    CreateFileAction.MkDirs mkdirs = new CreateFileAction.MkDirs(name, dir);
    name = mkdirs.newName;
    dir = mkdirs.directory;
    PsiElement element;
    Project project = dir.getProject();
    try {
        element = FileTemplateUtil.createFromTemplate(template, name,
                FileTemplateManager.getInstance().getDefaultProperties(project), dir);
        final PsiFile psiFile = element.getContainingFile();

        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null) {
            FileEditorManager.getInstance(project).openFile(virtualFile, true);
            if (defaultTemplateProperty != null) {
                PropertiesComponent.getInstance(project).setValue(defaultTemplateProperty, template.getName());
            }
            return psiFile;
        }
    } catch (ParseException e) {
        Messages.showErrorDialog(project, "Error parsing Velocity template: " + e.getMessage(),
                "Create File from Template");
        return null;
    } catch (IncorrectOperationException e) {
        throw e;
    } catch (Exception e) {
        LOG.error(e);
    }

    return null;
}