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

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

Introduction

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

Prototype

public static void showMessageDialog(@NotNull Component parent, String message,
            @NotNull @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon) 

Source Link

Usage

From source file:org.intellij.plugins.ui.MessageHandler.java

License:Open Source License

public void showMessageDialog(String message, String title, Icon icon) {
    Messages.showMessageDialog(project, message, title, icon);
}

From source file:org.jetbrains.generate.tostring.GenerateToStringUtils.java

License:Apache License

/**
 * Handles any exception during the executing on this plugin.
 *
 * @param project PSI project// w  w w.j a  v  a 2s .  com
 * @param e       the caused exception.
 * @throws RuntimeException is thrown for severe exceptions
 */
public static void handleException(Project project, Exception e) throws RuntimeException {
    log.info(e);

    if (e instanceof GenerateCodeException) {
        // code generation error - display velocity error in error dialog so user can identify problem quicker
        Messages.showMessageDialog(project,
                "Velocity error generating code - see IDEA log for more details (stacktrace should be in idea.log):\n"
                        + e.getMessage(),
                "Warning", Messages.getWarningIcon());
    } else if (e instanceof PluginException) {
        // plugin related error - could be recoverable.
        Messages.showMessageDialog(project,
                "A PluginException was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n"
                        + e.getMessage(),
                "Warning", Messages.getWarningIcon());
    } else if (e instanceof RuntimeException) {
        // unknown error (such as NPE) - not recoverable
        Messages.showMessageDialog(project,
                "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n"
                        + e.getMessage(),
                "Error", Messages.getErrorIcon());
        throw (RuntimeException) e; // throw to make IDEA alert user
    } else {
        // unknown error (such as NPE) - not recoverable
        Messages.showMessageDialog(project,
                "An unrecoverable exception was thrown while performing the action - see IDEA log for details (stacktrace should be in idea.log):\n"
                        + e.getMessage(),
                "Error", Messages.getErrorIcon());
        throw new RuntimeException(e); // rethrow as runtime to make IDEA alert user
    }
}

From source file:org.jetbrains.idea.devkit.inspections.quickfix.AbstractRegisterFix.java

License:Apache License

public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
    if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement()))
        return;/*from   w ww  .java 2  s .  c  o m*/
    final PsiFile psiFile = myClass.getContainingFile();
    LOG.assertTrue(psiFile != null);
    final Module module = ModuleUtil.findModuleForFile(psiFile.getVirtualFile(), project);

    Runnable command = new Runnable() {
        public void run() {
            try {
                if (ModuleUtil.getExtension(module, PluginModuleExtension.class) != null) {
                    final XmlFile pluginXml = PluginModuleUtil.getPluginXml(module);
                    if (pluginXml != null) {
                        DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXml);
                    }
                } else {
                    List<Module> modules = PluginModuleUtil.getCandidateModules(module);
                    if (modules.size() > 1) {
                        final ChooseModulesDialog dialog = new ChooseModulesDialog(project, modules, getName());
                        dialog.show();

                        if (!dialog.isOK()) {
                            return;
                        }
                        modules = dialog.getSelectedModules();
                    }
                    final XmlFile[] pluginXmls = new XmlFile[modules.size()];
                    for (int i = 0; i < pluginXmls.length; i++) {
                        pluginXmls[i] = PluginModuleUtil.getPluginXml(modules.get(i));
                    }

                    DescriptorUtil.patchPluginXml(AbstractRegisterFix.this, myClass, pluginXmls);
                }
                CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
            } catch (IncorrectOperationException e) {
                Messages.showMessageDialog(project, filterMessage(e.getMessage()),
                        DevKitBundle.message("inspections.component.not.registered.quickfix.error", getType()),
                        Messages.getErrorIcon());
            }
        }
    };
    CommandProcessor.getInstance().executeCommand(project, command, getName(), null);
}

From source file:org.jetbrains.idea.devkit.inspections.quickfix.BaseFix.java

License:Apache License

public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    // can happen during batch-inspection if resolution has already been applied
    // to plugin.xml or java class
    if (!myElement.isValid())
        return;//from w  w w . j  a  v a2s . c  om

    final boolean external = descriptor.getPsiElement().getContainingFile() != myElement.getContainingFile();
    if (external) {
        final PsiClass clazz = PsiTreeUtil.getParentOfType(myElement, PsiClass.class, false);
        final ReadonlyStatusHandler readonlyStatusHandler = ReadonlyStatusHandler.getInstance(project);
        final VirtualFile[] files = new VirtualFile[] { myElement.getContainingFile().getVirtualFile() };
        final ReadonlyStatusHandler.OperationStatus status = readonlyStatusHandler.ensureFilesWritable(files);

        if (status.hasReadonlyFiles()) {
            final String className = clazz != null ? clazz.getQualifiedName()
                    : myElement.getContainingFile().getName();

            Messages.showMessageDialog(project,
                    DevKitBundle.message("inspections.registration.problems.quickfix.read-only", className),
                    getName(), Messages.getErrorIcon());
            return;
        }
    }

    try {
        doFix(project, descriptor, external);
    } catch (IncorrectOperationException e) {
        Logger.getInstance("#" + getClass().getName()).error(e);
    }
}

