feat(creation): complete random fill settings
This commit is contained in:
@@ -15,6 +15,7 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
|
|||||||
private final RandomFillSettings settings;
|
private final RandomFillSettings settings;
|
||||||
private final Consumer<RandomFillSettings> onApply;
|
private final Consumer<RandomFillSettings> onApply;
|
||||||
|
|
||||||
|
private final Label collectionSizeLabel;
|
||||||
private final Label minGroupNumberLabel;
|
private final Label minGroupNumberLabel;
|
||||||
private final Label maxGroupNumberLabel;
|
private final Label maxGroupNumberLabel;
|
||||||
private final Label minAverageGradeLabel;
|
private final Label minAverageGradeLabel;
|
||||||
@@ -32,6 +33,10 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
|
|||||||
Panel panel = new Panel();
|
Panel panel = new Panel();
|
||||||
panel.setLayoutManager(new LinearLayout());
|
panel.setLayoutManager(new LinearLayout());
|
||||||
|
|
||||||
|
collectionSizeLabel =
|
||||||
|
new Label("Размер коллекции: " + getValueOrDefault(settings.getCollectionSize()));
|
||||||
|
|
||||||
|
panel.addComponent(collectionSizeLabel);
|
||||||
minGroupNumberLabel =
|
minGroupNumberLabel =
|
||||||
new Label("Минимальный номер группы: " + getValueOrDefault(settings.getMinGroupNumber()));
|
new Label("Минимальный номер группы: " + getValueOrDefault(settings.getMinGroupNumber()));
|
||||||
|
|
||||||
@@ -61,6 +66,8 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
|
|||||||
panel.addComponent(minRecordBookNumberLabel);
|
panel.addComponent(minRecordBookNumberLabel);
|
||||||
panel.addComponent(maxRecordBookNumberLabel);
|
panel.addComponent(maxRecordBookNumberLabel);
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Задать размер коллекции...", this::setCollectionSize));
|
||||||
|
|
||||||
panel.addComponent(new Button("Задать минимальный номер группы", this::setMinGroupNumber));
|
panel.addComponent(new Button("Задать минимальный номер группы", this::setMinGroupNumber));
|
||||||
|
|
||||||
panel.addComponent(new Button("Задать максимальный номер группы", this::setMaxGroupNumber));
|
panel.addComponent(new Button("Задать максимальный номер группы", this::setMaxGroupNumber));
|
||||||
@@ -82,6 +89,41 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
|
|||||||
setComponent(panel);
|
setComponent(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCollectionSize() {
|
||||||
|
InputValueWindow window =
|
||||||
|
new InputValueWindow(
|
||||||
|
gui,
|
||||||
|
"Размер коллекции",
|
||||||
|
"Введите размер коллекции:",
|
||||||
|
settings.getCollectionSize() == null
|
||||||
|
? null
|
||||||
|
: String.valueOf(settings.getCollectionSize()),
|
||||||
|
value -> {
|
||||||
|
try {
|
||||||
|
int collectionSize = Integer.parseInt(value);
|
||||||
|
|
||||||
|
if (collectionSize <= 0) {
|
||||||
|
MessageWindow.showModal(gui, "Размер коллекции должен быть больше 0.");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.setCollectionSize(collectionSize);
|
||||||
|
|
||||||
|
collectionSizeLabel.setText("Размер коллекции: " + collectionSize);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
MessageWindow.showModal(gui, "Введите целое число.");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.showModal();
|
||||||
|
}
|
||||||
|
|
||||||
private void setMinGroupNumber() {
|
private void setMinGroupNumber() {
|
||||||
showGroupNumberInput(
|
showGroupNumberInput(
|
||||||
"Минимальный номер группы",
|
"Минимальный номер группы",
|
||||||
@@ -302,6 +344,12 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void apply() {
|
private void apply() {
|
||||||
|
if (settings.getCollectionSize() == null) {
|
||||||
|
MessageWindow.showModal(gui, "Сначала задайте размер коллекции.");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onApply.accept(settings);
|
onApply.accept(settings);
|
||||||
|
|
||||||
MessageWindow.showModal(gui, "Настройки создания коллекции случайно успешно применены.");
|
MessageWindow.showModal(gui, "Настройки создания коллекции случайно успешно применены.");
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package ru.project.ui.creation.random;
|
|||||||
|
|
||||||
public class RandomFillSettings {
|
public class RandomFillSettings {
|
||||||
|
|
||||||
|
private Integer collectionSize;
|
||||||
|
|
||||||
private String minGroupNumber;
|
private String minGroupNumber;
|
||||||
private String maxGroupNumber;
|
private String maxGroupNumber;
|
||||||
|
|
||||||
@@ -12,6 +14,8 @@ public class RandomFillSettings {
|
|||||||
private Integer maxRecordBookNumber;
|
private Integer maxRecordBookNumber;
|
||||||
|
|
||||||
public RandomFillSettings() {
|
public RandomFillSettings() {
|
||||||
|
this.collectionSize = null;
|
||||||
|
|
||||||
this.minGroupNumber = null;
|
this.minGroupNumber = null;
|
||||||
this.maxGroupNumber = null;
|
this.maxGroupNumber = null;
|
||||||
|
|
||||||
@@ -22,6 +26,14 @@ public class RandomFillSettings {
|
|||||||
this.maxRecordBookNumber = null;
|
this.maxRecordBookNumber = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getCollectionSize() {
|
||||||
|
return collectionSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCollectionSize(Integer collectionSize) {
|
||||||
|
this.collectionSize = collectionSize;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMinGroupNumber() {
|
public String getMinGroupNumber() {
|
||||||
return minGroupNumber;
|
return minGroupNumber;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,46 @@
|
|||||||
package ru.project.ui.creation.random;
|
package ru.project.ui.creation.random;
|
||||||
|
|
||||||
import ru.project.collection.MyList;
|
import ru.project.collection.MyList;
|
||||||
|
import ru.project.random.RandomStudentGenerator;
|
||||||
import ru.project.student.Student;
|
import ru.project.student.Student;
|
||||||
import ru.project.ui.creation.FillStrategy;
|
import ru.project.ui.creation.FillStrategy;
|
||||||
|
|
||||||
public class RandomFillStrategy implements FillStrategy {
|
public class RandomFillStrategy implements FillStrategy {
|
||||||
|
|
||||||
// private final RandomFillSettings settings;
|
private final RandomFillSettings settings;
|
||||||
|
|
||||||
public RandomFillStrategy(RandomFillSettings settings) {
|
public RandomFillStrategy(RandomFillSettings settings) {
|
||||||
// this.settings = settings;
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MyList<Student> create() {
|
public MyList<Student> create() {
|
||||||
return null;
|
RandomStudentGenerator generator = new RandomStudentGenerator();
|
||||||
|
|
||||||
|
if (settings.getMinGroupNumber() != null) {
|
||||||
|
generator.setMinGroupNumber(settings.getMinGroupNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.getMaxGroupNumber() != null) {
|
||||||
|
generator.setMaxGroupNumber(settings.getMaxGroupNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.getMinAverageGrade() != null) {
|
||||||
|
generator.setMinAverageGrade(settings.getMinAverageGrade());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.getMaxAverageGrade() != null) {
|
||||||
|
generator.setMaxAverageGrade(settings.getMaxAverageGrade());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.getMinRecordBookNumber() != null) {
|
||||||
|
generator.setMinRecordBookNumber(settings.getMinRecordBookNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.getMaxRecordBookNumber() != null) {
|
||||||
|
generator.setMaxRecordBookNumber(settings.getMaxRecordBookNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
return generator.generate(settings.getCollectionSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user