in intellij-plugin/educational-core/src/com/jetbrains/edu/learning/newproject/ui/CoursesPlatformProvider.kt [72:112]
fun joinCourse(
courseInfo: CourseCreationInfo,
courseMode: CourseMode,
component: JPanel?,
openCourseParams: Map<String, String> = emptyMap(),
errorHandler: (ErrorState) -> Unit
): Project? {
val (course, location, projectSettings) = courseInfo
// location is null for course preview dialog only
if (location == null) {
return null
}
val configurator = course.configurator
// If `configurator != null` than `projectSettings` is always not null
// because project settings are produced by configurator itself
if (configurator != null && projectSettings != null) {
try {
configurator.beforeCourseStarted(course)
if (component != null) {
val dialog = UIUtil.getParentOfType(DialogWrapperDialog::class.java, component)
dialog?.dialogWrapper?.close(DialogWrapper.OK_EXIT_CODE)
}
course.courseMode = courseMode
val projectGenerator = configurator.courseBuilder.getCourseProjectGenerator(course)
val project = projectGenerator?.doCreateCourseProject(location, projectSettings, openCourseParams = openCourseParams)
// null project means that user hasn't created course project at all.
// For example, he/she may choose `Don't Open` option in `Trust and Open Project` dialog
if (project != null) {
CoursesStorage.getInstance().addCourse(course, location)
}
return project
}
catch (e: CourseCantBeStartedException) {
errorHandler(e.error)
}
}
return null
}