From source file:org.jetbrains.idea.svn.diff.ElementWithBranchComparer.java

License:Apache License

private void reportGeneralException(final Exception e) {
    WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
        public void run() {
            Messages.showMessageDialog(myProject, e.getMessage(),
                    SvnBundle.message("compare.with.branch.error.title"), Messages.getErrorIcon());
        }//from   w ww.  j  av a  2 s.c  o  m
    }, null, myProject);
    LOG.info(e);
}

From source file:org.jetbrains.idea.svn.diff.ElementWithBranchComparer.java

License:Apache License

private void reportNotFound() {
    WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
        public void run() {
            Messages.showMessageDialog(myProject,
                    SvnBundle.message("compare.with.branch.location.error", myVirtualFile.getPresentableUrl(),
                            myBranchUrl),
                    SvnBundle.message("compare.with.branch.error.title"), Messages.getErrorIcon());
        }// www . j ava  2 s  .com
    }, null, myProject);
}

From source file:org.jetbrains.plugins.groovy.annotator.intentions.GrMoveToDirFix.java

License:Apache License

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiFile file = descriptor.getPsiElement().getContainingFile();

    if (!(file instanceof GroovyFile))
        return;//  w w  w  .ja va2s .  c  o m

    VirtualFile vfile = file.getVirtualFile();
    if (vfile == null)
        return;

    final Module module = ModuleUtilCore.findModuleForFile(vfile, project);
    if (module == null)
        return;

    final String packageName = ((GroovyFile) file).getPackageName();
    PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, null, true);
    if (directory == null)
        return;

    String error = RefactoringMessageUtil.checkCanCreateFile(directory, file.getName());
    if (error != null) {
        Messages.showMessageDialog(project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
    }
    new MoveFilesOrDirectoriesProcessor(project, new PsiElement[] { file }, directory, false, false, false,
            null, null).run();
}

From source file:org.jetbrains.plugins.groovy.annotator.intentions.GroovyCreateClassDialog.java

License:Apache License

protected void doOKAction() {
    final String packageName = getPackageName();

    final Ref<String> errorStringRef = new Ref<String>();
    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
        public void run() {
            try {
                final PsiDirectory baseDir = myModule == null ? null
                        : PackageUtil.findPossiblePackageDirectoryInModule(myModule, packageName);
                myTargetDirectory = myModule == null ? null
                        : PackageUtil.findOrCreateDirectoryForPackage(myModule, packageName, baseDir, true);
                if (myTargetDirectory == null) {
                    errorStringRef.set("");
                    return;
                }//from w w  w.  j a v a  2 s  . c om
                errorStringRef
                        .set(RefactoringMessageUtil.checkCanCreateClass(myTargetDirectory, getClassName()));
            } catch (IncorrectOperationException e) {
                errorStringRef.set(e.getMessage());
            }
        }
    }, GroovyInspectionBundle.message("create.directory.command"), null);

    if (errorStringRef.get() != null) {
        if (errorStringRef.get().length() > 0) {
            Messages.showMessageDialog(myProject, errorStringRef.get(), CommonBundle.getErrorTitle(),
                    Messages.getErrorIcon());
        }
        return;
    }
    super.doOKAction();
}

From source file:org.jetbrains.plugins.groovy.doc.GenerateGroovyDocDialog.java

License:Apache License

private boolean checkDir(String dirName, String dirPrefix) {
    if (dirName == null || dirName.trim().length() == 0) {
        Messages.showMessageDialog(myProject,
                GroovyDocBundle.message("groovydoc.generate.0.directory.not.specified", dirPrefix),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return false;
    }// w  w w.j a  v  a2 s .  c o  m

    File dir = new File(dirName);
    if (dir.exists()) {
        if (!dir.isDirectory()) {
            showError(GroovyDocBundle.message("groovydoc.generate.not.a.directory", dirName));
            return false;
        }
    } else {
        int choice = Messages.showOkCancelDialog(myProject,
                GroovyDocBundle.message("groovydoc.generate.directory.not.exists", dirName),
                GroovyDocBundle.message("groovydoc.generate.message.title"), Messages.getWarningIcon());
        if (choice != 0)
            return false;
        if (!dir.mkdirs()) {
            showError(GroovyDocBundle.message("groovydoc.generate.directory.creation.failed", dirName));
            return false;
        }
    }
    return true;
}

From source file:org.jetbrains.plugins.groovy.doc.GenerateGroovyDocDialog.java

License:Apache License

private void showError(final String message) {
    Messages.showMessageDialog(myProject, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
}