Search in sources :

Example 1 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project intellij-community by JetBrains.

the class ProjectOpenProcessorBase method doOpenProject.

@Nullable
public Project doOpenProject(@NotNull VirtualFile virtualFile, Project projectToClose, boolean forceOpenInNewFrame) {
    try {
        getBuilder().setUpdate(false);
        final WizardContext wizardContext = new WizardContext(null);
        if (virtualFile.isDirectory()) {
            final String[] supported = getSupportedExtensions();
            for (VirtualFile file : getFileChildren(virtualFile)) {
                if (canOpenFile(file, supported)) {
                    virtualFile = file;
                    break;
                }
            }
        }
        wizardContext.setProjectFileDirectory(virtualFile.getParent().getPath());
        if (!doQuickImport(virtualFile, wizardContext))
            return null;
        if (wizardContext.getProjectName() == null) {
            if (wizardContext.getProjectStorageFormat() == StorageScheme.DEFAULT) {
                wizardContext.setProjectName(IdeBundle.message("project.import.default.name", getName()) + ProjectFileType.DOT_DEFAULT_EXTENSION);
            } else {
                wizardContext.setProjectName(IdeBundle.message("project.import.default.name.dotIdea", getName()));
            }
        }
        Project defaultProject = ProjectManager.getInstance().getDefaultProject();
        Sdk jdk = ProjectRootManager.getInstance(defaultProject).getProjectSdk();
        if (jdk == null) {
            jdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
        }
        wizardContext.setProjectJdk(jdk);
        final String dotIdeaFilePath = wizardContext.getProjectFileDirectory() + File.separator + Project.DIRECTORY_STORE_FOLDER;
        final String projectFilePath = wizardContext.getProjectFileDirectory() + File.separator + wizardContext.getProjectName() + ProjectFileType.DOT_DEFAULT_EXTENSION;
        File dotIdeaFile = new File(dotIdeaFilePath);
        File projectFile = new File(projectFilePath);
        String pathToOpen;
        if (wizardContext.getProjectStorageFormat() == StorageScheme.DEFAULT) {
            pathToOpen = projectFilePath;
        } else {
            pathToOpen = dotIdeaFile.getParent();
        }
        boolean shouldOpenExisting = false;
        boolean importToProject = true;
        if (projectFile.exists() || dotIdeaFile.exists()) {
            if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
                shouldOpenExisting = true;
                importToProject = true;
            } else {
                String existingName;
                if (dotIdeaFile.exists()) {
                    existingName = "an existing project";
                    pathToOpen = dotIdeaFile.getParent();
                } else {
                    existingName = "'" + projectFile.getName() + "'";
                    pathToOpen = projectFilePath;
                }
                int result = Messages.showYesNoCancelDialog(projectToClose, IdeBundle.message("project.import.open.existing", existingName, projectFile.getParent(), virtualFile.getName()), IdeBundle.message("title.open.project"), IdeBundle.message("project.import.open.existing.openExisting"), IdeBundle.message("project.import.open.existing.reimport"), CommonBundle.message("button.cancel"), Messages.getQuestionIcon());
                if (result == Messages.CANCEL)
                    return null;
                shouldOpenExisting = result == Messages.YES;
                importToProject = !shouldOpenExisting;
            }
        }
        final Project projectToOpen;
        if (shouldOpenExisting) {
            try {
                projectToOpen = ProjectManagerEx.getInstanceEx().loadProject(pathToOpen);
            } catch (Exception e) {
                return null;
            }
        } else {
            projectToOpen = ProjectManagerEx.getInstanceEx().newProject(wizardContext.getProjectName(), pathToOpen, true, false);
        }
        if (projectToOpen == null)
            return null;
        if (importToProject) {
            if (!getBuilder().validate(projectToClose, projectToOpen)) {
                return null;
            }
            projectToOpen.save();
            ApplicationManager.getApplication().runWriteAction(() -> {
                Sdk jdk1 = wizardContext.getProjectJdk();
                if (jdk1 != null) {
                    NewProjectUtil.applyJdkToProject(projectToOpen, jdk1);
                }
                String projectDirPath = wizardContext.getProjectFileDirectory();
                String path = StringUtil.endsWithChar(projectDirPath, '/') ? projectDirPath + "classes" : projectDirPath + "/classes";
                CompilerProjectExtension extension = CompilerProjectExtension.getInstance(projectToOpen);
                if (extension != null) {
                    extension.setCompilerOutputUrl(getUrl(path));
                }
            });
            getBuilder().commit(projectToOpen, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
        }
        if (!forceOpenInNewFrame) {
            NewProjectUtil.closePreviousProject(projectToClose);
        }
        ProjectUtil.updateLastProjectLocation(pathToOpen);
        ProjectManagerEx.getInstanceEx().openProject(projectToOpen);
        return projectToOpen;
    } finally {
        getBuilder().cleanup();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Project(com.intellij.openapi.project.Project) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) File(java.io.File) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project intellij-community by JetBrains.

the class ImportFromSourcesTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    myBuilder = new ProjectFromSourcesBuilderImpl(new WizardContext(null), ModulesProvider.EMPTY_MODULES_PROVIDER);
}
Also used : ProjectFromSourcesBuilderImpl(com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl) WizardContext(com.intellij.ide.util.projectWizard.WizardContext)

