<?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"/>
</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>
</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>
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;
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);
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();
+ }
}
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;
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;
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
@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);
}
@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");
@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();
});
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);
+ }
}