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:com.intellij.application.options.SaveSchemeDialog.java

License:Apache License

@Override
protected void doOKAction() {
    if (getSchemeName().trim().isEmpty()) {
        Messages.showMessageDialog(getContentPane(), ApplicationBundle.message("error.scheme.must.have.a.name"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;/*  w  w w. j a v  a  2s.  co m*/
    } else if ("default".equals(getSchemeName())) {
        Messages.showMessageDialog(getContentPane(), ApplicationBundle.message("error.illegal.scheme.name"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
    } else if (myExistingNames.contains(getSchemeName())) {
        Messages.showMessageDialog(getContentPane(), ApplicationBundle.message(
                "error.a.scheme.with.this.name.already.exists.or.was.deleted.without.applying.the.changes"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return;
    }
    super.doOKAction();
}

From source file:com.intellij.codeInsight.actions.AbstractLayoutCodeProcessor.java

License:Apache License

private void runProcessFile(@NotNull final PsiFile file) {
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);

    if (document == null) {
        return;/*from  w  w w. j a v a 2 s. com*/
    }

    if (!FileDocumentManager.getInstance().requestWriting(document, myProject)) {
        Messages.showMessageDialog(myProject,
                PsiBundle.message("cannot.modify.a.read.only.file", file.getName()),
                CodeInsightBundle.message("error.dialog.readonly.file.title"), Messages.getErrorIcon());
        return;
    }

    final Runnable[] resultRunnable = new Runnable[1];
    Runnable readAction = new Runnable() {
        @Override
        public void run() {
            if (!checkFileWritable(file))
                return;
            try {
                resultRunnable[0] = preprocessFile(file, myProcessChangedTextOnly);
            } catch (IncorrectOperationException e) {
                LOG.error(e);
            }
        }
    };
    Runnable writeAction = new Runnable() {
        @Override
        public void run() {
            if (resultRunnable[0] != null) {
                resultRunnable[0].run();
            }
        }
    };
    runLayoutCodeProcess(readAction, writeAction, false);
}

From source file:com.intellij.codeInsight.daemon.impl.quickfix.FetchExtResourceAction.java

License:Apache License

protected boolean resultIsValid(final Project project, ProgressIndicator indicator, final String resourceUrl,
        FetchResult result) {/*  ww  w.j  a  va 2s .c  om*/
    if (myForceResultIsValid) {
        return true;
    }
    if (!ApplicationManager.getApplication().isUnitTestMode() && result.contentType != null
            && result.contentType.contains(HTML_MIME) && new String(result.bytes).contains("<html")) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
                Messages.showMessageDialog(project,
                        XmlBundle.message("invalid.url.no.xml.file.at.location", resourceUrl),
                        XmlBundle.message("invalid.url.title"), Messages.getErrorIcon());
            }
        }, indicator.getModalityState());
        return false;
    }
    return true;
}

From source file:com.intellij.codeInsight.daemon.impl.quickfix.FetchExtResourceAction.java

License:Apache License

@Nullable
private static FetchResult fetchData(final Project project, final String dtdUrl,
        final ProgressIndicator indicator) throws IOException {
    try {//w ww  . j  a v a2  s .  c  o  m
        return HttpRequests.request(dtdUrl).accept("text/xml,application/xml,text/html,*/*")
                .connect(new HttpRequests.RequestProcessor<FetchResult>() {
                    @Override
                    public FetchResult process(@Nonnull HttpRequests.Request request) throws IOException {
                        FetchResult result = new FetchResult();
                        result.bytes = request.readBytes(indicator);
                        result.contentType = request.getConnection().getContentType();
                        return result;
                    }
                });
    } catch (MalformedURLException e) {
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                @Override
                public void run() {
                    Messages.showMessageDialog(project, XmlBundle.message("invalid.url.message", dtdUrl),
                            XmlBundle.message("invalid.url.title"), Messages.getErrorIcon());
                }
            }, indicator.getModalityState());
        }
    }

    return null;
}

From source file:com.intellij.codeInsight.generation.GenerateConstructorHandler.java

License:Apache License

