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.refactoring.move.moveInstanceMethod.MoveInstanceMethodDialogBase.java

License:Apache License

protected boolean verifyTargetClass(PsiClass targetClass) {
    if (targetClass.isInterface()) {
        final Project project = getProject();
        if (ClassInheritorsSearch.search(targetClass, false).findFirst() == null) {
            final String message = RefactoringBundle.message(
                    "0.is.an.interface.that.has.no.implementing.classes",
                    DescriptiveNameUtil.getDescriptiveName(targetClass));

            Messages.showErrorDialog(project, message, myRefactoringName);
            return false;
        }// w ww  .  j  a v  a  2 s  .  c o m

        final String message = RefactoringBundle.message(
                "0.is.an.interface.method.implementation.will.be.added.to.all.directly.implementing.classes",
                DescriptiveNameUtil.getDescriptiveName(targetClass));

        final int result = Messages.showYesNoDialog(project, message, myRefactoringName,
                Messages.getQuestionIcon());
        if (result != 0)
            return false;
    }

    return true;
}

From source file:com.intellij.spellchecker.settings.SpellCheckerSettingsPane.java

License:Apache License

public SpellCheckerSettingsPane(SpellCheckerSettings settings, final Project project) {
    super(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));

    mySpellCheckerSettings = settings;/*from  w  ww  .  j  av  a  2s  .co  m*/
    myManager = SpellCheckerManager.getInstance(project);
    HyperlinkLabel link = new HyperlinkLabel(SpellCheckerBundle.message("link.to.inspection.settings"));
    link.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                final OptionsEditor optionsEditor = OptionsEditor.KEY
                        .getData(DataManager.getInstance().getDataContext());
                if (optionsEditor != null) {
                    final ErrorsConfigurable errorsConfigurable = optionsEditor
                            .findConfigurable(ErrorsConfigurable.class);
                    if (errorsConfigurable != null) {
                        optionsEditor.clearSearchAndSelect(errorsConfigurable).doWhenDone(new Runnable() {
                            @Override
                            public void run() {
                                errorsConfigurable.selectInspectionTool(
                                        SpellCheckingInspection.SPELL_CHECKING_INSPECTION_TOOL_NAME);
                            }
                        });
                    }
                }
            }
        }
    });

    JPanel linkContainer = new JPanel(new BorderLayout());
    linkContainer.setPreferredSize(new Dimension(24, 38));
    linkContainer.add(link, BorderLayout.CENTER);
    add(linkContainer);

    // Fill in all the dictionaries folders (not implemented yet) and enabled dictionaries
    fillAllDictionaries();

    myPathsChooserComponent = new PathsChooserComponent(myDictionariesFolders,
            new PathsChooserComponent.PathProcessor() {
                @Override
                public boolean addPath(List<String> paths, String path) {
                    if (paths.contains(path)) {
                        final String title = SpellCheckerBundle.message("add.directory.title");
                        final String msg = SpellCheckerBundle.message("directory.is.already.included");
                        Messages.showErrorDialog(SpellCheckerSettingsPane.this, msg, title);
                        return false;
                    }
                    paths.add(path);

                    final ArrayList<Pair<String, Boolean>> currentDictionaries = myOptionalChooserComponent
                            .getCurrentModel();
                    SPFileUtil.processFilesRecursively(path, new Consumer<String>() {
                        @Override
                        public void consume(final String s) {
                            currentDictionaries.add(Pair.create(s, true));
                        }
                    });
                    myOptionalChooserComponent.refresh();
                    return true;
                }

                @Override
                public boolean removePath(List<String> paths, String path) {
                    if (paths.remove(path)) {
                        final ArrayList<Pair<String, Boolean>> result = new ArrayList<Pair<String, Boolean>>();
                        final ArrayList<Pair<String, Boolean>> currentDictionaries = myOptionalChooserComponent
                                .getCurrentModel();
                        for (Pair<String, Boolean> pair : currentDictionaries) {
                            if (!pair.first.startsWith(FileUtil.toSystemDependentName(path))) {
                                result.add(pair);
                            } else {
                                myRemovedDictionaries.add(pair.first);
                            }
                        }
                        currentDictionaries.clear();
                        currentDictionaries.addAll(result);
                        myOptionalChooserComponent.refresh();
                        return true;
                    }
                    return false;
                }
            }, project);

    myPathsChooserComponent.getEmptyText().setText(SpellCheckerBundle.message("no.custom.folders"));

    myOptionalChooserComponent = new OptionalChooserComponent<String>(myAllDictionaries) {
        @Override
        public JCheckBox createCheckBox(String path, boolean checked) {
            if (isUserDictionary(path)) {
                path = FileUtil.toSystemIndependentName(path);
                final int i = path.lastIndexOf('/');
                if (i != -1) {
                    final String name = path.substring(i + 1);
                    return new JCheckBox("[user] " + name, checked);
                }
            }
            return new JCheckBox("[bundled] " + FileUtil.toSystemDependentName(path), checked);
        }
    };

    myWordsPanel = new WordsPanel(myManager);

    TabbedPaneWrapper tabbedPaneWrapper = new TabbedPaneWrapper(this);
    tabbedPaneWrapper.addTab("Accepted Words", myWordsPanel);

    JPanel secondPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));

    JPanel customDictionariesPanel = new JPanel(
            new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));
    customDictionariesPanel.setBorder(
            IdeBorderFactory.createTitledBorder(SpellCheckerBundle.message("add.directory.title"), false));
    customDictionariesPanel.add(new JBLabel(SpellCheckerBundle.message("add.directory.description")));
    customDictionariesPanel.add(myPathsChooserComponent.getContentPane());
    secondPanel.add(customDictionariesPanel);

    myOptionalChooserComponent.getEmptyText().setText(SpellCheckerBundle.message("no.dictionaries"));
    JPanel dictionariesPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));
    dictionariesPanel.setBorder(
            IdeBorderFactory.createTitledBorder(SpellCheckerBundle.message("dictionaries.panel.title"), false));
    dictionariesPanel.add(new JBLabel(SpellCheckerBundle.message("dictionaries.panel.description")));
    dictionariesPanel.add(ScrollPaneFactory.createScrollPane(myOptionalChooserComponent.getContentPane()));
    secondPanel.add(dictionariesPanel);

    tabbedPaneWrapper.addTab("Dictionaries", secondPanel);

    add(tabbedPaneWrapper.getComponent());
}