Example 3 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project android by JetBrains.

the class AdtImportLocationStep method updateDataModel.

@Override
public void updateDataModel() {
    WizardContext context = getWizardContext();
    context.setProjectFileDirectory(getProjectFileDirectory());
    AdtImportBuilder builder = (AdtImportBuilder) context.getProjectBuilder();
    if (builder != null) {
        builder.setSelectedProject(mySourceProject);
    }
}
Also used : WizardContext(com.intellij.ide.util.projectWizard.WizardContext)

Example 4 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project intellij-community by JetBrains.

the class SelectExternalProjectStep method validate.

// TODO den uncomment
//@Override
//public String getHelpId() {
//  return GradleConstants.HELP_TOPIC_IMPORT_SELECT_PROJECT_STEP;
//}
@Override
public boolean validate() throws ConfigurationException {
    WizardContext wizardContext = getWizardContext();
    boolean isDefaultFormat = true;
    if (myControl.getProjectFormatPanel() != null) {
        isDefaultFormat = myControl.getProjectFormatPanel().isDefault();
    }
    if (!myControl.validate(wizardContext, isDefaultFormat))
        return false;
    AbstractExternalProjectImportBuilder builder = getBuilder();
    if (builder == null) {
        return false;
    }
    myControl.apply();
    if (myControl.getProjectFormatPanel() != null) {
        myControl.getProjectFormatPanel().updateData(wizardContext);
    }
    builder.ensureProjectIsDefined(wizardContext);
    return true;
}
Also used : WizardContext(com.intellij.ide.util.projectWizard.WizardContext)

Example 5 with WizardContext

use of com.intellij.ide.util.projectWizard.WizardContext in project intellij-community by JetBrains.

the class AbstractProjectWizard method initContext.

private static WizardContext initContext(@Nullable Project project, @Nullable String defaultPath, Disposable parentDisposable) {
    WizardContext context = new WizardContext(project, parentDisposable);
    if (defaultPath != null) {
        context.setProjectFileDirectory(defaultPath, true);
        context.setProjectName(defaultPath.substring(FileUtil.toSystemIndependentName(defaultPath).lastIndexOf("/") + 1));
    }
    return context;
}
Also used : WizardContext(com.intellij.ide.util.projectWizard.WizardContext)

Aggregations

WizardContext (com.intellij.ide.util.projectWizard.WizardContext)11 Project (com.intellij.openapi.project.Project)4 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)3 Disposable (com.intellij.openapi.Disposable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 StepSequence (com.intellij.ide.util.newProjectWizard.StepSequence)2 SettingsStep (com.intellij.ide.util.projectWizard.SettingsStep)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 ModulesProvider (com.intellij.openapi.roots.ui.configuration.ModulesProvider)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ModuleImporter (com.android.tools.idea.gradle.project.ModuleImporter)1 ModelWizardStep (com.android.tools.idea.wizard.model.ModelWizardStep)1 FrameworkSupportInModuleProvider (com.intellij.framework.addSupport.FrameworkSupportInModuleProvider)1 ProjectCategory (com.intellij.ide.projectWizard.ProjectCategory)1 ProjectCategoryUsagesCollector (com.intellij.ide.projectWizard.ProjectCategoryUsagesCollector)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 FrameworkRole (com.intellij.ide.util.frameworkSupport.FrameworkRole)1 FrameworkSupportUtil (com.intellij.ide.util.frameworkSupport.FrameworkSupportUtil)1