@Override
@Nullable/*from   w w  w.  jav  a2  s .c  o m*/
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
    if (aClass instanceof PsiAnonymousClass) {
        Messages.showMessageDialog(project,
                CodeInsightBundle.message("error.attempt.to.generate.constructor.for.anonymous.class"),
                CommonBundle.getErrorTitle(), Messages.getErrorIcon());
        return null;
    }

    myCopyJavadoc = false;
    PsiMethod[] baseConstructors = null;
    PsiClass baseClass = aClass.getSuperClass();
    if (baseClass != null) {
        ArrayList<PsiMethod> array = new ArrayList<PsiMethod>();
        for (PsiMethod method : baseClass.getConstructors()) {
            if (JavaPsiFacade.getInstance(method.getProject()).getResolveHelper().isAccessible(method, aClass,
                    null)) {
                array.add(method);
            }
        }
        if (!array.isEmpty()) {
            if (array.size() == 1) {
                baseConstructors = new PsiMethod[] { array.get(0) };
            } else {
                final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(baseClass,
                        aClass, PsiSubstitutor.EMPTY);
                PsiMethodMember[] constructors = ContainerUtil.map2Array(array, PsiMethodMember.class,
                        new Function<PsiMethod, PsiMethodMember>() {
                            @Override
                            public PsiMethodMember fun(final PsiMethod s) {
                                return new PsiMethodMember(s, substitutor);
                            }
                        });
                MemberChooser<PsiMethodMember> chooser = new MemberChooser<PsiMethodMember>(constructors, false,
                        true, project);
                chooser.setTitle(
                        CodeInsightBundle.message("generate.constructor.super.constructor.chooser.title"));
                chooser.show();
                List<PsiMethodMember> elements = chooser.getSelectedElements();
                if (elements == null || elements.isEmpty())
                    return null;
                baseConstructors = new PsiMethod[elements.size()];
                for (int i = 0; i < elements.size(); i++) {
                    final ClassMember member = elements.get(i);
                    baseConstructors[i] = ((PsiMethodMember) member).getElement();
                }
                myCopyJavadoc = chooser.isCopyJavadoc();
            }
        }
    }

    ClassMember[] allMembers = getAllOriginalMembers(aClass);
    ClassMember[] members;
    if (allMembers.length == 0) {
        members = ClassMember.EMPTY_ARRAY;
    } else {
        members = chooseMembers(allMembers, true, false, project, null);
        if (members == null)
            return null;
    }
    if (baseConstructors != null) {
        ArrayList<ClassMember> array = new ArrayList<ClassMember>();
        for (PsiMethod baseConstructor : baseConstructors) {
            array.add(new PsiMethodMember(baseConstructor));
        }
        ContainerUtil.addAll(array, members);
        members = array.toArray(new ClassMember[array.size()]);
    }

    return members;
}

From source file:com.intellij.codeInsight.intention.impl.ImplementAbstractMethodHandler.java

License:Apache License

public void invoke() {
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    final PsiElement[][] result = new PsiElement[1][];
    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        @Override/*from w w  w .j ava 2  s .  c  om*/
        public void run() {
            ApplicationManager.getApplication().runReadAction(new Runnable() {
                @Override
                public void run() {
                    final PsiClass psiClass = myMethod.getContainingClass();
                    if (!psiClass.isValid())
                        return;
                    if (!psiClass.isEnum()) {
                        result[0] = getClassImplementations(psiClass);
                    } else {
                        final List<PsiElement> enumConstants = new ArrayList<PsiElement>();
                        for (PsiField field : psiClass.getFields()) {
                            if (field instanceof PsiEnumConstant) {
                                final PsiEnumConstantInitializer initializingClass = ((PsiEnumConstant) field)
                                        .getInitializingClass();
                                if (initializingClass != null) {
                                    PsiMethod method = initializingClass.findMethodBySignature(myMethod, true);
                                    if (method == null
                                            || !method.getContainingClass().equals(initializingClass)) {
                                        enumConstants.add(initializingClass);
                                    }
                                } else {
                                    enumConstants.add(field);
                                }
                            }
                        }
                        result[0] = PsiUtilCore.toPsiElementArray(enumConstants);
                    }
                }
            });
        }
    }, CodeInsightBundle.message("intention.implement.abstract.method.searching.for.descendants.progress"),
            true, myProject);

    if (result[0] == null)
        return;

    if (result[0].length == 0) {
        Messages.showMessageDialog(myProject,
                CodeInsightBundle.message("intention.implement.abstract.method.error.no.classes.message"),
                CodeInsightBundle.message("intention.implement.abstract.method.error.no.classes.title"),
                Messages.getInformationIcon());
        return;
    }

    if (result[0].length == 1) {
        implementInClass(new Object[] { result[0][0] });
        return;
    }

    final MyPsiElementListCellRenderer elementListCellRenderer = new MyPsiElementListCellRenderer();
    elementListCellRenderer.sort(result[0]);
    myList = new JBList(result[0]);
    myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final Runnable runnable = new Runnable() {
        @Override
        public void run() {
            int index = myList.getSelectedIndex();
            if (index < 0)
                return;
            implementInClass(myList.getSelectedValues());
        }
    };
    myList.setCellRenderer(elementListCellRenderer);
    final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
    elementListCellRenderer.installSpeedSearch(builder);

    builder.setTitle(CodeInsightBundle.message("intention.implement.abstract.method.class.chooser.title"))
            .setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(myEditor);
}

