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.uiDesigner.quickFixes.CreateFieldFix.java

License:Apache License

/**
 * @param showErrors if <code>true</code> the error messages will be shown to the
 * @param undoGroupId the group used to undo the action together with some other action.
 *///from  ww  w.j  a  va2 s .c  o  m
public static void runImpl(@NotNull final Project project, @NotNull final RadContainer rootContainer,
        @NotNull final PsiClass boundClass, @NotNull final String fieldClassName,
        @NotNull final String fieldName, final boolean showErrors, @Nullable final Object undoGroupId) {
    ApplicationManager.getApplication().assertReadAccessAllowed();

    PsiDocumentManager.getInstance(project).commitAllDocuments();

    // Do nothing if file becomes invalid
    if (!boundClass.isValid()) {
        return;
    }

    if (!boundClass.isWritable()) {
        if (showErrors) {
            if (!CommonRefactoringUtil.checkReadOnlyStatus(boundClass, project,
                    UIDesignerBundle.message("error.cannot.create.field", fieldClassName))) {
                return;
            }
        } else
            return;
    }

    final PsiClass fieldClass = JavaPsiFacade.getInstance(project).findClass(fieldClassName.replace('$', '.'),
            GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(rootContainer.getModule()));
    if (fieldClass == null) {
        if (showErrors) {
            Messages.showErrorDialog(project,
                    UIDesignerBundle.message("error.cannot.create.field.no.class", fieldName, fieldClassName),
                    CommonBundle.getErrorTitle());
        }
        return;
    }

    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                public void run() {
                    createField(project, fieldClass, fieldName, boundClass, showErrors, rootContainer);
                }
            });
        }
    }, UIDesignerBundle.message("command.create.field"), undoGroupId);
}

From source file:com.intellij.uiDesigner.quickFixes.CreateFieldFix.java

License:Apache License

private static void createField(final Project project, final PsiClass fieldClass, final String fieldName,
        final PsiClass boundClass, final boolean showErrors, final IContainer rootContainer) {
    // 1. Create field
    final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
    final PsiType type = factory.createType(fieldClass);
    try {//from  w  ww . j  a  v a2 s. c o  m
        final PsiField field = factory.createField(fieldName, type);
        final String accessibility = GuiDesignerConfiguration.getInstance(project).DEFAULT_FIELD_ACCESSIBILITY;
        final PsiModifierList modifierList = field.getModifierList();
        assert modifierList != null;
        String[] modifiers = { PsiModifier.PRIVATE, PsiModifier.PROTECTED, PsiModifier.PUBLIC };
        for (@PsiModifier.ModifierConstant
        String modifier : modifiers) {
            modifierList.setModifierProperty(modifier, accessibility.equals(modifier));
        }
        PsiField lastUiField = null;
        for (PsiField uiField : boundClass.getFields()) {
            if (FormEditingUtil.findComponentWithBinding(rootContainer, uiField.getName()) != null) {
                lastUiField = uiField;
            }
        }
        if (lastUiField != null) {
            boundClass.addAfter(field, lastUiField);
        } else {
            boundClass.add(field);
        }
    } catch (final IncorrectOperationException exc) {
        if (showErrors) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {
                public void run() {
                    Messages.showErrorDialog(project, UIDesignerBundle
                            .message("error.cannot.create.field.reason", fieldName, exc.getMessage()),
                            CommonBundle.getErrorTitle());
                }
            });
        }
    }
}

From source file:com.intellij.uiDesigner.snapShooter.CreateSnapShotAction.java

License:Apache License

