@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;
 }
 public void updateStep() {
   if (!myRootPathComponent.isPathChangedByUser()) {
     final VirtualFile rootDirectory = getBuilder().getRootDirectory();
     final String path;
     if (rootDirectory != null) {
       path = rootDirectory.getPath();
     } else {
       path = getWizardContext().getProjectFileDirectory();
     }
     myRootPathComponent.setPath(FileUtil.toSystemDependentName(path));
     myRootPathComponent.getPathComponent().selectAll();
   }
   myImportingSettingsForm.setData(getImportingSettings());
 }
  @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;
  }
 public void updateDataModel() {
   MavenImportingSettings settings = getImportingSettings();
   myImportingSettingsForm.getData(settings);
   if (getWizardContext().isCreatingNewProject()) {
     myImportingSettingsForm.updateData(getWizardContext());
   }
   suggestProjectNameAndPath(settings.getDedicatedModuleDir(), myRootPathComponent.getPath());
 }
  public MavenProjectImportStep(WizardContext wizardContext) {
    super(wizardContext);

    myImportingSettingsForm =
        new MavenImportingSettingsForm(true, wizardContext.isCreatingNewProject()) {
          public String getDefaultModuleDir() {
            return myRootPathComponent.getPath();
          }
        };

    myRootPathComponent =
        new NamePathComponent(
            "",
            ProjectBundle.message("maven.import.label.select.root"),
            ProjectBundle.message("maven.import.title.select.root"),
            "",
            false,
            false);

    JButton envSettingsButton =
        new JButton(ProjectBundle.message("maven.import.environment.settings"));
    envSettingsButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ShowSettingsUtil.getInstance()
                .editConfigurable(myPanel, new MavenEnvironmentConfigurable());
          }
        });

    myPanel = new JPanel(new GridBagLayout());
    myPanel.setBorder(BorderFactory.createEtchedBorder());

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = JBUI.insets(4, 4, 0, 4);

    myPanel.add(myRootPathComponent, c);

    c.gridy = 1;
    c.insets = JBUI.insets(4, 4, 0, 4);
    myPanel.add(myImportingSettingsForm.createComponent(), c);

    c.gridy = 2;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.weighty = 1;
    c.insets = JBUI.insets(4 + envSettingsButton.getPreferredSize().height, 4, 4, 4);
    myPanel.add(envSettingsButton, c);

    myRootPathComponent.setNameComponentVisible(false);
  }
 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 JComponent getPreferredFocusedComponent() {
   return myRootPathComponent.getPathComponent();
 }
 public boolean validate() throws ConfigurationException {
   updateDataModel(); // needed to make 'exhaustive search' take an effect.
   return getBuilder()
       .setRootDirectory(getWizardContext().getProject(), myRootPathComponent.getPath());
 }
  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;
 }