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

    @NonNls List<String> parameters = new LinkedList<>();

    final String url = dialog.getUrl().getText();
    final VirtualFile relativeFile = VfsUtilCore.findRelativeFile(ExternalResourceManager.getInstance().getResourceLocation(url), null);
    if (relativeFile == null) {
      Messages.showErrorDialog(project, XmlBundle.message("file.doesnt.exist", url), XmlBundle.message("error"));
      return;
    }
    final PsiFile file = PsiManager.getInstance(project).findFile(relativeFile);
    if (!(file instanceof XmlFile)) {
      Messages.showErrorDialog(project, " (" + file.getFileType().getDescription() + ")", XmlBundle.message("error"));
      return;
    }

    VirtualFile 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");
    }
    parameters.add("-dl");

    String pathToUse;

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

      pathToUse = tempDir.getPath() + File.separatorChar + Xsd2InstanceUtils.processAndSaveAllSchemas(
        (XmlFile)file,
        new HashMap<>(),
        new Xsd2InstanceUtils.SchemaReferenceProcessor() {
          @Override
          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(ArrayUtilRt.toStringArray(parameters));
    }
    catch (Throwable e) {
      Messages.showErrorDialog(project, ExceptionUtil.getMessage(e), XmlBundle.message("error"));
      return;
    }

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

    try {
      // the generated XML doesn't have any XML declaration -> utf-8
      final File xmlFile = new File(xmlFileName);
      FileUtil.writeToFile(xmlFile, xml);

      VirtualFile virtualFile =
        WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xmlFile));
      FileEditorManager.getInstance(project).openFile(virtualFile, true);
    }
    catch (IOException e) {
      Messages.showErrorDialog(project, XmlBundle.message("could.not.save.generated.xml.document.0", StringUtil.getMessage(e)),
                               XmlBundle.message("error"));
    }
  }
public static void doAction(final Project project, final GenerateInstanceDocumentFromSchemaDialog dialog)