EDU-338 Add supported python versions info to the course.json
authorliana.bakradze <liana.bakradze@jetbrains.com>
Sat, 16 Jul 2016 08:18:55 +0000 (11:18 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Sat, 16 Jul 2016 08:18:55 +0000 (11:18 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/CCUtils.java
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.form
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/ui/CCNewProjectPanel.java
python/educational-core/student/src/com/jetbrains/edu/learning/courseFormat/Course.java
python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java
python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyPluginConfigurator.java

index 2d68478b6845a9ea3c0d11e3461f84dc409170ea..331366280c1793baeb220e5949c9806d1547fa4d 100644 (file)
@@ -44,7 +44,7 @@ public class CCUtils {
 
   @Nullable
   public static CCLanguageManager getStudyLanguageManager(@NotNull final Course course) {
-    Language language = Language.findLanguageByID(course.getLanguage());
+    Language language = Language.findLanguageByID(course.getLanguageID());
     return language == null ? null : CCLanguageManager.INSTANCE.forLanguage(language);
   }
 
index d4c33c0524d1002975c04e394f1c77780b10dfc6..9af0ba14c20930f9feb043d452ab93d16b0db9d0 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.edu.coursecreator.ui.CCNewProjectPanel">
-  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
       <xy x="20" y="20" width="666" height="488"/>
@@ -26,7 +26,7 @@
       </component>
       <component id="ec56c" class="javax.swing.JLabel">
         <constraints>
-          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false">
+          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false">
             <preferred-size width="80" height="-1"/>
           </grid>
         </constraints>
@@ -52,7 +52,7 @@
       </component>
       <component id="389a7" class="javax.swing.JTextArea" binding="myDescription">
         <constraints>
-          <grid row="2" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false">
+          <grid row="3" column="1" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="3" indent="0" use-parent-layout="false">
             <preferred-size width="-1" height="50"/>
           </grid>
         </constraints>
           <lineWrap value="true"/>
         </properties>
       </component>
+      <component id="aa51f" class="javax.swing.JLabel" binding="myLanguageLevelLabel">
+        <constraints>
+          <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="Label"/>
+        </properties>
+      </component>
+      <component id="cfe00" class="com.intellij.openapi.ui.ComboBox" binding="myLanguageLevelCombobox">
+        <constraints>
+          <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties/>
+      </component>
     </children>
   </grid>
 </form>
index b3b141d6cb8c200e9b492905cc2f7a71c64e55da..7b4830c9cb4382ede2d95277bf6d73c72054b849 100644 (file)
@@ -1,10 +1,12 @@
 package com.jetbrains.edu.coursecreator.ui;
 
 import com.intellij.facet.ui.FacetValidatorsManager;
+import com.intellij.openapi.ui.ComboBox;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.ui.DocumentAdapter;
 import com.intellij.ui.JBColor;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import javax.swing.event.DocumentEvent;
@@ -14,10 +16,14 @@ public class CCNewProjectPanel {
   private JTextArea myDescription;
   private JTextField myName;
   private JTextField myAuthorField;
+  private JLabel myLanguageLevelLabel;
+  private ComboBox<String> myLanguageLevelCombobox;
   private FacetValidatorsManager myValidationManager;
 
 
   public CCNewProjectPanel() {
+    myLanguageLevelLabel.setVisible(false);
+    myLanguageLevelCombobox.setVisible(false);
     final String userName = System.getProperty("user.name");
     if (userName != null) {
       myAuthorField.setText(userName);
@@ -81,4 +87,20 @@ public class CCNewProjectPanel {
   public JTextField getNameField() {
     return myName;
   }
+
+  public JLabel getLanguageLevelLabel() {
+    return myLanguageLevelLabel;
+  }
+
+  public ComboBox<String> getLanguageLevelCombobox() {
+    return myLanguageLevelCombobox;
+  }
+
+  @Nullable
+  public String getLanguageVersion() {
+    if (!myLanguageLevelCombobox.isVisible() || myLanguageLevelCombobox.getItemCount() == 0) {
+      return null;
+    }
+    return (String)myLanguageLevelCombobox.getSelectedItem();
+  }
 }
index fa4f4759475717635b2c9b3a5f02ef9139410528..98e3eeca0f1b01408b1b187b343925dd89b85209 100644 (file)
@@ -10,6 +10,7 @@ import com.jetbrains.edu.learning.core.EduUtils;
 import com.jetbrains.edu.learning.stepic.StepicUser;
 import org.jdom.Element;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -122,9 +123,14 @@ public class Course {
   }
 
   public Language getLanguageById() {
-    return Language.findLanguageByID(myLanguage);
+    return Language.findLanguageByID(getLanguageID());
   }
 
+  /**
+   * This method should be used by serialized only
+   * Use {@link #getLanguageID()} and {@link #getLanguageVersion()} methods instead
+   */
+  @Deprecated
   public String getLanguage() {
     return myLanguage;
   }
@@ -133,6 +139,19 @@ public class Course {
     myLanguage = language;
   }
 
+  public String getLanguageID() {
+    return myLanguage.split(" ")[0];
+  }
+
+  @Nullable
+  public String getLanguageVersion() {
+    String[] split = myLanguage.split(" ");
+    if (split.length <= 1) {
+      return null;
+    }
+    return split[1];
+  }
+
   public void setAuthors(List<StepicUser> authors) {
     this.authors = authors;
   }
index b0b612df6f2ea984deb38bc191ecd4d119ecb608..b37ea4c4f0f0638b65a8cfab651f48ebea9e416c 100644 (file)
@@ -12,6 +12,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.progress.ProcessCanceledException;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.ComboBox;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.platform.DirectoryProjectGenerator;
@@ -27,6 +28,7 @@ import com.jetbrains.edu.learning.courseFormat.Course;
 import com.jetbrains.edu.learning.statistics.EduUsagesCollector;
 import com.jetbrains.python.PythonLanguage;
 import com.jetbrains.python.newProject.PythonProjectGenerator;
+import com.jetbrains.python.psi.LanguageLevel;
 import icons.CourseCreatorPythonIcons;
 import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NotNull;
@@ -38,6 +40,9 @@ import java.io.File;
 
 public class PyCCProjectGenerator extends PythonProjectGenerator implements DirectoryProjectGenerator {
   private static final Logger LOG = Logger.getInstance(PyCCProjectGenerator.class);
+  public static final String ALL_VERSIONS = "All versions";
+  public static final String PYTHON_3 = "3x";
+  public static final String PYTHON_2 = "2x";
   private CCNewProjectPanel mySettingsPanel;
 
   @Nls
@@ -56,14 +61,11 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
   @Override
   public void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir,
                               @Nullable Object settings, @NotNull Module module) {
-    generateProject(project, baseDir, mySettingsPanel.getName(),
-                    mySettingsPanel.getAuthors(), mySettingsPanel.getDescription());
+    generateProject(project, baseDir, mySettingsPanel);
   }
 
-  public static void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir,
-                                     @NotNull final String name, @NotNull final String[] authors,
-                                     @NotNull final String description) {
-    final Course course = getCourse(project, name, authors, description);
+  public static void generateProject(@NotNull final Project project, @NotNull final VirtualFile baseDir, CCNewProjectPanel settingsPanel) {
+    final Course course = getCourse(project, settingsPanel);
     EduUsagesCollector.projectTypeCreated(CCUtils.COURSE_MODE);
 
     final PsiDirectory projectDir = PsiManager.getInstance(project).findDirectory(baseDir);
@@ -94,12 +96,19 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
   }
 
   @NotNull
-  private static Course getCourse(@NotNull Project project, @NotNull String name, @NotNull String[] authors, @NotNull String description) {
+  private static Course getCourse(@NotNull Project project, @NotNull CCNewProjectPanel settingsPanel) {
     final Course course = new Course();
+    String name = settingsPanel.getName();
     course.setName(name);
-    course.setAuthors(authors);
-    course.setDescription(description);
-    course.setLanguage(PythonLanguage.getInstance().getID());
+    course.setAuthors(settingsPanel.getAuthors());
+    course.setDescription(settingsPanel.getDescription());
+
+    String language = PythonLanguage.getInstance().getID();
+    String version = settingsPanel.getLanguageVersion();
+    if (version != null && !ALL_VERSIONS.equals(version)) {
+      language += " " + version;
+    }
+    course.setLanguage(language);
     course.setCourseMode(CCUtils.COURSE_MODE);
 
     File coursesDir = new File(PathManager.getConfigPath(), "courses");
@@ -125,6 +134,7 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
   @Override
   public JPanel extendBasePanel() throws ProcessCanceledException {
     mySettingsPanel = new CCNewProjectPanel();
+    setupLanguageLevels(mySettingsPanel);
     mySettingsPanel.registerValidators(new FacetValidatorsManager() {
       public void registerValidator(FacetEditorValidator validator, JComponent... componentsToWatch) {
         throw new UnsupportedOperationException();
@@ -136,4 +146,18 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire
     });
     return mySettingsPanel.getMainPanel();
   }
+
+  private static void setupLanguageLevels(CCNewProjectPanel panel) {
+    JLabel languageLevelLabel = panel.getLanguageLevelLabel();
+    languageLevelLabel.setText("Python Version:");
+    languageLevelLabel.setVisible(true);
+    ComboBox<String> languageLevelCombobox = panel.getLanguageLevelCombobox();
+    languageLevelCombobox.addItem(ALL_VERSIONS);
+    languageLevelCombobox.addItem(PYTHON_3);
+    languageLevelCombobox.addItem(PYTHON_2);
+    for (LanguageLevel level : LanguageLevel.values()) {
+      languageLevelCombobox.addItem(level.toString());
+    }
+    languageLevelCombobox.setVisible(true);
+  }
 }
index 5a163337ecfa575a54d1c05dac31ae62dfd3a1d2..76890be134209a3ca5c98020d8988fa33bbcd811 100644 (file)
@@ -34,6 +34,6 @@ public class PyStudyPluginConfigurator extends StudyBasePluginConfigurator {
     StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
     if (taskManager == null) return false;
     Course course = taskManager.getCourse();
-    return course != null && "Python".equals(course.getLanguage()) && "PyCharm".equals(course.getCourseType());
+    return course != null && "Python".equals(course.getLanguageID()) && "PyCharm".equals(course.getCourseType());
   }
 }