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

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

Introduction

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

Prototype

@NotNull
    public static Icon getErrorIcon() 

Source Link

Usage

From source file:org.jetbrains.android.sdk.AndroidSdkData.java

License:Apache License

@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
private boolean initializeDdmlib(@NotNull Project project) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    while (true) {
        final MyInitializeDdmlibTask task = new MyInitializeDdmlibTask(project);

        AdbErrors.clear();/* w ww . j  ava 2 s  .  co m*/

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                doInitializeDdmlib();
                task.finish();
            }
        });

        t.start();

        boolean retryWas = false;

        while (!task.isFinished()) {
            ProgressManager.getInstance().run(task);

            boolean finished = task.isFinished();

            if (task.isCanceled()) {
                myAdbCrashed = !finished;
                forceInterrupt(t);
                return false;
            }

            myAdbCrashed = false;

            if (!finished) {
                final String adbErrorString = combine(AdbErrors.getErrors());
                final int result = Messages.showDialog(project,
                        "ADB not responding. You can wait more, or kill \"" + SdkConstants.FN_ADB
                                + "\" process manually and click 'Restart'"
                                + (adbErrorString.length() > 0 ? "\nErrors from ADB:\n" + adbErrorString : ""),
                        CommonBundle.getErrorTitle(), new String[] { "&Wait more", "&Restart", "&Cancel" }, 0,
                        Messages.getErrorIcon());
                if (result == 2) {
                    // cancel
                    myAdbCrashed = true;
                    forceInterrupt(t);
                    return false;
                } else if (result == 1) {
                    // restart
                    myAdbCrashed = true;
                    retryWas = true;
                }
            }
        }

        // task finished, but if we had problems, ddmlib can be still initialized incorrectly, so we invoke initialize once again
        if (!retryWas) {
            break;
        }
    }

    return true;
}

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/*from  www.j a v a2 s.c  o m*/
 * @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;/*  w  ww .java2  s.com*/
    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 .jav a 2  s .c o  m

    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());
        }/* w  ww.j a  v 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());
        }/*from   w w  w .  j ava2s. com*/
    }, null, myProject);
}

From source file:org.jetbrains.plugins.github.util.GithubSslSupport.java

License:Apache License

@CalledInAwt
public boolean askIfShouldProceed(final String host) {
    final String BACK_TO_SAFETY = "No, I don't trust";
    final String TRUST = "Proceed anyway";
    //int choice = Messages.showDialog("The security certificate of " + host + " is not trusted. Do you want to
    // proceed anyway?",
    //                               "Not Trusted Certificate", new String[] { BACK_TO_SAFETY, TRUST }, 0,
    // Messages.getErrorIcon());
    int choice = Messages.showIdeaMessageDialog(null,
            "The security certificate of " + host + " is not trusted. Do" + " you want to proceed anyway?",
            "Not Trusted Certificate", new String[] { BACK_TO_SAFETY, TRUST }, 0, Messages.getErrorIcon(),
            null);//from  w  w w  .j  av a2  s  .  c o m
    boolean trust = (choice == 1);
    if (trust) {
        saveToTrusted(host);
    }
    return trust;
}

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;/*from   www .  j a  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;
                }/* w w  w  .j  a  v  a2 s .  co m*/
                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 a2s .  co 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;
}