From source file:com.intellij.tasks.actions.CloseTaskAction.java

License:Apache License

@RequiredDispatchThread
public void actionPerformed(@Nonnull AnActionEvent e) {
    Project project = e.getProject();//w  ww.j  ava  2 s .co m
    assert project != null;
    TaskManagerImpl taskManager = (TaskManagerImpl) TaskManager.getManager(project);
    LocalTask task = taskManager.getActiveTask();
    CloseTaskDialog dialog = new CloseTaskDialog(project, task);
    if (dialog.showAndGet()) {
        final CustomTaskState taskState = dialog.getCloseIssueState();
        if (taskState != null) {
            try {
                TaskRepository repository = task.getRepository();
                assert repository != null;
                repository.setTaskState(task, taskState);
                repository.setPreferredCloseTaskState(taskState);
            } catch (Exception e1) {
                Messages.showErrorDialog(project, e1.getMessage(), "Cannot Set State For Issue");
            }
        }
    }
}

From source file:com.intellij.tasks.actions.OpenTaskDialog.java

License:Apache License

public void createTask() {
    final TaskManagerImpl taskManager = (TaskManagerImpl) TaskManager.getManager(myProject);

    if (myUpdateState.isSelected()) {
        final CustomTaskState taskState = myTaskStateCombo.getSelectedState();
        final TaskRepository repository = myTask.getRepository();
        if (repository != null && taskState != null) {
            try {
                repository.setTaskState(myTask, taskState);
                repository.setPreferredOpenTaskState(taskState);
            } catch (Exception ex) {
                Messages.showErrorDialog(myProject, ex.getMessage(), "Cannot Set State For Issue");
                LOG.warn(ex);//from   w  ww  .  ja v  a  2s.com
            }
        }
    }
    taskManager.activateTask(myTask, isClearContext());
    if (myTask.getType() == TaskType.EXCEPTION && AnalyzeTaskStacktraceAction.hasTexts(myTask)) {
        AnalyzeTaskStacktraceAction.analyzeStacktrace(myTask, myProject);
    }

    for (TaskDialogPanel panel : myPanels) {
        panel.commit();
    }
}

From source file:com.intellij.tasks.impl.TaskManagerImpl.java

License:Apache License