private static void runSnapShooterSession(final SnapShotClient client, final Project project,
        final PsiDirectory dir, final IdeView view) {
    try {/*from  www . j a  v a  2  s  .c om*/
        client.suspendSwing();
    } catch (IOException e1) {
        Messages.showMessageDialog(project, UIDesignerBundle.message("snapshot.connection.error"),
                UIDesignerBundle.message("snapshot.title"), Messages.getInformationIcon());
        return;
    }

    final MyDialog dlg = new MyDialog(project, client, dir);
    dlg.show();
    if (dlg.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        final int id = dlg.getSelectedComponentId();
        final Ref<Object> result = new Ref<Object>();
        ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
            public void run() {
                try {
                    result.set(client.createSnapshot(id));
                } catch (Exception ex) {
                    result.set(ex);
                }
            }
        }, UIDesignerBundle.message("progress.creating.snapshot"), false, project);

        String snapshot = null;
        if (result.get() instanceof String) {
            snapshot = (String) result.get();
        } else {
            Exception ex = (Exception) result.get();
            Messages.showMessageDialog(project,
                    UIDesignerBundle.message("snapshot.create.error", ex.getMessage()),
                    UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
        }

        if (snapshot != null) {
            final String snapshot1 = snapshot;
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                public void run() {
                    CommandProcessor.getInstance().executeCommand(project, new Runnable() {
                        public void run() {
                            try {
                                PsiFile formFile = PsiFileFactory.getInstance(dir.getProject())
                                        .createFileFromText(
                                                dlg.getFormName() + GuiFormFileType.DOT_DEFAULT_EXTENSION,
                                                snapshot1);
                                formFile = (PsiFile) dir.add(formFile);
                                formFile.getVirtualFile().setCharset(CharsetToolkit.UTF8_CHARSET);
                                formFile.getViewProvider().getDocument().setText(snapshot1);
                                view.selectElement(formFile);
                            } catch (IncorrectOperationException ex) {
                                Messages.showMessageDialog(project,
                                        UIDesignerBundle.message("snapshot.save.error", ex.getMessage()),
                                        UIDesignerBundle.message("snapshot.title"), Messages.getErrorIcon());
                            }
                        }
                    }, "", null);
                }
            });
        }
    }

    try {
        client.resumeSwing();
    } catch (IOException ex) {
        Messages.showErrorDialog(project, UIDesignerBundle.message("snapshot.connection.broken"),
                UIDesignerBundle.message("snapshot.title"));
    }

    client.dispose();
}

From source file:com.intellij.uiDesigner.wizard.DataBindingWizard.java

License:Apache License

protected void doOKAction() {
    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                public void run() {
                    try {
                        Generator.generateDataBindingMethods(myData);
                        DataBindingWizard.super.doOKAction();
                    } catch (Generator.MyException exc) {
                        Messages.showErrorDialog(getContentPane(), exc.getMessage(),
                                CommonBundle.getErrorTitle());
                    }//from  w  ww .  ja v  a  2  s .co  m
                }
            });
        }
    }, "", null);
}

From source file:com.intellij.vcsUtil.VcsImplUtil.java

License:Apache License

/**
 * Shows error message with specified message text and title.
 * The parent component is the root frame.
 *
 * @param project Current project component
 * @param message information message//from w ww.j a va  2  s  .c o  m
 * @param title   Dialog title
 */
public static void showErrorMessage(final Project project, final String message, final String title) {
    Runnable task = new Runnable() {
        public void run() {
            Messages.showErrorDialog(project, message, title);
        }
    };
    WaitForProgressToShow.runOrInvokeLaterAboveProgress(task, null, project);
}

From source file:com.intellij.xml.actions.xmlbeans.GenerateInstanceDocumentFromSchemaAction.java

License:Apache License

