use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class EduStepicUpdater method updateCourseList.
private static ActionCallback updateCourseList() {
ActionCallback callback = new ActionCallback();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final List<CourseInfo> courses = EduStepicConnector.getCourses(null);
final List<CourseInfo> cachedCourses = StudyProjectGenerator.getCoursesFromCache();
StudyProjectGenerator.flushCache(courses);
StepicUpdateSettings.getInstance().setLastTimeChecked(System.currentTimeMillis());
courses.removeAll(cachedCourses);
if (!courses.isEmpty() && !cachedCourses.isEmpty()) {
final String message;
final String title;
if (courses.size() == 1) {
message = courses.get(0).getName();
title = "New course available";
} else {
title = "New courses available";
message = StringUtil.join(courses, CourseInfo::getName, ", ");
}
final Notification notification = new Notification("New.course", title, message, NotificationType.INFORMATION);
notification.notify(null);
}
});
return callback;
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class StudyNewProjectPanel method initListeners.
private void initListeners() {
myRefreshButton.addActionListener(new RefreshActionListener());
myCoursesComboBox.addActionListener(new CourseSelectedListener());
setupBrowseButton();
addAncestorListener(new AncestorListenerAdapter() {
@Override
public void ancestorMoved(AncestorEvent event) {
if (!isComboboxInitialized && isVisible()) {
isComboboxInitialized = true;
initCoursesCombobox();
}
CourseInfo selectedCourse = (CourseInfo) myCoursesComboBox.getSelectedItem();
if (selectedCourse == null || selectedCourse.equals(CourseInfo.INVALID_COURSE)) {
setError(CONNECTION_ERROR);
}
}
});
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class StudyProjectComponent method updateCourse.
private void updateCourse() {
final Course currentCourse = StudyTaskManager.getInstance(myProject).getCourse();
final CourseInfo info = CourseInfo.fromCourse(currentCourse);
if (info == null)
return;
final File resourceDirectory = new File(currentCourse.getCourseDirectory());
if (resourceDirectory.exists()) {
FileUtil.delete(resourceDirectory);
}
final Course course = EduStepicConnector.getCourse(myProject, info);
if (course == null)
return;
flushCourse(course);
course.initCourse(false);
StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
if (manager == null) {
LOG.info("Study Language Manager is null for " + course.getLanguageById().getDisplayName());
return;
}
final ArrayList<Lesson> updatedLessons = new ArrayList<>();
int lessonIndex = 0;
for (Lesson lesson : course.getLessons()) {
lessonIndex += 1;
Lesson studentLesson = currentCourse.getLesson(lesson.getId());
final String lessonDirName = EduNames.LESSON + String.valueOf(lessonIndex);
final File lessonDir = new File(myProject.getBasePath(), lessonDirName);
if (!lessonDir.exists()) {
final File fromLesson = new File(resourceDirectory, lessonDirName);
try {
FileUtil.copyDir(fromLesson, lessonDir);
} catch (IOException e) {
LOG.warn("Failed to copy lesson " + fromLesson.getPath());
}
lesson.setIndex(lessonIndex);
lesson.initLesson(currentCourse, false);
for (int i = 1; i <= lesson.getTaskList().size(); i++) {
Task task = lesson.getTaskList().get(i - 1);
task.setIndex(i);
}
updatedLessons.add(lesson);
continue;
}
studentLesson.setIndex(lessonIndex);
updatedLessons.add(studentLesson);
int index = 0;
final ArrayList<Task> tasks = new ArrayList<>();
for (Task task : lesson.getTaskList()) {
index += 1;
final Task studentTask = studentLesson.getTask(task.getStepId());
if (studentTask != null && StudyStatus.Solved.equals(studentTask.getStatus())) {
studentTask.setIndex(index);
tasks.add(studentTask);
continue;
}
task.initTask(studentLesson, false);
task.setIndex(index);
final String taskDirName = EduNames.TASK + String.valueOf(index);
final File toTask = new File(lessonDir, taskDirName);
final String taskPath = FileUtil.join(resourceDirectory.getPath(), lessonDirName, taskDirName);
final File taskDir = new File(taskPath);
if (!taskDir.exists())
return;
final File[] taskFiles = taskDir.listFiles();
if (taskFiles == null)
continue;
for (File fromFile : taskFiles) {
copyFile(fromFile, new File(toTask, fromFile.getName()));
}
tasks.add(task);
}
studentLesson.updateTaskList(tasks);
}
currentCourse.setLessons(updatedLessons);
final Notification notification = new Notification("Update.course", "Course update", "Current course is synchronized", NotificationType.INFORMATION);
notification.notify(myProject);
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class StudyNewProjectPanel method refreshCoursesList.
private void refreshCoursesList(@NotNull final List<CourseInfo> courses) {
if (courses.isEmpty()) {
setError(CONNECTION_ERROR);
return;
}
myCoursesComboBox.removeAllItems();
addCoursesToCombobox(courses);
final CourseInfo selectedCourse = StudyUtils.getFirst(courses);
if (selectedCourse == null)
return;
myGenerator.setSelectedCourse(selectedCourse);
myGenerator.setCourses(courses);
myAvailableCourses = courses;
StudyProjectGenerator.flushCache(myAvailableCourses, false);
}
use of com.jetbrains.edu.learning.courseFormat.CourseInfo in project intellij-community by JetBrains.
the class StudyNewProjectPanel method initCoursesCombobox.
private void initCoursesCombobox() {
myAvailableCourses = myGenerator.getCoursesUnderProgress(false, "Getting Available Courses", ProjectManager.getInstance().getDefaultProject());
if (myAvailableCourses.contains(CourseInfo.INVALID_COURSE)) {
setError(CONNECTION_ERROR);
} else {
addCoursesToCombobox(myAvailableCourses);
final CourseInfo selectedCourse = StudyUtils.getFirst(myAvailableCourses);
if (selectedCourse == null)
return;
setAuthors(selectedCourse);
myDescriptionPane.setText(selectedCourse.getDescription());
myDescriptionPane.setEditable(false);
//setting the first course in list as selected
myGenerator.setSelectedCourse(selectedCourse);
if (myGenerator.getSelectedCourseInfo() != null) {
myCoursesComboBox.setSelectedItem(myGenerator.getSelectedCourseInfo());
}
if (selectedCourse.isAdaptive() && !myGenerator.isLoggedIn()) {
setError(LOGIN_TO_STEPIC_MESSAGE);
} else {
setOK();
}
}
}
Aggregations