Search in sources :

Example 11 with ProjectBuilder

use of com.intellij.ide.util.projectWizard.ProjectBuilder in project moe-ide-integration by multi-os-engine.

the class MOENewModuleAction method createModuleFromWizard.

@Override
public Module createModuleFromWizard(Project project, @Nullable Object dataFromContext, AbstractProjectWizard wizard) {
    ProjectBuilder builder = wizard.getProjectBuilder();
    if (builder instanceof ModuleBuilder) {
        ModuleBuilder module = (ModuleBuilder) builder;
        if (module.getName() == null) {
            module.setName(wizard.getProjectName());
        }
        if (module.getModuleFilePath() == null) {
            module.setModuleFilePath(wizard.getModuleFilePath());
        } else {
            // TODO: get fake temp module to change with the correct one with info from wizard
            File tempModuleFile = new File(module.getModuleFilePath());
            String endOfFile = tempModuleFile.getName();
            File tempFolder = tempModuleFile.getParentFile();
            if (tempFolder != null && tempFolder.getParent() != null) {
                String correctedContentEntryPath = tempFolder.getParent() + File.separator + module.getName();
                String correctedModuleFilePath = correctedContentEntryPath + File.separator + endOfFile;
                ((ModuleBuilder) builder).setModuleFilePath(correctedModuleFilePath);
                ((ModuleBuilder) builder).setContentEntryPath(correctedContentEntryPath);
            }
        }
    }
    if (!builder.validate(project, project)) {
        return null;
    } else {
        Module module1;
        if (builder instanceof ModuleBuilder) {
            module1 = ((ModuleBuilder) builder).commitModule(project, (ModifiableModuleModel) null);
            if (module1 != null) {
                this.processCreatedModule(module1, dataFromContext);
            }
            return module1;
        } else {
            List modules = builder.commit(project, (ModifiableModuleModel) null, new DefaultModulesProvider(project));
            if (builder.isOpenProjectSettingsAfter()) {
                ModulesConfigurator.showDialog(project, (String) null, (String) null);
            }
            module1 = modules != null && !modules.isEmpty() ? (Module) modules.get(0) : null;
            project.save();
            return module1;
        }
    }
}
Also used : ProjectBuilder(com.intellij.ide.util.projectWizard.ProjectBuilder) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) DefaultModulesProvider(com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider) ModuleBuilder(com.intellij.ide.util.projectWizard.ModuleBuilder) List(java.util.List) Module(com.intellij.openapi.module.Module) File(java.io.File)

Aggregations

ProjectBuilder (com.intellij.ide.util.projectWizard.ProjectBuilder)11 ModuleBuilder (com.intellij.ide.util.projectWizard.ModuleBuilder)5 Module (com.intellij.openapi.module.Module)5 Project (com.intellij.openapi.project.Project)4 DefaultModulesProvider (com.intellij.openapi.roots.ui.configuration.DefaultModulesProvider)4 Nullable (org.jetbrains.annotations.Nullable)4 File (java.io.File)3 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)2 ProjectManagerEx (com.intellij.openapi.project.ex.ProjectManagerEx)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 List (java.util.List)2 Projects.canImportAsGradleProject (com.android.tools.idea.gradle.util.Projects.canImportAsGradleProject)1 NewProjectWizard (com.intellij.ide.projectWizard.NewProjectWizard)1 ProjectTypeStep (com.intellij.ide.projectWizard.ProjectTypeStep)1 AbstractProjectWizard (com.intellij.ide.util.newProjectWizard.AbstractProjectWizard)1 StepSequence (com.intellij.ide.util.newProjectWizard.StepSequence)1 CreateFromSourcesMode (com.intellij.ide.util.newProjectWizard.modes.CreateFromSourcesMode)1 WizardContext (com.intellij.ide.util.projectWizard.WizardContext)1 Step (com.intellij.ide.wizard.Step)1 Disposable (com.intellij.openapi.Disposable)1