fix get courses in show course preview

This commit is contained in:
Ekaterina Tuzova
2017-03-25 20:02:37 +03:00
committed by Ekaterina Tuzova
parent 2168b64066
commit 5bc23e38bc
6 changed files with 15 additions and 10 deletions

View File

@@ -123,7 +123,7 @@ public class StudyProjectGenerator {
if (force) {
myCourses = execCancelable(() -> EduStepicConnector.getCourses(StepicUpdateSettings.getInstance().getUser()));
}
if (force || myCourses == null || myCourses.isEmpty() || (myCourses.size() == 1 && myCourses.contains(CourseInfo.INVALID_COURSE))) {
if (myCourses == null || myCourses.isEmpty() || (myCourses.size() == 1 && myCourses.contains(CourseInfo.INVALID_COURSE))) {
myCourses = Collections.singletonList(getBundledIntro());
}
sortCourses(myCourses);

View File

@@ -2,8 +2,8 @@ package com.jetbrains.edu.learning.intellij.localCourses;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
import com.jetbrains.edu.learning.courseFormat.CourseInfo;
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
import com.jetbrains.edu.learning.ui.StudyNewProjectPanel;
import javax.swing.*;
@@ -45,7 +45,7 @@ public class EduLocalCoursePanel {
}
private void createUIComponents() {
myStudyPanel = new StudyNewProjectPanel(myGenerator);
myStudyPanel = new StudyNewProjectPanel(myGenerator, true);
myInfoPanel = myStudyPanel.getInfoPanel();
}
}

View File

@@ -61,6 +61,7 @@ public class StudyNewProjectPanel extends JPanel implements PanelWithAnchor {
private JTextPane myDescriptionPane;
private JComponent myAnchor;
private final StudyProjectGenerator myGenerator;
private boolean isLocal = false;
private static final String CONNECTION_ERROR = "<html>Failed to download courses.<br>Check your Internet connection.</html>";
private static final String INVALID_COURSE = "Selected course is invalid";
private FacetValidatorsManager myValidationManager;
@@ -68,10 +69,10 @@ public class StudyNewProjectPanel extends JPanel implements PanelWithAnchor {
private static final String LOGIN_TO_STEPIC_MESSAGE = "<html><u>Login to Stepik</u> to open the adaptive course </html>";
private static final String LOGIN_TO_STEPIC = "Login to Stepik";
public StudyNewProjectPanel(@NotNull final StudyProjectGenerator generator) {
public StudyNewProjectPanel(@NotNull final StudyProjectGenerator generator, boolean isLocal) {
super(new VerticalFlowLayout(true, true));
myGenerator = generator;
this.isLocal = isLocal;
layoutPanel();
initListeners();
}
@@ -120,7 +121,7 @@ public class StudyNewProjectPanel extends JPanel implements PanelWithAnchor {
private void initCoursesCombobox() {
myAvailableCourses =
myGenerator.getCoursesUnderProgress(false, "Getting Available Courses", ProjectManager.getInstance().getDefaultProject());
myGenerator.getCoursesUnderProgress(!isLocal, "Getting Available Courses", ProjectManager.getInstance().getDefaultProject());
if (myAvailableCourses.contains(CourseInfo.INVALID_COURSE)) {
setError(CONNECTION_ERROR);
}

View File

@@ -10,8 +10,8 @@ import com.jetbrains.edu.learning.PyStudyDirectoryProjectGenerator;
import com.jetbrains.edu.learning.StudyTaskManager;
import com.jetbrains.edu.learning.core.EduNames;
import com.jetbrains.edu.learning.courseFormat.Course;
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
import com.jetbrains.edu.learning.courseFormat.CourseInfo;
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
import com.jetbrains.python.newProject.steps.PyCharmNewProjectStep;
import org.jetbrains.annotations.NotNull;
@@ -25,7 +25,7 @@ class CreateFromArchiveProjectStep extends PyCharmNewProjectStep {
private final Project myProject;
private final Module myModule;
private PyStudyDirectoryProjectGenerator myGenerator = new PyStudyDirectoryProjectGenerator();
private PyStudyDirectoryProjectGenerator myGenerator = new PyStudyDirectoryProjectGenerator(true);
public MyCustomization(Project project,
Module module) {

View File

@@ -60,6 +60,10 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
private StudyNewProjectPanel mySettingsPanel;
public PyStudyDirectoryProjectGenerator() {
this(false);
}
public PyStudyDirectoryProjectGenerator(boolean isLocal) {
myGenerator = new StudyProjectGenerator();
myGenerator.addSettingsStateListener(new StudyProjectGenerator.SettingsListener() {
@Override
@@ -68,7 +72,7 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
}
});
mySettingsPanel = new StudyNewProjectPanel(myGenerator);
mySettingsPanel = new StudyNewProjectPanel(myGenerator, isLocal);
mySettingsPanel.registerValidators(new FacetValidatorsManager() {
public void registerValidator(FacetEditorValidator validator, JComponent... componentsToWatch) {
throw new UnsupportedOperationException();

View File

@@ -61,7 +61,7 @@ public class PyStudyIntroductionCourseAction extends AnAction {
ProjectUtil.openProject(projectDir.getPath(), null, false);
}
else {
final PyStudyDirectoryProjectGenerator generator = new PyStudyDirectoryProjectGenerator();
final PyStudyDirectoryProjectGenerator generator = new PyStudyDirectoryProjectGenerator(true);
final EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(PythonLanguage.getInstance());
final String bundledCoursePath = configurator.getBundledCoursePath();
CourseInfo introCourse = generator.getGenerator().getCourseInfo(bundledCoursePath);