feat: add custom data collection settings

Add support for storing and configuring custom student data
collections in AppState.

Introduce a custom data settings window for entering and validating
student fields, selecting an object index, previewing student data,
and applying prepared data to the current collection.

Refactor collection creation to use reusable input handling and
update collection display and message window usage.
This commit is contained in:
2026-08-28 19:51:47 +04:00
parent 5d0052805c
commit ff0c063078
4 changed files with 350 additions and 29 deletions
@@ -8,7 +8,8 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import ru.project.model.AppState;
import ru.project.model.FillMethod;
import ru.project.ui.base.BaseWindow;
import ru.project.ui.window.CollectionSizeInputWindow;
import ru.project.ui.window.CustomDataSettingsWindow;
import ru.project.ui.window.InputValueWindow;
import ru.project.ui.window.MessageWindow;
public class CreateCollectionMenu extends BaseWindow {
@@ -19,9 +20,13 @@ public class CreateCollectionMenu extends BaseWindow {
private final Label sizeLabel;
private final Label fillMethodLabel;
private final AppState state;
public CreateCollectionMenu(WindowBasedTextGUI gui, AppState state) {
super("Создание новой коллекции", gui);
this.state = state;
collectionSize = 0;
selectedFillMethod = FillMethod.CUSTOM;
@@ -35,9 +40,12 @@ public class CreateCollectionMenu extends BaseWindow {
panel.addComponent(sizeLabel);
panel.addComponent(fillMethodLabel);
panel.addComponent(new Button("Задать размер", this::openCollectionSizeInputWindow));
panel.addComponent(new Button("Задать размер", this::openCollectionSizeInputValueWindow));
panel.addComponent(new Button("Настроить способ заполнения", this::openFillMethodMenu));
panel.addComponent(new Button("Выбрать способ заполнения", this::selectFillMethod));
panel.addComponent(
new Button("Настроить текущий способ заполнения", this::setupCurrentFillMethod));
panel.addComponent(new Button("Создать новую коллекцию", this::createCollection));
@@ -46,20 +54,53 @@ public class CreateCollectionMenu extends BaseWindow {
setComponent(panel);
}
private void openCollectionSizeInputWindow() {
CollectionSizeInputWindow window =
new CollectionSizeInputWindow(
private void openCollectionSizeInputValueWindow() {
InputValueWindow window =
new InputValueWindow(
gui,
size -> {
collectionSize = size;
sizeLabel.setText("Размер: " + collectionSize);
});
"Размер коллекции",
"Введите размер коллекции:",
collectionSize > 0 ? String.valueOf(collectionSize) : null,
this::handleSizeEntered);
window.show();
}
private void openFillMethodMenu() {
FillMethodSelectionWindow menu =
private boolean handleSizeEntered(String value) {
try {
int enteredSize = Integer.parseInt(value);
if (enteredSize <= 0) {
MessageWindow.show(gui, "Размер должен быть больше 0.");
return false;
}
collectionSize = enteredSize;
sizeLabel.setText("Размер: " + collectionSize);
return true;
} catch (NumberFormatException e) {
MessageWindow.show(gui, "Введите целое число.");
return false;
}
}
private void setupCurrentFillMethod() {
switch (selectedFillMethod) {
case CUSTOM -> {
BaseWindow window = new CustomDataSettingsWindow(gui, state, collectionSize);
window.show();
}
case FILE ->
// TODO
MessageWindow.show(gui, "Не реализовано.");
case RANDOM ->
MessageWindow.show(gui, "Для случайных данных дополнительные настройки не требуются.");
}
}
private void selectFillMethod() {
BaseWindow menu =
new FillMethodSelectionWindow(
gui,
fillMethod -> {
@@ -73,7 +114,7 @@ public class CreateCollectionMenu extends BaseWindow {
private void createCollection() {
if (collectionSize <= 0) {
MessageWindow.create(gui, "Сначала задайте размер коллекции.");
MessageWindow.show(gui, "Сначала задайте размер коллекции.");
return;
}
@@ -94,17 +135,17 @@ public class CreateCollectionMenu extends BaseWindow {
private void createCollectionFromCustomData() {
// TODO
MessageWindow.create(gui, "Не реализовано.");
MessageWindow.show(gui, "Не реализовано.");
}
private void createCollectionFromRandomData() {
// TODO
MessageWindow.create(gui, "Не реализовано.");
MessageWindow.show(gui, "Не реализовано.");
}
private void createCollectionFromFileData() {
// TODO
MessageWindow.create(gui, "Не реализовано.");
MessageWindow.show(gui, "Не реализовано.");
}
private String getFillMethodName(FillMethod fillMethod) {