use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.
the class StepikModuleType method modifySettingsStep.
@Nullable
@Override
public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep, @NotNull ModuleBuilder moduleBuilder) {
JTextField nameField = settingsStep.getModuleNameField();
if (nameField != null) {
CourseModuleBuilder courseModuleBuilder = (CourseModuleBuilder) moduleBuilder;
StudyObject studyObject = courseModuleBuilder.getWizardStep().getSelectedStudyObject();
String projectDirectory = settingsStep.getContext().getProjectFileDirectory();
String projectName = ProjectWizardUtils.getProjectDefaultName(projectDirectory, studyObject);
nameField.setText(projectName);
}
return null;
}
use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.
the class StepikProjectGenerator method initEmptyStudyNode.
@NotNull
private static StudyObject initEmptyStudyNode() {
StudyObject course = new Course();
course.setTitle("Empty");
course.setDescription("Please, press refresh button");
return course;
}
use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.
the class StepikProjectGenerator method getCourses.
@NotNull
public static CompletableFuture<List<StudyObject>> getCourses(@NotNull SupportedLanguages programmingLanguage) {
return CompletableFuture.supplyAsync(() -> {
List<StudyObject> courses = new ArrayList<>();
List<Long> coursesIds = getHardcodedCoursesId(programmingLanguage);
if (!coursesIds.isEmpty()) {
StepikApiClient stepikApiClient = authAndGetStepikApiClient();
try {
courses = stepikApiClient.courses().get().id(coursesIds).execute().getCourses().stream().map(course -> (StudyObject) course).collect(Collectors.toList());
} catch (StepikClientException e) {
logger.warn("Failed get courses", e);
}
}
courses.sort((course1, course2) -> {
long id1 = course1.getId();
long id2 = course2.getId();
int index1 = coursesIds.indexOf(id1);
int index2 = coursesIds.indexOf(id2);
return Integer.compare(index1, index2);
});
return courses;
});
}
use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.
the class JavaWizardStep method onWizardFinished.
@Override
public void onWizardFinished() throws CommitStepException {
if (!(valid && leaving)) {
return;
}
SupportedLanguages selectedLang = panel.getLanguage();
generator.setDefaultLang(selectedLang);
StudyObject studyObject = panel.getSelectedStudyObject();
generator.createCourseNodeUnderProgress(project, studyObject);
long id = studyObject.getId();
if (id == 0) {
return;
}
boolean wasEnrollment = ProjectWizardUtils.enrollmentCourse(studyObject);
if (wasEnrollment) {
logger.warn("User didn't enrollment on course: " + id);
}
String messageTemplate = "Leaving step the project wizard with the selected study object: type=%s, id = %s, name = %s";
logger.info(String.format(messageTemplate, studyObject.getClass().getSimpleName(), id, studyObject.getTitle()));
}
use of org.stepik.api.objects.StudyObject in project intellij-plugins by StepicOrg.
the class CourseListModel method update.
void update(@NotNull SupportedLanguages programmingLanguage) {
StepikProjectGenerator.getCourses(programmingLanguage).thenAccept(newCourseList -> {
StudyObject selectedCourse = getSelectedItem();
courses.clear();
if (!newCourseList.isEmpty()) {
courses.addAll(newCourseList);
if (selectedCourse == EMPTY_STUDY_OBJECT || !courses.contains(selectedCourse)) {
selectedCourse = courses.get(0);
}
} else {
courses.add(EMPTY_STUDY_OBJECT);
}
StudyObject finalSelectedCourse = selectedCourse;
SwingUtilities.invokeLater(() -> {
setSelectedItem(finalSelectedCourse);
fireIntervalAdded(this, 0, getSize() - 1);
});
});
}
Aggregations