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