Apply the code style

This commit is contained in:
meanmail
2017-04-14 15:19:38 +07:00
parent 35bc629c48
commit 5aba090129
10 changed files with 60 additions and 85 deletions
@@ -44,9 +44,6 @@ import java.util.List;
import static com.jetbrains.edu.learning.core.EduNames.STUDY_PROJECT_XML_PATH;
import static com.jetbrains.edu.learning.navigation.StudyNavigator.navigateToTask;
/**
* @author meanmail
*/
public class EduBuiltInServerUtils {
public static boolean focusOpenProject(int courseId, int stepId) {
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
@@ -34,12 +34,9 @@ import static com.jetbrains.edu.learning.builtInServer.EduBuiltInServerUtils.*;
import static com.jetbrains.edu.learning.stepic.EduStepicNames.EDU_STEPIK_SERVICE_NAME;
import static com.jetbrains.edu.learning.stepic.EduStepicNames.STEP_ID;
/**
* @author meanmail
*/
public class EduStepikRestService extends RestService {
private static final Logger LOG = Logger.getInstance(EduStepikRestService.class.getName());
private static final Pattern OPEN_COURSE = Pattern.compile("/" + EDU_STEPIK_SERVICE_NAME + "/course/(\\d+)");
private static final Pattern OPEN_COURSE_PATTERN = Pattern.compile("/" + EDU_STEPIK_SERVICE_NAME + "/course/(\\d+)");
@NotNull
@Override
@@ -64,7 +61,7 @@ public class EduStepikRestService extends RestService {
LOG.info("Request: " + urlDecoder.uri());
String path = urlDecoder.path();
Matcher matcher = OPEN_COURSE.matcher(path);
Matcher matcher = OPEN_COURSE_PATTERN.matcher(path);
if (matcher.matches()) {
int courseId = Integer.parseInt(matcher.group(1));
List<String> stepIds = urlDecoder.parameters().get(STEP_ID);
@@ -22,9 +22,6 @@ import com.jetbrains.edu.learning.courseFormat.Course;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author meanmail
*/
public interface EduCourseProjectGenerator {
@NotNull
DirectoryProjectGenerator getDirectoryProjectGenerator();
@@ -47,21 +47,18 @@ import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
/**
* @author meanmail
*/
public class EduCreateNewProjectDialog extends DialogWrapper {
private static final Logger LOG = Logger.getInstance(EduCreateNewProjectDialog.class);
private Project project;
private Course course;
private final List<EduCreateNewProjectListener> listeners = new ArrayList<>();
private final EduCreateNewProjectPanel panel;
private Project myProject;
private Course myCourse;
private final List<EduCreateNewProjectListener> myListeners = new ArrayList<>();
private final EduCreateNewProjectPanel myPanel;
public EduCreateNewProjectDialog() {
super(false);
setTitle("New project");
setTitle("New Project");
Project defaultProject = ProjectManager.getInstance().getDefaultProject();
panel = new EduCreateNewProjectPanel(defaultProject, this);
myPanel = new EduCreateNewProjectPanel(defaultProject, this);
setOKButtonText("Create");
init();
}
@@ -69,45 +66,45 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
@Nullable
@Override
protected JComponent createCenterPanel() {
return panel;
return myPanel;
}
public void addListener(@NotNull EduCreateNewProjectListener listener) {
listeners.add(listener);
myListeners.add(listener);
}
public void setCourse(@Nullable Course course) {
this.course = course;
this.myCourse = course;
}
@Override
protected void doOKAction() {
if (course == null) {
panel.setError("Selected course is null");
if (myCourse == null) {
myPanel.setError("Selected course is null");
return;
}
Language language = course.getLanguageById();
Language language = myCourse.getLanguageById();
if (language == null) {
String message = "Selected course don't have language";
panel.setError(message);
myPanel.setError(message);
LOG.warn(message);
return;
}
EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(language);
if (configurator == null) {
String message = "A configurator for the selected course not found";
panel.setError(message);
myPanel.setError(message);
LOG.warn(message + ": " + language);
return;
}
EduCourseProjectGenerator projectGenerator = configurator.getEduCourseProjectGenerator();
String errorMessage = createProject(projectGenerator);
if (errorMessage != null) {
panel.setError(errorMessage);
myPanel.setError(errorMessage);
return;
}
if (project == null) {
panel.setError("Project did't created");
if (myProject == null) {
myPanel.setError("Project did't created");
return;
}
notifyCreated();
@@ -121,8 +118,8 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
*/
@Nullable
private String createProject(@NotNull final EduCourseProjectGenerator projectGenerator) {
String name = panel.getName();
String path = FileUtil.join(FileUtil.toSystemDependentName(panel.getLocationPath()), name);
String name = myPanel.getName();
String path = FileUtil.join(FileUtil.toSystemDependentName(myPanel.getLocationPath()), name);
ValidationResult result = projectGenerator.validate(path);
if (!result.isOk()) {
@@ -136,7 +133,7 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
return message;
}
projectGenerator.setCourse(course);
projectGenerator.setCourse(myCourse);
final VirtualFile baseDir = ApplicationManager.getApplication()
.runWriteAction((Computable<VirtualFile>)() ->
@@ -152,9 +149,9 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
if (baseDir.getChildren().length > 0) {
String message =
String.format("Directory '%s' is not empty.\nFiles and directories will remove.\nDo you want continue?", location.getAbsolutePath());
int rc = Messages.showYesNoDialog((Project)null, message, "New project", Messages.getQuestionIcon());
int rc = Messages.showYesNoDialog((Project)null, message, "New Project", Messages.getQuestionIcon());
if (rc != Messages.YES) {
panel.resetError();
myPanel.resetError();
return "Canceled by user";
}
}
@@ -179,11 +176,11 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
};
}
EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.noneOf(PlatformProjectOpenProcessor.Option.class);
project = PlatformProjectOpenProcessor.doOpenProject(baseDir, null, -1, callback, options);
myProject = PlatformProjectOpenProcessor.doOpenProject(baseDir, null, -1, callback, options);
return null;
}
private void notifyCreated() {
listeners.forEach(listener -> listener.created(project));
myListeners.forEach(listener -> listener.created(myProject));
}
}
@@ -18,9 +18,6 @@ package com.jetbrains.edu.learning.newproject.ui;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author meanmail
*/
public interface EduCreateNewProjectListener {
void created(@NotNull Project project);
}
@@ -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.learning.newproject.ui.EduCreateNewProjectPanel">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" 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="372" height="88"/>
@@ -17,7 +17,7 @@
<text value="Name:"/>
</properties>
</component>
<component id="160bb" class="javax.swing.JTextField" binding="nameField">
<component id="160bb" class="javax.swing.JTextField" binding="myNameField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="300" height="-1"/>
@@ -33,7 +33,7 @@
<properties/>
<border type="none"/>
<children>
<component id="4fa15" class="javax.swing.JLabel" binding="errorIcon">
<component id="4fa15" class="javax.swing.JLabel" binding="myErrorIcon">
<constraints>
<grid row="0" 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>
@@ -41,7 +41,7 @@
<text value=""/>
</properties>
</component>
<component id="4bdcf" class="javax.swing.JLabel" binding="errorLabel">
<component id="4bdcf" class="javax.swing.JLabel" binding="myErrorLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
@@ -61,7 +61,7 @@
<text value="Location:"/>
</properties>
</component>
<component id="aab8" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="locationField">
<component id="aab8" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myLocationField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="171" height="10"/>
@@ -31,31 +31,28 @@ import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.io.File;
/**
* @author meanmail
*/
public class EduCreateNewProjectPanel extends JPanel {
private JPanel panel;
private JTextField nameField;
private TextFieldWithBrowseButton locationField;
private JLabel errorIcon;
private JLabel errorLabel;
private JPanel myPanel;
private JTextField myNameField;
private TextFieldWithBrowseButton myLocationField;
private JLabel myErrorIcon;
private JLabel myErrorLabel;
public EduCreateNewProjectPanel(@NotNull final Project project, @NotNull EduCreateNewProjectDialog dialog) {
setLayout(new BorderLayout());
add(panel, BorderLayout.CENTER);
errorIcon.setIcon(AllIcons.Actions.Lightning);
add(myPanel, BorderLayout.CENTER);
myErrorIcon.setIcon(AllIcons.Actions.Lightning);
resetError();
String location = RecentProjectsManager.getInstance().getLastProjectCreationLocation();
locationField.setText(location);
myLocationField.setText(location);
String name = ProjectWizardUtil.findNonExistingFileName(location, "course", "");
nameField.setText(name);
myNameField.setText(name);
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
locationField.addBrowseFolderListener("Choose Location Folder", null, project, descriptor);
locationField.addFocusListener(new FocusAdapter() {
myLocationField.addBrowseFolderListener("Choose Location Folder", null, project, descriptor);
myLocationField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
String location = FileUtil.toSystemDependentName(locationField.getText());
String location = FileUtil.toSystemDependentName(myLocationField.getText());
File file = new File(location);
if (!FileUtil.ensureCanCreateFile(file)) {
dialog.setOKActionEnabled(false);
@@ -69,21 +66,21 @@ public class EduCreateNewProjectPanel extends JPanel {
}
private void setState(boolean isVisible) {
errorIcon.setVisible(isVisible);
errorLabel.setVisible(isVisible);
myErrorIcon.setVisible(isVisible);
myErrorLabel.setVisible(isVisible);
}
void setError(@NotNull String message) {
errorLabel.setText(message);
myErrorLabel.setText(message);
setState(true);
}
public String getName() {
return nameField.getText();
return myNameField.getText();
}
public String getLocationPath() {
return locationField.getText();
return myLocationField.getText();
}
public void resetError() {
@@ -29,9 +29,6 @@ import java.io.IOException;
import static com.jetbrains.edu.learning.StudyUtils.execCancelable;
/**
* @author meanmail
*/
public class EduCreateNewStepikProjectDialog extends EduCreateNewProjectDialog {
private static final Logger LOG = Logger.getInstance(EduCreateNewStepikProjectDialog.class);
@@ -52,7 +49,7 @@ public class EduCreateNewStepikProjectDialog extends EduCreateNewProjectDialog {
try {
Course course = EduStepicConnector.getCourseFromStepik(user, courseId);
if (course != null) {
setTitle("New project - " + course.getName());
setTitle("New Project - " + course.getName());
}
setCourse(course);
@@ -34,53 +34,50 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author meanmail
*/
public class PyEduCourseProjectGenerator implements EduCourseProjectGenerator {
private final PyStudyDirectoryProjectGenerator generator;
private final PyStudyDirectoryProjectGenerator myGenerator;
public PyEduCourseProjectGenerator() {
this.generator = new PyStudyDirectoryProjectGenerator();
this.myGenerator = new PyStudyDirectoryProjectGenerator();
}
@NotNull
@Override
public DirectoryProjectGenerator getDirectoryProjectGenerator() {
return generator;
return myGenerator;
}
@Nullable
@Override
public Object getProjectSettings() {
return generator.getProjectSettings();
return myGenerator.getProjectSettings();
}
@Override
public void setCourse(@NotNull Course course) {
generator.setSelectedCourse(course);
myGenerator.setSelectedCourse(course);
}
@Override
public ValidationResult validate(@NotNull String path) {
generator.setValidationResult(ValidationResult.OK);
return generator.validate(path);
myGenerator.setValidationResult(ValidationResult.OK);
return myGenerator.validate(path);
}
@Override
public boolean beforeProjectGenerated() {
BooleanFunction<PythonProjectGenerator> function =
generator.beforeProjectGenerated(null);
return function != null && function.fun(generator);
myGenerator.beforeProjectGenerated(null);
return function != null && function.fun(myGenerator);
}
@Override
public void afterProjectGenerated(@NotNull Project project) {
PyNewProjectSettings settings = (PyNewProjectSettings)generator.getProjectSettings();
PyNewProjectSettings settings = (PyNewProjectSettings)myGenerator.getProjectSettings();
Sdk sdk = settings.getSdk();
if (sdk == null) {
generator.createAndAddVirtualEnv(project, settings);
myGenerator.createAndAddVirtualEnv(project, settings);
sdk = settings.getSdk();
}
@@ -51,7 +51,6 @@ import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.List;
public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyNewProjectSettings> {
private static final Logger LOG = Logger.getInstance(PyStudyDirectoryProjectGenerator.class.getName());
private final StudyProjectGenerator myGenerator;