Minor refactoring

This commit is contained in:
meanmail
2017-04-08 23:16:39 +07:00
parent 755171101f
commit d0b08b2d67
5 changed files with 20 additions and 16 deletions
@@ -29,19 +29,19 @@ import org.jetbrains.annotations.Nullable;
public class EduProjectCreator {
public static final ExtensionPointName<EduProjectCreator> EP_NAME = ExtensionPointName.create("Edu.eduProjectCreator");
public static boolean createProject(@NotNull Course course, @Nullable Consumer<Project> callback) {
public static boolean createProject(@NotNull Course course, @Nullable Consumer<Project> onCreated) {
EduProjectCreator[] extensions = Extensions.getExtensions(EP_NAME);
for (EduProjectCreator projectCreator : extensions) {
if (projectCreator.canCreateProject(course)) {
return projectCreator.createCourseProject(course, callback);
return projectCreator.createCourseProject(course, onCreated);
}
}
return false;
}
public boolean createCourseProject(@NotNull Course course, @Nullable Consumer<Project> callback) {
public boolean createCourseProject(@NotNull Course course, @Nullable Consumer<Project> onCreated) {
return false;
}
@@ -169,7 +169,7 @@ public class Utils {
});
for (Course course : availableCourses) {
if (course instanceof RemoteCourse && ((RemoteCourse)course).getId() == courseId) {
Consumer<Project> callback = project ->
Consumer<Project> onCreated = project ->
ApplicationManager.getApplication().invokeLater(() -> {
StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
Course targetCourse = taskManager.getCourse();
@@ -177,7 +177,7 @@ public class Utils {
navigateToStep(project, targetCourse, stepId);
}
});
return EduProjectCreator.createProject(course, callback);
return EduProjectCreator.createProject(course, onCreated);
}
}
return false;
@@ -57,7 +57,7 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
private static final Logger LOG = Logger.getInstance(PyStudyDirectoryProjectGenerator.class.getName());
private final StudyProjectGenerator myGenerator;
private static final String NO_PYTHON_INTERPRETER = "<html><u>Add</u> python interpreter.</html>";
private final Consumer<Project> myCallback;
private final Consumer<Project> myOnCreated;
public ValidationResult myValidationResult = new ValidationResult("selected course is not valid");
private final StudyNewProjectPanel mySettingsPanel;
@@ -66,8 +66,8 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
this(false);
}
public PyStudyDirectoryProjectGenerator(boolean isLocal, @Nullable Consumer<Project> callback) {
myCallback = callback;
public PyStudyDirectoryProjectGenerator(boolean isLocal, @Nullable Consumer<Project> onCreated) {
myOnCreated = onCreated;
myGenerator = new StudyProjectGenerator();
myGenerator.addSettingsStateListener(new StudyProjectGenerator.SettingsListener() {
@Override
@@ -150,8 +150,12 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
LOG.error("Can't copy test_helper.py " + exception.getMessage());
}
if (myCallback != null) {
myCallback.consume(project);
doCreated(project);
}
protected void doCreated(@NotNull Project project) {
if (myOnCreated != null) {
myOnCreated.consume(project);
}
}
@@ -31,17 +31,17 @@ import java.util.ArrayList;
* @author meanmail
*/
public class BuiltInServerNewProjectStep extends PyCharmNewProjectStep {
public BuiltInServerNewProjectStep(@NotNull Course course, @Nullable Consumer<Project> callback) {
super(new BuiltInServerNewProjectStep.MyCustomization(course, callback));
public BuiltInServerNewProjectStep(@NotNull Course course, @Nullable Consumer<Project> onCreated) {
super(new BuiltInServerNewProjectStep.MyCustomization(course, onCreated));
}
protected static class MyCustomization extends PyCharmNewProjectStep.Customization {
private final Course myCourse;
private final PyStudyDirectoryProjectGenerator myGenerator;
public MyCustomization(@NotNull Course course, @Nullable Consumer<Project> callback) {
public MyCustomization(@NotNull Course course, @Nullable Consumer<Project> onCreated) {
myCourse = course;
myGenerator = new PyStudyDirectoryProjectGenerator(true, callback);
myGenerator = new PyStudyDirectoryProjectGenerator(true, onCreated);
}
@NotNull
@@ -35,12 +35,12 @@ public class EduPythonProjectCreator extends EduProjectCreator {
}
@Override
public boolean createCourseProject(@NotNull Course course, @Nullable Consumer<Project> callback) {
public boolean createCourseProject(@NotNull Course course, @Nullable Consumer<Project> onCreated) {
ApplicationManager.getApplication().invokeAndWait(() -> {
AbstractNewProjectDialog dlg = new AbstractNewProjectDialog() {
@Override
protected DefaultActionGroup createRootStep() {
return new BuiltInServerNewProjectStep(course, callback);
return new BuiltInServerNewProjectStep(course, onCreated);
}
};
dlg.show();