From aac2fe398170379eed8b194ea096bfac901113d6 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 16 Feb 2015 21:19:24 +0300 Subject: [PATCH] moved course initialization back --- .../edu/coursecreator/CCProjectService.java | 2 +- .../edu/learning/StudyProjectComponent.java | 2 +- .../edu/learning/StudyTaskManager.java | 3 +- .../StudyProjectGenerator.java | 3 +- .../src/com/jetbrains/edu/EduUtils.java | 56 +------------------ .../edu/courseFormat/AnswerPlaceholder.java | 7 +++ .../jetbrains/edu/courseFormat/Course.java | 9 +++ .../jetbrains/edu/courseFormat/Lesson.java | 7 +++ .../com/jetbrains/edu/courseFormat/Task.java | 12 ++++ .../jetbrains/edu/courseFormat/TaskFile.java | 12 ++++ 10 files changed, 53 insertions(+), 60 deletions(-) diff --git a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java index 23ae0bed57a5..4d2081b369d4 100644 --- a/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java +++ b/python/educational/course-creator/src/com/jetbrains/edu/coursecreator/CCProjectService.java @@ -173,7 +173,7 @@ public class CCProjectService implements PersistentStateComponent taskList = lesson.getTaskList(); - for (Task task : taskList) { - initTask(task, lesson, isRestarted); - } - } - - /** - * Initializes state of task file - * - * @param lesson lesson which task belongs to - */ - public static void initTask(@NotNull final Task task, final Lesson lesson, boolean isRestarted) { - task.setLesson(lesson); - for (TaskFile taskFile : task.getTaskFiles().values()) { - initTaskFile(taskFile, task, isRestarted); - } - } - - public static void initTaskFile(@NotNull final TaskFile taskFile, final Task task, boolean isRestarted) { - taskFile.setTask(task); - final List answerPlaceholders = taskFile.getAnswerPlaceholders(); - for (AnswerPlaceholder answerPlaceholder : answerPlaceholders) { - initAnswerPlaceholder(answerPlaceholder, taskFile, isRestarted); - } - Collections.sort(answerPlaceholders, new AnswerPlaceholderComparator()); - for (int i = 0; i < answerPlaceholders.size(); i++) { - answerPlaceholders.get(i).setIndex(i); - } - } - - public static void initAnswerPlaceholder(@NotNull final AnswerPlaceholder placeholder, final TaskFile file, boolean isRestarted) { - if (!isRestarted) { - placeholder.setInitialState(new AnswerPlaceholder.MyInitialState(placeholder.getLine(), placeholder.getLength(), - placeholder.getStart())); - } - placeholder.setTaskFile(file); - } - } diff --git a/python/educational/src/com/jetbrains/edu/courseFormat/AnswerPlaceholder.java b/python/educational/src/com/jetbrains/edu/courseFormat/AnswerPlaceholder.java index b4f7af7f92db..a2ffd42ef345 100644 --- a/python/educational/src/com/jetbrains/edu/courseFormat/AnswerPlaceholder.java +++ b/python/educational/src/com/jetbrains/edu/courseFormat/AnswerPlaceholder.java @@ -26,6 +26,13 @@ public class AnswerPlaceholder { @Transient private TaskFile myTaskFile; + public void initAnswerPlaceholder(final TaskFile file, boolean isRestarted) { + if (!isRestarted) { + setInitialState(new MyInitialState(getLine(), getLength(), getStart())); + } + setTaskFile(file); + } + public int getIndex() { return myIndex; } diff --git a/python/educational/src/com/jetbrains/edu/courseFormat/Course.java b/python/educational/src/com/jetbrains/edu/courseFormat/Course.java index db3b199aa372..0bde12d2c6ad 100644 --- a/python/educational/src/com/jetbrains/edu/courseFormat/Course.java +++ b/python/educational/src/com/jetbrains/edu/courseFormat/Course.java @@ -23,6 +23,15 @@ public class Course { @Expose @SerializedName("language") private String myLanguage; + /** + * Initializes state of course + */ + public void initCourse(boolean isRestarted) { + for (Lesson lesson : getLessons()) { + lesson.initLesson(this, isRestarted); + } + } + public List getLessons() { return lessons; } diff --git a/python/educational/src/com/jetbrains/edu/courseFormat/Lesson.java b/python/educational/src/com/jetbrains/edu/courseFormat/Lesson.java index f687fde80ca1..0b4e4bece5fe 100644 --- a/python/educational/src/com/jetbrains/edu/courseFormat/Lesson.java +++ b/python/educational/src/com/jetbrains/edu/courseFormat/Lesson.java @@ -30,6 +30,13 @@ public class Lesson { private Course myCourse = null; private int myIndex = -1; + public void initLesson(final Course course, boolean isRestarted) { + setCourse(course); + for (Task task : getTaskList()) { + task.initTask(this, isRestarted); + } + } + public String getName() { return name; } diff --git a/python/educational/src/com/jetbrains/edu/courseFormat/Task.java b/python/educational/src/com/jetbrains/edu/courseFormat/Task.java index e381c6d61697..a97803e3acda 100644 --- a/python/educational/src/com/jetbrains/edu/courseFormat/Task.java +++ b/python/educational/src/com/jetbrains/edu/courseFormat/Task.java @@ -36,6 +36,18 @@ public class Task { this.name = name; } + /** + * Initializes state of task file + * + * @param lesson lesson which task belongs to + */ + public void initTask(final Lesson lesson, boolean isRestarted) { + setLesson(lesson); + for (TaskFile taskFile : getTaskFiles().values()) { + taskFile.initTaskFile(this, isRestarted); + } + } + public String getName() { return name; } diff --git a/python/educational/src/com/jetbrains/edu/courseFormat/TaskFile.java b/python/educational/src/com/jetbrains/edu/courseFormat/TaskFile.java index 1e6fa65bf5ab..f7e0cedc3f8e 100644 --- a/python/educational/src/com/jetbrains/edu/courseFormat/TaskFile.java +++ b/python/educational/src/com/jetbrains/edu/courseFormat/TaskFile.java @@ -34,6 +34,18 @@ public class TaskFile { private boolean myTrackChanges = true; private boolean myHighlightErrors = false; + public void initTaskFile(final Task task, boolean isRestarted) { + setTask(task); + final List answerPlaceholders = getAnswerPlaceholders(); + for (AnswerPlaceholder answerPlaceholder : answerPlaceholders) { + answerPlaceholder.initAnswerPlaceholder(this, isRestarted); + } + Collections.sort(answerPlaceholders, new AnswerPlaceholderComparator()); + for (int i = 0; i < answerPlaceholders.size(); i++) { + answerPlaceholders.get(i).setIndex(i); + } + } + @Nullable @Transient public AnswerPlaceholder getSelectedAnswerPlaceholder() {