@Override
public boolean testConnection(final TaskRepository repository) {

    TestConnectionTask task = new TestConnectionTask("Test connection") {
        @Override/*from  ww w. j  ava2s.c  o m*/
        public void run(@Nonnull ProgressIndicator indicator) {
            indicator.setText("Connecting to " + repository.getUrl() + "...");
            indicator.setFraction(0);
            indicator.setIndeterminate(true);
            try {
                myConnection = repository.createCancellableConnection();
                if (myConnection != null) {
                    Future<Exception> future = ApplicationManager.getApplication()
                            .executeOnPooledThread(myConnection);
                    while (true) {
                        try {
                            myException = future.get(100, TimeUnit.MILLISECONDS);
                            return;
                        } catch (TimeoutException ignore) {
                            try {
                                indicator.checkCanceled();
                            } catch (ProcessCanceledException e) {
                                myException = e;
                                myConnection.cancel();
                                return;
                            }
                        } catch (Exception e) {
                            myException = e;
                            return;
                        }
                    }
                } else {
                    try {
                        repository.testConnection();
                    } catch (Exception e) {
                        LOG.info(e);
                        myException = e;
                    }
                }
            } catch (Exception e) {
                myException = e;
            }
        }
    };
    ProgressManager.getInstance().run(task);
    Exception e = task.myException;
    if (e == null) {
        myBadRepositories.remove(repository);
        Messages.showMessageDialog(myProject, "Connection is successful", "Connection",
                Messages.getInformationIcon());
    } else if (!(e instanceof ProcessCanceledException)) {
        String message = e.getMessage();
        if (e instanceof UnknownHostException) {
            message = "Unknown host: " + message;
        }
        if (message == null) {
            LOG.error(e);
            message = "Unknown error";
        }
        Messages.showErrorDialog(myProject, StringUtil.capitalize(message), "Error");
    }
    return e == null;
}

From source file:com.intellij.tasks.timeTracking.SendTimeTrackingInformationDialog.java

License:Apache License

@Override
protected void doOKAction() {
    String timeSpentText = myFromPreviousPostRadioButton.isSelected() ? myFromPreviousPostTextField.getText()
            : myTotallyRadioButton.isSelected() ? myTotallyTextField.getText() : myCustomTextField.getText();
    final Matcher matcher = PATTERN.matcher(timeSpentText);
    if (matcher.matches()) {
        final int timeSpent = Integer.valueOf(matcher.group(1)) * 24 * 60
                + Integer.valueOf(matcher.group(2)) * 60 + Integer.valueOf(matcher.group(3));

        final TaskRepository repository = myTask.getRepository();
        if (repository != null && repository.isSupported(TaskRepository.TIME_MANAGEMENT)) {
            try {
                repository.updateTimeSpent(myTask, timeSpentText, myCommentTextArea.getText());
                myTask.setLastPost(new Date());
            } catch (Exception e1) {
                Messages.showErrorDialog(myProject, "<html>Could not send information for "
                        + myTask.getPresentableName() + "<br/>" + e1.getMessage(), "Error");
                LOG.warn(e1);/*from ww w .jav a  2 s  .  co m*/
            }
        }
    }

    super.doOKAction();
}

From source file:com.intellij.testIntegration.createTest.JavaTestGenerator.java

License:Apache License

private static void showErrorLater(final Project project, final String targetClassName) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
            Messages.showErrorDialog(project,
                    CodeInsightBundle.message("intention.error.cannot.create.class.message", targetClassName),
                    CodeInsightBundle.message("intention.error.cannot.create.class.title"));
        }/*w  w w .  j  a  v  a  2 s.  c o m*/
    });
}

From source file:com.intellij.tools.ScanSourceCommentsAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {

    final Project p = CommonDataKeys.PROJECT.getData(e.getDataContext());
    final String file = Messages.showInputDialog(p, "Enter path to the file comments will be extracted to",
            "Comments File Path", Messages.getQuestionIcon());

    try {/*  w w w .  ja  v a  2s .  c  o m*/
        final PrintStream stream = new PrintStream(file);
        stream.println("Comments in " + p.getName());

        ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
            @Override
            public void run() {
                final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
                ProjectRootManager.getInstance(p).getFileIndex().iterateContent(new ContentIterator() {
                    @Override
                    public boolean processFile(VirtualFile fileOrDir) {
                        if (fileOrDir.isDirectory()) {
                            indicator.setText("Extracting comments");
                            indicator.setText2(fileOrDir.getPresentableUrl());
                        }
                        scanCommentsInFile(p, fileOrDir);
                        return true;
                    }
                });

                indicator.setText2("");
                int count = 1;
                for (CommentDescriptor descriptor : myComments.values()) {
                    stream.println(
                            "#" + count + " ---------------------------------------------------------------");
                    descriptor.print(stream);
                    stream.println();
                    count++;
                }

            }
        }, "Generating Comments", true, p);

        stream.close();

    } catch (Throwable e1) {
        LOG.error(e1);
        Messages.showErrorDialog(p, "Error writing? " + e1.getMessage(), "Problem writing");
    }
}