private void doAction(final Project project, final GenerateInstanceDocumentFromSchemaDialog dialog) {
    FileDocumentManager.getInstance().saveAllDocuments();

    @NonNls//from  w w  w  .jav  a 2s. co m
    List<String> parameters = new LinkedList<String>();

    final String url = dialog.getUrl().getText();
    final VirtualFile relativeFile = VfsUtil
            .findRelativeFile(ExternalResourceManager.getInstance().getResourceLocation(url), null);
    final PsiFile file = PsiManager.getInstance(project).findFile(relativeFile);
    if (!(file instanceof XmlFile)) {
        Messages.showErrorDialog(project,
                "This is not XmlFile" + file == null ? "" : " (" + file.getFileType().getName() + ")",
                XmlBundle.message("error"));
        return;
    }

    VirtualFile relativeFileDir;
    if (relativeFile == null) {
        Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url),
                XmlBundle.message("error"));
        return;
    } else {
        relativeFileDir = relativeFile.getParent();
    }
    if (relativeFileDir == null) {
        Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url),
                XmlBundle.message("error"));
        return;
    }

    if (!dialog.enableRestrictionCheck()) {
        parameters.add("-nopvr");
    }

    if (!dialog.enableUniquenessCheck()) {
        parameters.add("-noupa");
    }

    String pathToUse;

    try {
        final File tempDir = FileUtil.createTempFile("xsd2inst", "");
        tempDir.delete();
        tempDir.mkdir();

        pathToUse = tempDir.getPath() + File.separatorChar
                + Xsd2InstanceUtils.processAndSaveAllSchemas((XmlFile) file, new THashMap<String, String>(),
                        new Xsd2InstanceUtils.SchemaReferenceProcessor() {
                            public void processSchema(String schemaFileName, byte[] schemaContent) {
                                try {
                                    final String fullFileName = tempDir.getPath() + File.separatorChar
                                            + schemaFileName;
                                    FileUtils.saveStreamContentAsFile(fullFileName,
                                            new ByteArrayInputStream(schemaContent));
                                } catch (IOException e) {
                                    throw new RuntimeException(e);
                                }
                            }
                        });
    } catch (IOException e) {
        return;
    }

    parameters.add(pathToUse);

    parameters.add("-name");
    parameters.add(dialog.getElementName());

    String xml;
    try {
        xml = Xsd2InstanceUtils.generate(ArrayUtil.toStringArray(parameters));
    } catch (IllegalArgumentException e) {
        Messages.showErrorDialog(project, StringUtil.getMessage(e), XmlBundle.message("error"));
        return;
    }

    final VirtualFile baseDirForCreatedInstanceDocument1 = relativeFileDir;
    String xmlFileName = baseDirForCreatedInstanceDocument1.getPath() + File.separatorChar
            + dialog.getOutputFileName();

    FileOutputStream fileOutputStream;
    try {
        fileOutputStream = new FileOutputStream(xmlFileName);
        try {
            // the generated XML doesn't have any XML declaration -> utf-8
            fileOutputStream.write(xml.getBytes("utf-8"));
        } finally {
            fileOutputStream.close();
        }

        final File xmlFile = new File(xmlFileName);
        VirtualFile virtualFile = ApplicationManager.getApplication()
                .runWriteAction(new Computable<VirtualFile>() {
                    @Nullable
                    public VirtualFile compute() {
                        return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xmlFile);
                    }
                });
        FileEditorManager.getInstance(project).openFile(virtualFile, true);
    } catch (IOException e) {
        Messages.showErrorDialog(project, "Could not save generated XML document: " + StringUtil.getMessage(e),
                XmlBundle.message("error"));
    }
}

From source file:com.intellij.xml.actions.xmlbeans.GenerateSchemaFromInstanceDocumentAction.java

License:Apache License

private static void doAction(final Project project, final GenerateSchemaFromInstanceDocumentDialog dialog) {
    FileDocumentManager.getInstance().saveAllDocuments();

    final String url = dialog.getUrl().getText();
    final VirtualFile relativeFile = VfsUtil
            .findRelativeFile(ExternalResourceManager.getInstance().getResourceLocation(url), null);
    VirtualFile relativeFileDir;/*from  www .j  a v  a 2  s  .  c om*/
    if (relativeFile == null) {
        Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url),
                XmlBundle.message("error"));
        return;
    } else {
        relativeFileDir = relativeFile.getParent();
    }
    if (relativeFileDir == null) {
        Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url),
                XmlBundle.message("error"));
        return;
    }

    @NonNls
    List<String> parameters = new LinkedList<String>();
    parameters.add("-design");
    parameters.add(DESIGN_TYPES.get(dialog.getDesignType()));

    parameters.add("-simple-content-types");
    parameters.add(CONTENT_TYPES.get(dialog.getSimpleContentType()));

    parameters.add("-enumerations");
    String enumLimit = dialog.getEnumerationsLimit();
    parameters.add("0".equals(enumLimit) ? "never" : enumLimit);

    parameters.add("-outDir");
    final String dirPath = relativeFileDir.getPath();
    parameters.add(dirPath);

    final File expectedSchemaFile = new File(dirPath + File.separator + relativeFile.getName() + "0.xsd");
    if (expectedSchemaFile.exists()) {
        if (!expectedSchemaFile.delete()) {
            Messages.showErrorDialog(project,
                    XmlBundle.message("cant.delete.file", expectedSchemaFile.getPath()),
                    XmlBundle.message("error"));
            return;
        }
    }

    parameters.add("-outPrefix");
    parameters.add(relativeFile.getName());

    parameters.add(url);
    File xsd = new File(dirPath + File.separator + dialog.getTargetSchemaName());
    final VirtualFile xsdFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xsd);
    if (xsdFile != null) {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
            public void run() {
                try {
                    xsdFile.delete(null);
                } catch (IOException e) {//
                }
            }
        });
    }

    Inst2Xsd.main(ArrayUtil.toStringArray(parameters));
    if (expectedSchemaFile.exists()) {
        final boolean renamed = expectedSchemaFile.renameTo(xsd);
        if (!renamed) {
            Messages.showErrorDialog(project,
                    XmlBundle.message("cant.rename.file", expectedSchemaFile.getPath(), xsd.getPath()),
                    XmlBundle.message("error"));
        }
    }

    VirtualFile xsdVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xsd);
    if (xsdVFile != null) {
        FileEditorManager.getInstance(project).openFile(xsdVFile, true);
    } else {
        Messages.showErrorDialog(project, XmlBundle.message("xml2xsd.generator.error.message"),
                XmlBundle.message("xml2xsd.generator.error"));
    }

}

