feat(creation): add file-based fill settings and strategy
- add FileFillSettings and FileFillStrategy - add file path type selection - add FileDataSettingsWindow for file configuration
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
package ru.project.ui.creation.file;
|
||||||
|
|
||||||
|
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 com.googlecode.lanterna.gui2.dialogs.FileDialog;
|
||||||
|
import com.googlecode.lanterna.gui2.dialogs.FileDialogBuilder;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import ru.project.ui.base.BaseModalWindow;
|
||||||
|
|
||||||
|
public class FileDataSettingsWindow extends BaseModalWindow {
|
||||||
|
|
||||||
|
// private final StudentBuilder studentBuilder;
|
||||||
|
|
||||||
|
private final FileFillSettings settings;
|
||||||
|
private final Consumer<FileFillSettings> onApply;
|
||||||
|
|
||||||
|
private final Label filePathLabel;
|
||||||
|
|
||||||
|
public FileDataSettingsWindow(WindowBasedTextGUI gui, Consumer<FileFillSettings> onApply) {
|
||||||
|
|
||||||
|
super("Данные из файла", gui);
|
||||||
|
|
||||||
|
this.onApply = onApply;
|
||||||
|
|
||||||
|
this.settings = new FileFillSettings();
|
||||||
|
// this.studentBuilder = new StudentBuilder();
|
||||||
|
|
||||||
|
Panel panel = new Panel();
|
||||||
|
panel.setLayoutManager(new LinearLayout());
|
||||||
|
|
||||||
|
filePathLabel = new Label("Абсолютный путь: " + getFilePathLabel());
|
||||||
|
|
||||||
|
panel.addComponent(filePathLabel);
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Выбрать файл", this::selectFile));
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Применить", this::apply));
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Выйти", this::close));
|
||||||
|
|
||||||
|
setComponent(panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectFile() {
|
||||||
|
FileDialog fileDialog =
|
||||||
|
new FileDialogBuilder()
|
||||||
|
.setTitle("Выбор файла")
|
||||||
|
.setDescription("Выберите файл:")
|
||||||
|
.setActionLabel("Открыть")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
File selectedFile = fileDialog.showDialog(gui);
|
||||||
|
|
||||||
|
if (selectedFile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.setAbsoluteFilePath(selectedFile.getAbsolutePath());
|
||||||
|
|
||||||
|
filePathLabel.setText("Абсолютный путь: " + settings.getAbsoluteFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void apply() {
|
||||||
|
onApply.accept(settings);
|
||||||
|
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFilePathLabel() {
|
||||||
|
String filePath = settings.getAbsoluteFilePath();
|
||||||
|
|
||||||
|
return filePath == null || filePath.isBlank() ? "не задан" : filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package ru.project.ui.creation.file;
|
||||||
|
|
||||||
|
public class FileFillSettings {
|
||||||
|
|
||||||
|
private String absoluteFilePath;
|
||||||
|
|
||||||
|
public FileFillSettings() {
|
||||||
|
this.absoluteFilePath = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAbsoluteFilePath() {
|
||||||
|
return absoluteFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAbsoluteFilePath(String absoluteFilePath) {
|
||||||
|
this.absoluteFilePath = absoluteFilePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package ru.project.ui.creation.file;
|
||||||
|
|
||||||
|
import ru.project.collection.MyList;
|
||||||
|
import ru.project.student.Student;
|
||||||
|
import ru.project.ui.creation.FillStrategy;
|
||||||
|
|
||||||
|
public class FileFillStrategy implements FillStrategy {
|
||||||
|
|
||||||
|
// private final FileFillSettings settings;
|
||||||
|
|
||||||
|
public FileFillStrategy(FileFillSettings settings) {
|
||||||
|
// this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MyList<Student> create() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package ru.project.ui.creation.file;
|
||||||
|
|
||||||
|
public enum FilePathType {
|
||||||
|
ABSOLUTE,
|
||||||
|
RELATIVE
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package ru.project.ui.creation.file;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.ActionListBox;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import ru.project.ui.base.BaseModalWindow;
|
||||||
|
|
||||||
|
public class FilePathTypeSelectionWindow extends BaseModalWindow {
|
||||||
|
|
||||||
|
private final Consumer<FilePathType> onPathTypeSelected;
|
||||||
|
|
||||||
|
public FilePathTypeSelectionWindow(
|
||||||
|
WindowBasedTextGUI gui, Consumer<FilePathType> onPathTypeSelected) {
|
||||||
|
|
||||||
|
super("Выбор типа пути", gui);
|
||||||
|
|
||||||
|
this.onPathTypeSelected = onPathTypeSelected;
|
||||||
|
|
||||||
|
ActionListBox menu = new ActionListBox();
|
||||||
|
|
||||||
|
menu.addItem("Абсолютный", () -> selectPathType(FilePathType.ABSOLUTE));
|
||||||
|
|
||||||
|
menu.addItem("Относительный", () -> selectPathType(FilePathType.RELATIVE));
|
||||||
|
|
||||||
|
menu.addItem("Выйти", this::close);
|
||||||
|
|
||||||
|
setComponent(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectPathType(FilePathType pathType) {
|
||||||
|
onPathTypeSelected.accept(pathType);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user