From source file:com.intellij.codeInspection.dataFlow.MethodCheckerDetailsDialog.java

License:Apache License

private boolean overlaps(ConditionChecker thisChecker) {
    for (ConditionChecker overlappingChecker : myOtherCheckers) {
        if (thisChecker.overlaps(overlappingChecker)) {
            Messages.showMessageDialog(myProject,
                    InspectionsBundle.message("configure.checker.option.overlap.error.msg") + " "
                            + overlappingChecker.getConditionCheckType() + " " + overlappingChecker.toString(),
                    InspectionsBundle.message("configure.checker.option.overlap.error.title"),
                    Messages.getErrorIcon());
            return true;
        }/*from  w  ww .  j  ava  2 s  .c o  m*/
    }
    return false;
}

From source file:com.intellij.codeInspection.ex.GlobalJavaInspectionContextImpl.java

License:Apache License

@SuppressWarnings({ "UseOfSystemOutOrSystemErr" })
public static boolean isInspectionsEnabled(final boolean online, @NotNull Project project) {
    final Module[] modules = ModuleManager.getInstance(project).getModules();
    if (online) {
        if (modules.length == 0) {
            Messages.showMessageDialog(project,
                    InspectionsBundle.message("inspection.no.modules.error.message"),
                    CommonBundle.message("title.error"), Messages.getErrorIcon());
            return false;
        }// w w w .  jav  a  2 s . c o m
        while (isBadSdk(project, modules)) {
            Messages.showMessageDialog(project, InspectionsBundle.message("inspection.no.jdk.error.message"),
                    CommonBundle.message("title.error"), Messages.getErrorIcon());
            final Sdk projectJdk = ProjectSettingsService.getInstance(project).chooseAndSetSdk();
            if (projectJdk == null)
                return false;
        }
    } else {
        if (modules.length == 0) {
            System.err.println(InspectionsBundle.message("inspection.no.modules.error.message"));
            return false;
        }
        if (isBadSdk(project, modules)) {
            System.err.println(InspectionsBundle.message("inspection.no.jdk.error.message"));
            System.err.println(InspectionsBundle.message("offline.inspections.jdk.not.found",
                    ""/*ProjectRootManager.getInstance(project).getProjectSdkName()*/));
            return false;
        }
        for (Module module : modules) {
            final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
            final OrderEntry[] entries = rootManager.getOrderEntries();
            for (OrderEntry entry : entries) {
                if (entry instanceof SdkOrderEntry) {
                    if (/*!ModuleType.get(module).isValidSdk(module, null)*/Boolean.FALSE) {
                        System.err.println(InspectionsBundle.message("offline.inspections.module.jdk.not.found",
                                ((SdkOrderEntry) entry).getSdkName(), module.getName()));
                        return false;
                    }
                } else if (entry instanceof LibraryOrderEntry) {
                    final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
                    final Library library = libraryOrderEntry.getLibrary();
                    if (library == null || library.getFiles(OrderRootType.CLASSES).length < library
                            .getUrls(OrderRootType.CLASSES).length) {
                        System.err.println(
                                InspectionsBundle.message("offline.inspections.library.was.not.resolved",
                                        libraryOrderEntry.getPresentableName(), module.getName()));
                    }
                }
            }
        }
    }
    return true;
}

From source file:com.intellij.codeInspection.export.HTMLExportUtil.java

License:Apache License

public static void writeFile(final String folder, @NonNls final String fileName, CharSequence buf,
        final Project project) {
    try {//from  w w w .ja  v  a  2 s  .c o  m
        HTMLExporter.writeFileImpl(folder, fileName, buf);
    } catch (IOException e) {
        Runnable showError = new Runnable() {
            @Override
            public void run() {
                final String fullPath = folder + File.separator + fileName;
                Messages.showMessageDialog(project,
                        InspectionsBundle.message("inspection.export.error.writing.to", fullPath),
                        InspectionsBundle.message("inspection.export.results.error.title"),
                        Messages.getErrorIcon());
            }
        };
        ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL);
        throw new ProcessCanceledException();
    }
}

From source file:com.intellij.codeInspection.export.HTMLExportUtil.java

License:Apache License

public static void runExport(final Project project, @NotNull ThrowableRunnable<IOException> runnable) {
    try {/*from  w ww . j a  va  2  s . c  o m*/
        runnable.run();
    } catch (IOException e) {
        Runnable showError = new Runnable() {
            @Override
            public void run() {
                Messages.showMessageDialog(project,
                        InspectionsBundle.message("inspection.export.error.writing.to", "export file"),
                        InspectionsBundle.message("inspection.export.results.error.title"),
                        Messages.getErrorIcon());
            }
        };
        ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL);
        throw new ProcessCanceledException();
    }
}