From source file:com.jetbrains.flask.project.FlaskProjectGenerator.java

License:Apache License

private static void createFlaskMain(final Module module, final VirtualFile baseDir) {
    final Project project = module.getProject();
    final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
    new WriteCommandAction.Simple(project) {
        @Override//ww w  . ja va2s  .  co m
        protected void run() throws Throwable {
            FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate("Flask Main");
            PsiFile appFile;
            try {
                appFile = (PsiFile) FileTemplateUtil.createFromTemplate(template, baseDir.getName() + ".py",
                        null, projectDir);
            } catch (Exception e) {
                Messages.showErrorDialog(project, "Error creating Flask application: " + e.getMessage(),
                        "Create Flask Project");
                return;
            }
            projectDir.createSubdirectory("static");
            PsiDirectory templates = projectDir.createSubdirectory(FlaskNames.TEMPLATES);
            FlaskProjectConfigurator.createFlaskRunConfiguration(module, appFile.getVirtualFile());
            TemplatesService templatesService = TemplatesService.getInstance(module);
            templatesService.setTemplateLanguage(TemplatesService.JINJA2);
            templatesService.setTemplateFolders(templates.getVirtualFile());
            appFile.navigate(true);
        }
    }.execute();
}

From source file:com.jetbrains.lang.dart.ide.refactoring.DartRenameHandler.java

License:Apache License

@Override
protected void doAction() {
    // Validate final status.
    {/*from   w  w w .  j  ava2 s. c  om*/
        final RefactoringStatus finalStatus = myRefactoring.checkFinalConditions();
        if (finalStatus.hasError()) {
            Messages.showErrorDialog(myProject, finalStatus.getMessage(), "Error");
            return;
        }
    }
    // Apply the change.
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
            final SourceChange change = myRefactoring.getChange();
            assert change != null;
            final Set<String> excludedIds = myRefactoring.getPotentialEdits();
            AssistUtils.applySourceChange(myProject, change, excludedIds);
            close(DialogWrapper.OK_EXIT_CODE);
        }
    });
}

From source file:com.jetbrains.lang.dart.ide.refactoring.ServerRefactoringDialog.java

License:Apache License

@Override
protected void doAction() {
    // Validate final status.
    {//from   w  ww  .  j a v a2  s  .  c o m
        final RefactoringStatus finalStatus = myRefactoring.checkFinalConditions();
        if (finalStatus == null) {
            return;
        }
        if (finalStatus.hasError()) {
            Messages.showErrorDialog(myProject, finalStatus.getMessage(), CommonBundle.getErrorTitle());
            return;
        }
    }

    if (hasPreviewButton() && isPreviewUsages() || isForcePreview()) {
        previewRefactoring();
    } else {
        doRefactoring(myRefactoring.getPotentialEdits());
    }

    close(DialogWrapper.OK_EXIT_CODE);
}