2026-08-29 23:37:58 +04:00
|
|
|
package ru.project.ui.creation;
|
2026-08-27 18:03:01 +04:00
|
|
|
|
|
|
|
|
import com.googlecode.lanterna.gui2.Button;
|
|
|
|
|
import com.googlecode.lanterna.gui2.Label;
|
|
|
|
|
import com.googlecode.lanterna.gui2.LinearLayout;
|
|
|
|
|
import com.googlecode.lanterna.gui2.Panel;
|
|
|
|
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
|
|
|
|
import ru.project.model.AppState;
|
2026-08-29 18:42:22 +04:00
|
|
|
import ru.project.ui.base.BaseModalWindow;
|
2026-08-29 23:37:58 +04:00
|
|
|
import ru.project.ui.common.MessageWindow;
|
2026-08-30 23:46:53 +04:00
|
|
|
import ru.project.ui.creation.file.FileDataSettingsWindow;
|
|
|
|
|
import ru.project.ui.creation.file.FileFillSettings;
|
|
|
|
|
import ru.project.ui.creation.file.FileFillStrategy;
|
|
|
|
|
import ru.project.ui.creation.manual.ManualDataSettingsWindow;
|
|
|
|
|
import ru.project.ui.creation.manual.ManualFillSettings;
|
|
|
|
|
import ru.project.ui.creation.manual.ManualFillStrategy;
|
2026-08-27 18:03:01 +04:00
|
|
|
|
2026-08-29 18:42:22 +04:00
|
|
|
public class CreateCollectionMenu extends BaseModalWindow {
|
2026-08-27 18:03:01 +04:00
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
private final AppState state;
|
|
|
|
|
|
2026-08-27 18:03:01 +04:00
|
|
|
private FillMethod selectedFillMethod;
|
2026-08-30 23:46:53 +04:00
|
|
|
private FillStrategy fillStrategy;
|
2026-08-27 18:03:01 +04:00
|
|
|
|
|
|
|
|
private final Label fillMethodLabel;
|
|
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
private final ManualDataSettingsWindow manualDataSettingsWindow;
|
|
|
|
|
private final FileDataSettingsWindow fileDataSettingsWindow;
|
2026-08-28 19:51:47 +04:00
|
|
|
|
2026-08-27 18:03:01 +04:00
|
|
|
public CreateCollectionMenu(WindowBasedTextGUI gui, AppState state) {
|
2026-08-30 23:46:53 +04:00
|
|
|
|
2026-08-27 18:03:01 +04:00
|
|
|
super("Создание новой коллекции", gui);
|
|
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
this.state = state;
|
|
|
|
|
this.selectedFillMethod = FillMethod.CUSTOM;
|
|
|
|
|
this.fillStrategy = null;
|
2026-08-27 18:03:01 +04:00
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
this.manualDataSettingsWindow = new ManualDataSettingsWindow(gui, this::setManualFillStrategy);
|
|
|
|
|
this.fileDataSettingsWindow = new FileDataSettingsWindow(gui, this::setFileFillStrategy);
|
2026-08-29 18:42:22 +04:00
|
|
|
|
2026-08-27 18:03:01 +04:00
|
|
|
Panel panel = new Panel();
|
|
|
|
|
panel.setLayoutManager(new LinearLayout());
|
|
|
|
|
|
|
|
|
|
fillMethodLabel = new Label("Способ заполнения: " + getFillMethodName(selectedFillMethod));
|
|
|
|
|
|
|
|
|
|
panel.addComponent(fillMethodLabel);
|
|
|
|
|
|
2026-08-28 19:51:47 +04:00
|
|
|
panel.addComponent(new Button("Выбрать способ заполнения", this::selectFillMethod));
|
|
|
|
|
|
|
|
|
|
panel.addComponent(
|
|
|
|
|
new Button("Настроить текущий способ заполнения", this::setupCurrentFillMethod));
|
2026-08-27 18:03:01 +04:00
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
panel.addComponent(new Button("Создать новую коллекцию", this::updateMainCollection));
|
2026-08-27 18:03:01 +04:00
|
|
|
|
|
|
|
|
panel.addComponent(new Button("Выйти", this::close));
|
|
|
|
|
|
|
|
|
|
setComponent(panel);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
private void setManualFillStrategy(ManualFillSettings settings) {
|
|
|
|
|
fillStrategy = new ManualFillStrategy(settings);
|
2026-08-27 18:03:01 +04:00
|
|
|
}
|
|
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
private void setFileFillStrategy(FileFillSettings settings) {
|
|
|
|
|
fillStrategy = new FileFillStrategy(settings);
|
2026-08-28 19:51:47 +04:00
|
|
|
}
|
|
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
// private void setRandomFillStrategy(RandomFillSettings settings) {
|
|
|
|
|
// fillStrategy = new RandomFillStrategy(settings);
|
|
|
|
|
// }
|
|
|
|
|
|
2026-08-28 19:51:47 +04:00
|
|
|
private void setupCurrentFillMethod() {
|
|
|
|
|
switch (selectedFillMethod) {
|
2026-08-30 23:46:53 +04:00
|
|
|
case CUSTOM -> manualDataSettingsWindow.showModal();
|
2026-08-28 19:51:47 +04:00
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
case FILE -> fileDataSettingsWindow.showModal();
|
2026-08-28 19:51:47 +04:00
|
|
|
|
|
|
|
|
case RANDOM ->
|
2026-08-29 18:42:22 +04:00
|
|
|
MessageWindow.showModal(
|
|
|
|
|
gui, "Для случайных данных дополнительные настройки не требуются.");
|
2026-08-28 19:51:47 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void selectFillMethod() {
|
2026-08-29 18:42:22 +04:00
|
|
|
BaseModalWindow menu =
|
2026-08-27 18:03:01 +04:00
|
|
|
new FillMethodSelectionWindow(
|
|
|
|
|
gui,
|
|
|
|
|
fillMethod -> {
|
|
|
|
|
selectedFillMethod = fillMethod;
|
2026-08-30 23:46:53 +04:00
|
|
|
|
2026-08-27 18:03:01 +04:00
|
|
|
fillMethodLabel.setText(
|
|
|
|
|
"Способ заполнения: " + getFillMethodName(selectedFillMethod));
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-29 18:42:22 +04:00
|
|
|
menu.showModal();
|
2026-08-27 18:03:01 +04:00
|
|
|
}
|
|
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
private void updateMainCollection() {
|
|
|
|
|
if (fillStrategy == null) {
|
|
|
|
|
MessageWindow.showModal(gui, "Сначала настройте способ заполнения.");
|
2026-08-29 18:42:22 +04:00
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
return;
|
2026-08-29 18:42:22 +04:00
|
|
|
}
|
|
|
|
|
|
2026-08-30 23:46:53 +04:00
|
|
|
state.setMainCollection(fillStrategy.create());
|
2026-08-29 18:42:22 +04:00
|
|
|
|
|
|
|
|
MessageWindow.showModal(gui, "Коллекция успешно создана.");
|
2026-08-27 18:03:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getFillMethodName(FillMethod fillMethod) {
|
|
|
|
|
return switch (fillMethod) {
|
|
|
|
|
case CUSTOM -> "Пользовательские данные";
|
|
|
|
|
case RANDOM -> "Случайные данные";
|
|
|
|
|
case FILE -> "Данные из файла";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|