EDU-717 Adaptive/Nonadaptive sorting breaks "Preview Course" action
authorliana.bakradze <liana.bakradze@jetbrains.com>
Sat, 6 Aug 2016 18:14:19 +0000 (21:14 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Sat, 6 Aug 2016 18:14:19 +0000 (21:14 +0300)
python/educational-core/student/src/com/jetbrains/edu/learning/StudyUtils.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseGeneration/StudyProjectGenerator.java

index c82a0379c2d1751881e5e8fd03726b1934fddc32..8c926e52ceeace1cf0b2fe286d26cdbffa6fbf6e 100644 (file)
@@ -59,7 +59,6 @@ import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.courseFormat.*;
 import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
 import com.jetbrains.edu.learning.editor.StudyEditor;
-import com.jetbrains.edu.learning.stepic.CourseInfo;
 import com.jetbrains.edu.learning.ui.StudyToolWindow;
 import com.jetbrains.edu.learning.ui.StudyToolWindowFactory;
 import com.petebevin.markdown.MarkdownProcessor;
@@ -69,7 +68,9 @@ import org.jetbrains.annotations.Nullable;
 import javax.swing.*;
 import java.awt.*;
 import java.io.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
@@ -722,17 +723,6 @@ public class StudyUtils {
     showCheckPopUp(project, balloon);
   }
 
-  public static void sortCourses(List<CourseInfo> result) {
-    // sort courses so as to have non-adaptive courses in the beginning of the list
-    Collections.sort(result, (c1, c2) -> {
-      if ((c1.isAdaptive() && c2.isAdaptive()) || (!c1.isAdaptive() && !c2.isAdaptive())) {
-        return 0;
-      }
-
-      return c1.isAdaptive() ? 1 : -1;
-    });
-  }
-
   public static void selectFirstAnswerPlaceholder(@Nullable final StudyEditor studyEditor, @NotNull final Project project) {
     if (studyEditor == null) return;
     final Editor editor = studyEditor.getEditor();
index b512f91cfa3b7df7d0df9cf94ba94352356f0855..0a12c9558fdd223d0a53070bc11a3aca7fb5a550 100644 (file)
@@ -407,10 +407,28 @@ public class StudyProjectGenerator {
     if (myCourses.isEmpty()) {
       myCourses = getBundledIntro();
     }
-    StudyUtils.sortCourses(myCourses);
+    sortCourses(myCourses);
     return myCourses;
   }
 
+  public void sortCourses(List<CourseInfo> result) {
+    // sort courses so as to have non-adaptive courses in the beginning of the list
+    Collections.sort(result, (c1, c2) -> {
+      if (mySelectedCourseInfo != null) {
+        if (mySelectedCourseInfo.equals(c1)) {
+          return -1;
+        }
+        if (mySelectedCourseInfo.equals(c2)) {
+          return 1;
+        }
+      }
+      if ((c1.isAdaptive() && c2.isAdaptive()) || (!c1.isAdaptive() && !c2.isAdaptive())) {
+        return 0;
+      }
+      return c1.isAdaptive() ? 1 : -1;
+    });
+  }
+
   @NotNull
   public List<CourseInfo> getCoursesUnderProgress(boolean force, @NotNull final String progressTitle, @NotNull final Project project) {
     try {
@@ -539,7 +557,7 @@ public class StudyProjectGenerator {
       File courseFile = courseFiles[0];
       CourseInfo courseInfo = getCourseInfo(courseFile);
       if (courseInfo != null) {
-        courses.add(courseInfo);
+        courses.add(0, courseInfo);
       }
       return courseInfo;
     }