fix EDU-743 Disable create button in new project dialog if no course selected

Properly compare invalid courses.
By accident fixed error label listener also
This commit is contained in:
Ekaterina Tuzova
2016-12-07 15:52:30 +03:00
parent 7a60fe55a2
commit e69e41faff
4 changed files with 22 additions and 7 deletions
@@ -60,9 +60,17 @@ public class CourseInfo {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CourseInfo that = (CourseInfo)o;
if (that.getName() == null || that.getDescription() == null) return false;
return that.getName().equals(getName())
&& that.getDescription().equals(myDescription);
final String thatName = that.getName();
final String thatDescription = that.getDescription();
if (thatName == null && getName() == null && thatDescription == null &&
getDescription() == null) {
return true;
}
if (thatName == null || thatDescription == null) {
return false;
}
return thatName.equals(getName())
&& thatDescription.equals(myDescription);
}
@Override
@@ -70,7 +70,7 @@ public class EduStepicConnector {
return result;
}
catch (IOException e) {
LOG.error("Cannot load course list " + e.getMessage());
LOG.warn("Cannot load course list " + e.getMessage());
}
return Collections.singletonList(CourseInfo.INVALID_COURSE);
}
@@ -216,6 +216,10 @@ public class StudyNewProjectPanel extends JPanel implements PanelWithAnchor {
isComboboxInitialized = true;
initCoursesCombobox();
}
CourseInfo selectedCourse = (CourseInfo)myCoursesComboBox.getSelectedItem();
if (selectedCourse == null || selectedCourse.equals(CourseInfo.INVALID_COURSE)) {
setError(CONNECTION_ERROR);
}
}
});
}
@@ -81,21 +81,24 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator<PyN
addErrorLabelMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (((CourseInfo)mySettingsPanel.getCoursesComboBox().getSelectedItem()).isAdaptive() && !myGenerator.isLoggedIn()) {
final Object selectedItem = mySettingsPanel.getCoursesComboBox().getSelectedItem();
if (selectedItem != null && ((CourseInfo)selectedItem).isAdaptive() && !myGenerator.isLoggedIn()) {
mySettingsPanel.showLoginDialog(false, "Signing In");
}
}
@Override
public void mouseEntered(MouseEvent e) {
if (((CourseInfo)mySettingsPanel.getCoursesComboBox().getSelectedItem()).isAdaptive() && !myGenerator.isLoggedIn()) {
final Object selectedItem = mySettingsPanel.getCoursesComboBox().getSelectedItem();
if (selectedItem != null && ((CourseInfo)selectedItem).isAdaptive() && !myGenerator.isLoggedIn()) {
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
}
@Override
public void mouseExited(MouseEvent e) {
if (((CourseInfo)mySettingsPanel.getCoursesComboBox().getSelectedItem()).isAdaptive() && !myGenerator.isLoggedIn()) {
final CourseInfo selectedItem = (CourseInfo)mySettingsPanel.getCoursesComboBox().getSelectedItem();
if (selectedItem != null && selectedItem.isAdaptive() && !myGenerator.isLoggedIn()) {
e.getComponent().setCursor(Cursor.getDefaultCursor());
}
}