Search in sources :

Example 6 with CourseInfo

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) Notification(com.intellij.notification.Notification)

Example 7 with CourseInfo

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);
            }
        }
    });
}
Also used : AncestorListenerAdapter(com.intellij.ui.AncestorListenerAdapter) AncestorEvent(javax.swing.event.AncestorEvent) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo)

Example 8 with CourseInfo

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);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) Notification(com.intellij.notification.Notification) StudyProjectGenerator.flushCourse(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator.flushCourse) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 9 with CourseInfo

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);
}
Also used : CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo)

Example 10 with CourseInfo

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();
        }
    }
}
Also used : CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo)

Aggregations

CourseInfo (com.jetbrains.edu.learning.courseFormat.CourseInfo)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 TaskFile (com.jetbrains.edu.learning.courseFormat.TaskFile)7 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)5 PsiFile (com.intellij.psi.PsiFile)5 Course (com.jetbrains.edu.learning.courseFormat.Course)4 File (java.io.File)4 Project (com.intellij.openapi.project.Project)3 Lesson (com.jetbrains.edu.learning.courseFormat.Lesson)3 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 IdeView (com.intellij.ide.IdeView)2 Notification (com.intellij.notification.Notification)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 AncestorListenerAdapter (com.intellij.ui.AncestorListenerAdapter)2 ArrayList (java.util.ArrayList)2 JsonReader (com.google.gson.stream.JsonReader)1 FacetValidatorsManager (com.intellij.facet.ui.FacetValidatorsManager)1 ValidationResult (com.intellij.facet.ui.ValidationResult)1