From source file:com.intellij.uiDesigner.actions.DataBindingWizardAction.java

License:Apache License

public void actionPerformed(final AnActionEvent e) {
    final Project project;
    final VirtualFile formFile;
    GuiEditor editor = FormEditingUtil.getActiveEditor(e.getDataContext());
    assert editor != null;
    project = editor.getProject();//ww  w  .j  ava2 s .c o m
    formFile = editor.getFile();

    try {
        final WizardData wizardData = new WizardData(project, formFile);

        final Module module = ModuleUtil.findModuleForFile(formFile, wizardData.myProject);
        LOG.assertTrue(module != null);

        final LwRootContainer[] rootContainer = new LwRootContainer[1];
        Generator.exposeForm(wizardData.myProject, formFile, rootContainer);
        final String classToBind = rootContainer[0].getClassToBind();
        if (classToBind == null) {
            Messages.showInfoMessage(project, UIDesignerBundle.message("info.form.not.bound"),
                    UIDesignerBundle.message("title.data.binding.wizard"));
            return;
        }

        final PsiClass boundClass = FormEditingUtil.findClassToBind(module, classToBind);
        if (boundClass == null) {
            Messages.showErrorDialog(project,
                    UIDesignerBundle.message("error.bound.to.not.found.class", classToBind),
                    UIDesignerBundle.message("title.data.binding.wizard"));
            return;
        }

        Generator.prepareWizardData(wizardData, boundClass);

        if (!hasBinding(rootContainer[0])) {
            Messages.showInfoMessage(project, UIDesignerBundle.message("info.no.bound.components"),
                    UIDesignerBundle.message("title.data.binding.wizard"));
            return;
        }

        if (!wizardData.myBindToNewBean) {
            final String[] variants = new String[] { UIDesignerBundle.message("action.alter.data.binding"),
                    UIDesignerBundle.message("action.bind.to.another.bean"),
                    CommonBundle.getCancelButtonText() };
            final int result = Messages.showYesNoCancelDialog(project,
                    MessageFormat.format(UIDesignerBundle.message("info.data.binding.regenerate"),
                            wizardData.myBeanClass.getQualifiedName()),
                    UIDesignerBundle.message("title.data.binding"), variants[0], variants[1], variants[2],
                    Messages.getQuestionIcon());
            if (result == 0) {
                // do nothing here
            } else if (result == 1) {
                wizardData.myBindToNewBean = true;
            } else {
                return;
            }
        }

        final DataBindingWizard wizard = new DataBindingWizard(project, formFile, wizardData);
        wizard.show();
    } catch (Generator.MyException exc) {
        Messages.showErrorDialog(project, exc.getMessage(), CommonBundle.getErrorTitle());
    }
}

From source file:com.intellij.uiDesigner.actions.PreviewFormAction.java

License:Apache License

