@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 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()); } } }