diff --git a/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateLesson.java b/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateLesson.java index 0436abb5132c..09e24daf3360 100644 --- a/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateLesson.java +++ b/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateLesson.java @@ -15,8 +15,6 @@ import icons.EducationalCoreIcons; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; - public class CCCreateLesson extends CCCreateStudyItemActionBase { public static final String TITLE = "Create New " + EduNames.LESSON_TITLED; @@ -82,8 +80,8 @@ public class CCCreateLesson extends CCCreateStudyItemActionBase { } @Override - protected List getSiblings(@NotNull Course course, @Nullable StudyItem parentItem) { - return course.getLessons(true); + protected void sortSiblings(@NotNull Course course, @Nullable StudyItem parentItem) { + course.sortLessons(); } @Override diff --git a/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateStudyItemActionBase.java b/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateStudyItemActionBase.java index 4af27a9a372f..bad3979442b0 100644 --- a/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateStudyItemActionBase.java +++ b/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateStudyItemActionBase.java @@ -18,15 +18,12 @@ import com.jetbrains.edu.coursecreator.CCUtils; import com.jetbrains.edu.coursecreator.ui.CCCreateStudyItemDialog; import com.jetbrains.edu.learning.StudyTaskManager; import com.jetbrains.edu.learning.StudyUtils; -import com.jetbrains.edu.learning.core.EduUtils; import com.jetbrains.edu.learning.courseFormat.Course; import com.jetbrains.edu.learning.courseFormat.StudyItem; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.Collections; -import java.util.List; public abstract class CCCreateStudyItemActionBase extends DumbAwareAction { @@ -103,7 +100,7 @@ public abstract class CCCreateStudyItemActionBase extends DumbAwareAction { CCUtils.updateHigherElements(parentDir.getVirtualFile().getChildren(), getStudyOrderable(item), item.getIndex() - 1, getItemName(), 1); addItem(course, item); - Collections.sort(getSiblings(course, parentItem), EduUtils.INDEX_COMPARATOR); + sortSiblings(course, parentItem); return createItemDir(project, item, view, parentDir, course); } @@ -168,7 +165,7 @@ public abstract class CCCreateStudyItemActionBase extends DumbAwareAction { @NotNull final Project project, @NotNull final Course course); - protected abstract List getSiblings(@NotNull final Course course, @Nullable final StudyItem parentItem); + protected abstract void sortSiblings(@NotNull final Course course, @Nullable final StudyItem parentItem); protected abstract String getItemName(); diff --git a/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java b/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java index 78e74feda957..f64e54b4a123 100644 --- a/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java +++ b/python/educational-core/src/com/jetbrains/edu/coursecreator/actions/CCCreateTask.java @@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; -import java.util.List; public class CCCreateTask extends CCCreateStudyItemActionBase { public static final String TITLE = "Create New " + EduNames.TASK_TITLED; @@ -100,11 +99,10 @@ public class CCCreateTask extends CCCreateStudyItemActionBase { } @Override - protected List getSiblings(@NotNull Course course, @Nullable StudyItem parentItem) { + protected void sortSiblings(@NotNull Course course, @Nullable StudyItem parentItem) { if (parentItem instanceof Lesson) { - return ((Lesson)parentItem).getTaskList(); + Collections.sort(((Lesson)parentItem).getTaskList(), EduUtils.INDEX_COMPARATOR); } - return Collections.emptyList(); } @Override diff --git a/python/educational-core/src/com/jetbrains/edu/coursecreator/handlers/CCLessonMoveHandlerDelegate.java b/python/educational-core/src/com/jetbrains/edu/coursecreator/handlers/CCLessonMoveHandlerDelegate.java index 3b163cd947ca..ebe4603afc9c 100644 --- a/python/educational-core/src/com/jetbrains/edu/coursecreator/handlers/CCLessonMoveHandlerDelegate.java +++ b/python/educational-core/src/com/jetbrains/edu/coursecreator/handlers/CCLessonMoveHandlerDelegate.java @@ -22,14 +22,12 @@ import com.jetbrains.edu.coursecreator.CCUtils; import com.jetbrains.edu.coursecreator.ui.CCMoveStudyItemDialog; import com.jetbrains.edu.learning.StudyTaskManager; import com.jetbrains.edu.learning.core.EduNames; -import com.jetbrains.edu.learning.core.EduUtils; import com.jetbrains.edu.learning.courseFormat.Course; import com.jetbrains.edu.learning.courseFormat.Lesson; import com.jetbrains.edu.learning.courseFormat.StudyItem; import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.util.Collections; public class CCLessonMoveHandlerDelegate extends MoveHandlerDelegate { @@ -109,7 +107,7 @@ public class CCLessonMoveHandlerDelegate extends MoveHandlerDelegate { newItemIndex - 1, EduNames.LESSON, 1); sourceLesson.setIndex(newItemIndex); - Collections.sort(course.getLessons(true), EduUtils.INDEX_COMPARATOR); + course.sortLessons(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { diff --git a/python/educational-core/src/com/jetbrains/edu/learning/courseFormat/Course.java b/python/educational-core/src/com/jetbrains/edu/learning/courseFormat/Course.java index 9e4efbe46f33..d203b338f186 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/courseFormat/Course.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/courseFormat/Course.java @@ -44,13 +44,19 @@ public class Course { } } + /** + * exclude service lesson containing additional files for the course. Returns lessons copy. + */ public List getLessons() { return getLessons(false); } + /** + * returns service lesson as well. Meant to be used in project generation/serialization + */ public List getLessons(boolean withAdditional) { - return withAdditional ? lessons - : lessons.stream().filter(lesson -> !EduNames.PYCHARM_ADDITIONAL.equals(lesson.getName())).collect(Collectors.toList()); + return withAdditional ? lessons : lessons.stream().filter(lesson -> !EduNames.PYCHARM_ADDITIONAL.equals(lesson.getName())) + .collect(Collectors.toList()); } public void setLessons(List lessons) {