@Nullable
  ProjectBuilder runModuleWizard(Component dialogParent, boolean anImport) {
    AbstractProjectWizard wizard;
    if (anImport) {
      wizard = ImportModuleAction.selectFileAndCreateWizard(myProject, dialogParent);
      if (wizard == null) return null;
      if (wizard.getStepCount() == 0) {
        ProjectBuilder builder = wizard.getProjectBuilder();
        Disposer.dispose(wizard.getDisposable());
        return builder;
      }
    } else {
      wizard = new NewProjectWizard(myProject, dialogParent, this);
    }
    if (wizard.showAndGet()) {
      final ProjectBuilder builder = wizard.getProjectBuilder();
      if (builder instanceof ModuleBuilder) {
        final ModuleBuilder moduleBuilder = (ModuleBuilder) builder;
        if (moduleBuilder.getName() == null) {
          moduleBuilder.setName(wizard.getProjectName());
        }
        if (moduleBuilder.getModuleFilePath() == null) {
          moduleBuilder.setModuleFilePath(wizard.getModuleFilePath());
        }
      }
      if (!builder.validate(myProject, myProject)) {
        return null;
      }
      return wizard.getProjectBuilder();
    }

    return null;
  }
 @Nullable
 public List<Module> addModule(Component parent, boolean anImport) {
   if (myProject.isDefault()) return null;
   final ProjectBuilder builder = runModuleWizard(parent, anImport);
   if (builder != null) {
     final List<Module> modules = new ArrayList<Module>();
     final List<Module> commitedModules;
     if (builder instanceof ProjectImportBuilder<?>) {
       final ModifiableArtifactModel artifactModel =
           ProjectStructureConfigurable.getInstance(myProject)
               .getArtifactsStructureConfigurable()
               .getModifiableArtifactModel();
       commitedModules =
           ((ProjectImportBuilder<?>) builder)
               .commit(myProject, myModuleModel, this, artifactModel);
     } else {
       commitedModules = builder.commit(myProject, myModuleModel, this);
     }
     if (commitedModules != null) {
       modules.addAll(commitedModules);
     }
     ApplicationManager.getApplication()
         .runWriteAction(
             new Runnable() {
               @Override
               public void run() {
                 for (Module module : modules) {
                   getOrCreateModuleEditor(module);
                 }
               }
             });
     return modules;
   }
   return null;
 }
Beispiel #3
0
  public static List<Module> createFromWizard(Project project, AbstractProjectWizard wizard) {
    if (project == null && wizard.getStepCount() > 0) {
      Project newProject = NewProjectUtil.createFromWizard(wizard, null);
      return newProject == null
          ? Collections.<Module>emptyList()
          : Arrays.asList(ModuleManager.getInstance(newProject).getModules());
    }

    final ProjectBuilder projectBuilder = wizard.getProjectBuilder();
    try {
      if (wizard.getStepCount() > 0) {
        Module module = new NewModuleAction().createModuleFromWizard(project, null, wizard);
        return Collections.singletonList(module);
      } else {
        return projectBuilder.commit(project);
      }
    } finally {
      if (projectBuilder != null) {
        projectBuilder.cleanup();
      }
    }
  }