feat(creation): complete random fill settings

This commit is contained in:
2026-09-01 21:55:11 +04:00
parent c046265d11
commit 62fabdd97c
3 changed files with 90 additions and 3 deletions
@@ -15,6 +15,7 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
private final RandomFillSettings settings;
private final Consumer<RandomFillSettings> onApply;
private final Label collectionSizeLabel;
private final Label minGroupNumberLabel;
private final Label maxGroupNumberLabel;
private final Label minAverageGradeLabel;
@@ -32,6 +33,10 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
Panel panel = new Panel();
panel.setLayoutManager(new LinearLayout());
collectionSizeLabel =
new Label("Размер коллекции: " + getValueOrDefault(settings.getCollectionSize()));
panel.addComponent(collectionSizeLabel);
minGroupNumberLabel =
new Label("Минимальный номер группы: " + getValueOrDefault(settings.getMinGroupNumber()));
@@ -61,6 +66,8 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
panel.addComponent(minRecordBookNumberLabel);
panel.addComponent(maxRecordBookNumberLabel);
panel.addComponent(new Button("Задать размер коллекции...", this::setCollectionSize));
panel.addComponent(new Button("Задать минимальный номер группы", this::setMinGroupNumber));
panel.addComponent(new Button("Задать максимальный номер группы", this::setMaxGroupNumber));
@@ -82,6 +89,41 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
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() {
showGroupNumberInput(
"Минимальный номер группы",
@@ -302,6 +344,12 @@ public class RandomDataSettingsWindow extends BaseModalWindow {
}
private void apply() {
if (settings.getCollectionSize() == null) {
MessageWindow.showModal(gui, "Сначала задайте размер коллекции.");
return;
}
onApply.accept(settings);
MessageWindow.showModal(gui, "Настройки создания коллекции случайно успешно применены.");
@@ -2,6 +2,8 @@ package ru.project.ui.creation.random;
public class RandomFillSettings {
private Integer collectionSize;
private String minGroupNumber;
private String maxGroupNumber;
@@ -12,6 +14,8 @@ public class RandomFillSettings {
private Integer maxRecordBookNumber;
public RandomFillSettings() {
this.collectionSize = null;
this.minGroupNumber = null;
this.maxGroupNumber = null;
@@ -22,6 +26,14 @@ public class RandomFillSettings {
this.maxRecordBookNumber = null;
}
public Integer getCollectionSize() {
return collectionSize;
}
public void setCollectionSize(Integer collectionSize) {
this.collectionSize = collectionSize;
}
public String getMinGroupNumber() {
return minGroupNumber;
}
@@ -1,19 +1,46 @@
package ru.project.ui.creation.random;
import ru.project.collection.MyList;
import ru.project.random.RandomStudentGenerator;
import ru.project.student.Student;
import ru.project.ui.creation.FillStrategy;
public class RandomFillStrategy implements FillStrategy {
// private final RandomFillSettings settings;
private final RandomFillSettings settings;
public RandomFillStrategy(RandomFillSettings settings) {
// this.settings = settings;
this.settings = settings;
}
@Override
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());
}
}