private static void showPreviewFrame(@NotNull final Module module, @NotNull final VirtualFile formFile,
        @Nullable final Locale stringDescriptorLocale) {
    final String tempPath;
    try {/*w  w w .  j  a va  2s  . c o  m*/
        final File tempDirectory = FileUtil.createTempDirectory("FormPreview", "");
        tempPath = tempDirectory.getAbsolutePath();

        CopyResourcesUtil.copyFormsRuntime(tempPath, true);
    } catch (IOException e) {
        Messages.showErrorDialog(module.getProject(),
                UIDesignerBundle.message("error.cannot.preview.form",
                        formFile.getPath().replace('/', File.separatorChar), e.toString()),
                CommonBundle.getErrorTitle());
        return;
    }

    final PathsList sources = OrderEnumerator.orderEntries(module).withoutSdk().withoutLibraries()
            .withoutDepModules().getSourcePathsList();
    final String classPath = OrderEnumerator.orderEntries(module).recursively().getPathsList().getPathsString()
            + File.pathSeparator + sources.getPathsString() + File.pathSeparator + /* resources bundles */
            tempPath;
    final InstrumentationClassFinder finder = Form2ByteCodeCompiler.createClassFinder(classPath);

    try {
        final Document doc = FileDocumentManager.getInstance().getDocument(formFile);
        final LwRootContainer rootContainer;
        try {
            rootContainer = Utils.getRootContainer(doc.getText(),
                    new CompiledClassPropertiesProvider(finder.getLoader()));
        } catch (Exception e) {
            Messages.showErrorDialog(module.getProject(),
                    UIDesignerBundle.message("error.cannot.read.form",
                            formFile.getPath().replace('/', File.separatorChar), e.getMessage()),
                    CommonBundle.getErrorTitle());
            return;
        }

        if (rootContainer.getComponentCount() == 0) {
            Messages.showErrorDialog(module.getProject(),
                    UIDesignerBundle.message("error.cannot.preview.empty.form",
                            formFile.getPath().replace('/', File.separatorChar)),
                    CommonBundle.getErrorTitle());
            return;
        }

        setPreviewBindings(rootContainer, CLASS_TO_BIND_NAME);

        // 2. Copy previewer class and all its superclasses into TEMP directory and instrument it.
        try {
            PreviewNestedFormLoader nestedFormLoader = new PreviewNestedFormLoader(module, tempPath, finder);

            final File tempFile = CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME, true);
            //CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$1", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MyExitAction", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MyPackAction", true);
            CopyResourcesUtil.copyClass(tempPath, CLASS_TO_BIND_NAME + "$MySetLafAction", true);

            Locale locale = Locale.getDefault();
            if (locale.getCountry().length() > 0 && locale.getLanguage().length() > 0) {
                CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage()
                        + "_" + locale.getCountry() + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            }
            if (locale.getLanguage().length() > 0) {
                CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage()
                        + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            }
            CopyResourcesUtil.copyProperties(tempPath, RUNTIME_BUNDLE_PREFIX + "_" + locale.getLanguage()
                    + PropertiesFileType.DOT_DEFAULT_EXTENSION);
            CopyResourcesUtil.copyProperties(tempPath,
                    RUNTIME_BUNDLE_PREFIX + PropertiesFileType.DOT_DEFAULT_EXTENSION);

            final AsmCodeGenerator codeGenerator = new AsmCodeGenerator(rootContainer, finder, nestedFormLoader,
                    true, new PsiClassWriter(module));
            codeGenerator.patchFile(tempFile);
            final FormErrorInfo[] errors = codeGenerator.getErrors();
            if (errors.length != 0) {
                Messages.showErrorDialog(module.getProject(),
                        UIDesignerBundle.message("error.cannot.preview.form",
                                formFile.getPath().replace('/', File.separatorChar),
                                errors[0].getErrorMessage()),
                        CommonBundle.getErrorTitle());
                return;
            }
        } catch (Exception e) {
            LOG.debug(e);
            Messages.showErrorDialog(module.getProject(),
                    UIDesignerBundle.message("error.cannot.preview.form",
                            formFile.getPath().replace('/', File.separatorChar),
                            e.getMessage() != null ? e.getMessage() : e.toString()),
                    CommonBundle.getErrorTitle());
            return;
        }

        // 2.5. Copy up-to-date properties files to the output directory.
        final HashSet<String> bundleSet = new HashSet<String>();
        FormEditingUtil.iterateStringDescriptors(rootContainer,
                new FormEditingUtil.StringDescriptorVisitor<IComponent>() {
                    public boolean visit(final IComponent component, final StringDescriptor descriptor) {
                        if (descriptor.getBundleName() != null) {
                            bundleSet.add(descriptor.getDottedBundleName());
                        }
                        return true;
                    }
                });

        if (bundleSet.size() > 0) {
            HashSet<VirtualFile> virtualFiles = new HashSet<VirtualFile>();
            HashSet<Module> modules = new HashSet<Module>();
            PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(module.getProject());
            for (String bundleName : bundleSet) {
                for (PropertiesFile propFile : manager.findPropertiesFiles(module, bundleName)) {
                    virtualFiles.add(propFile.getVirtualFile());
                    final Module moduleForFile = ModuleUtil.findModuleForFile(propFile.getVirtualFile(),
                            module.getProject());
                    if (moduleForFile != null) {
                        modules.add(moduleForFile);
                    }
                }
            }
            FileSetCompileScope scope = new FileSetCompileScope(virtualFiles,
                    modules.toArray(new Module[modules.size()]));

            CompilerManager.getInstance(module.getProject()).make(scope, new CompileStatusNotification() {
                public void finished(boolean aborted, int errors, int warnings,
                        final CompileContext compileContext) {
                    if (!aborted && errors == 0) {
                        runPreviewProcess(tempPath, sources, module, formFile, stringDescriptorLocale);
                    }
                }
            });
        } else {
            runPreviewProcess(tempPath, sources, module, formFile, stringDescriptorLocale);
        }
    } finally {
        finder.releaseResources();
    }
}