@Override
  public void updateDataModel() {

    myWizardContext.setProjectBuilder(myModuleBuilder);
    myWizardContext.setProjectName(myNamePathComponent.getNameValue());
    myWizardContext.setProjectFileDirectory(myNamePathComponent.getPath());
    myFormatPanel.updateData(myWizardContext);

    if (myModuleBuilder != null) {
      final String moduleName = getModuleName();
      myModuleBuilder.setName(moduleName);
      myModuleBuilder.setModuleFilePath(
          FileUtil.toSystemIndependentName(myModuleFileLocation.getText())
              + "/"
              + moduleName
              + ModuleFileType.DOT_DEFAULT_EXTENSION);
      myModuleBuilder.setContentEntryPath(FileUtil.toSystemIndependentName(getModuleContentRoot()));
      if (myModuleBuilder instanceof TemplateModuleBuilder) {
        myWizardContext.setProjectStorageFormat(StorageScheme.DIRECTORY_BASED);
      }
    }

    if (mySettingsStep != null) {
      mySettingsStep.updateDataModel();
    }
  }
 private static NamePathComponent initNamePathComponent(WizardContext context) {
   NamePathComponent component =
       new NamePathComponent(
           IdeBundle.message("label.project.name"),
           IdeBundle.message("label.project.files.location"),
           IdeBundle.message(
               "title.select.project.file.directory",
               IdeBundle.message("project.new.wizard.project.identification")),
           IdeBundle.message(
               "description.select.project.file.directory",
               StringUtil.capitalize(
                   IdeBundle.message("project.new.wizard.project.identification"))),
           true,
           false);
   final String baseDir = context.getProjectFileDirectory();
   final String projectName = context.getProjectName();
   final String initialProjectName =
       projectName != null
           ? projectName
           : ProjectWizardUtil.findNonExistingFileName(baseDir, "untitled", "");
   component.setPath(
       projectName == null ? (baseDir + File.separator + initialProjectName) : baseDir);
   component.setNameValue(initialProjectName);
   component.getNameComponent().select(0, initialProjectName.length());
   return component;
 }
  @Override
  public boolean validate() throws ConfigurationException {
    ProjectTemplate template = getSelectedTemplate();
    if (template == null) {
      throw new ConfigurationException(
          StringUtil.capitalize(
              ProjectBundle.message(
                  "project.new.wizard.from.template.error", myWizardContext.getPresentationName())),
          "Error");
    }

    if (myWizardContext.isCreatingNewProject()) {
      if (!myNamePathComponent.validateNameAndPath(myWizardContext, myFormatPanel.isDefault()))
        return false;
    }

    if (!validateModulePaths()) return false;
    if (!myWizardContext.isCreatingNewProject()) {
      validateExistingModuleName();
    }

    ValidationInfo info = template.validateSettings();
    if (info != null) {
      throw new ConfigurationException(info.message, "Error");
    }
    if (mySettingsStep != null) {
      return mySettingsStep.validate();
    }
    return true;
  }
 private String getDefaultBaseDir(WizardContext wizardContext) {
   if (wizardContext.isCreatingNewProject()) {
     return myNamePathComponent.getPath();
   } else {
     final Project project = wizardContext.getProject();
     assert project != null;
     final VirtualFile baseDir = project.getBaseDir();
     if (baseDir != null) {
       return baseDir.getPath();
     }
     return "";
   }
 }
  public void bindModuleSettings() {

    myNamePathComponent
        .getNameComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myModuleNameChangedByUser) {
                  setModuleName(myNamePathComponent.getNameValue());
                }
              }
            });

    myModuleContentRoot.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);

    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myContentRootChangedByUser) {
                  setModuleContentRoot(myNamePathComponent.getPath());
                }
              }
            });
    myModuleName
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myModuleNameDocListenerEnabled) {
                  myModuleNameChangedByUser = true;
                }
                String path = getDefaultBaseDir(myWizardContext);
                final String moduleName = getModuleName();
                if (path.length() > 0
                    && !Comparing.strEqual(moduleName, myNamePathComponent.getNameValue())) {
                  path += "/" + moduleName;
                }
                if (!myContentRootChangedByUser) {
                  final boolean f = myModuleNameChangedByUser;
                  myModuleNameChangedByUser = true;
                  setModuleContentRoot(path);
                  myModuleNameChangedByUser = f;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(path);
                }
              }
            });
    myModuleContentRoot
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myContentRootDocListenerEnabled) {
                  myContentRootChangedByUser = true;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(getModuleContentRoot());
                }
                if (!myModuleNameChangedByUser) {
                  final String path = FileUtil.toSystemIndependentName(getModuleContentRoot());
                  final int idx = path.lastIndexOf("/");

                  boolean f = myContentRootChangedByUser;
                  myContentRootChangedByUser = true;

                  boolean i = myImlLocationChangedByUser;
                  myImlLocationChangedByUser = true;

                  setModuleName(idx >= 0 ? path.substring(idx + 1) : "");

                  myContentRootChangedByUser = f;
                  myImlLocationChangedByUser = i;
                }
              }
            });

    myModuleFileLocation.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.file.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.file.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    myModuleFileLocation
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myImlLocationDocListenerEnabled) {
                  myImlLocationChangedByUser = true;
                }
              }
            });
    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myNamePathComponent.getPath());
                }
              }
            });
    if (myWizardContext.isCreatingNewProject()) {
      setModuleName(myNamePathComponent.getNameValue());
      setModuleContentRoot(myNamePathComponent.getPath());
      setImlFileLocation(myNamePathComponent.getPath());
    } else {
      final Project project = myWizardContext.getProject();
      assert project != null;
      VirtualFile baseDir = project.getBaseDir();
      if (baseDir != null) { // e.g. was deleted
        final String baseDirPath = baseDir.getPath();
        String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", "");
        String contentRoot = baseDirPath + "/" + moduleName;
        if (!Comparing.strEqual(project.getName(), myWizardContext.getProjectName())
            && !myWizardContext.isCreatingNewProject()
            && myWizardContext.getProjectName() != null) {
          moduleName =
              ProjectWizardUtil.findNonExistingFileName(
                  myWizardContext.getProjectFileDirectory(), myWizardContext.getProjectName(), "");
          contentRoot = myWizardContext.getProjectFileDirectory();
        }
        setModuleName(moduleName);
        setModuleContentRoot(contentRoot);
        setImlFileLocation(contentRoot);
        myModuleName.select(0, moduleName.length());
      }
    }
  }
 private JTextField getNameComponent() {
   return myWizardContext.isCreatingNewProject()
       ? myNamePathComponent.getNameComponent()
       : myModuleName;
 }