feat(fill-method): add fill method selection presenter
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.project.model;
|
||||||
|
|
||||||
|
public enum FillMethod {
|
||||||
|
CUSTOM,
|
||||||
|
RANDOM,
|
||||||
|
FILE
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package ru.project.presenter;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import ru.project.model.AppState;
|
||||||
|
import ru.project.model.FillMethod;
|
||||||
|
import ru.project.view.FillMethodView;
|
||||||
|
|
||||||
|
public class FillMethodPresenter extends BasePresenter {
|
||||||
|
|
||||||
|
private final FillMethodView view;
|
||||||
|
private final Consumer<FillMethod> onMethodSelected;
|
||||||
|
|
||||||
|
public FillMethodPresenter(
|
||||||
|
AppState state,
|
||||||
|
FillMethodView view,
|
||||||
|
WindowBasedTextGUI gui,
|
||||||
|
Consumer<FillMethod> onMethodSelected) {
|
||||||
|
|
||||||
|
super(state, gui);
|
||||||
|
|
||||||
|
this.view = view;
|
||||||
|
this.onMethodSelected = onMethodSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
bindActions();
|
||||||
|
view.show(gui);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindActions() {
|
||||||
|
view.setCustomAction(() -> selectMethod(FillMethod.CUSTOM));
|
||||||
|
|
||||||
|
view.setRandomAction(() -> selectMethod(FillMethod.RANDOM));
|
||||||
|
|
||||||
|
view.setFileAction(() -> selectMethod(FillMethod.FILE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectMethod(FillMethod method) {
|
||||||
|
onMethodSelected.accept(method);
|
||||||
|
view.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package ru.project.view;
|
||||||
|
|
||||||
|
public class FillMethodView extends ActionListView {
|
||||||
|
|
||||||
|
private Runnable customAction = this::defaultAction;
|
||||||
|
private Runnable randomAction = this::defaultAction;
|
||||||
|
private Runnable fileAction = this::defaultAction;
|
||||||
|
|
||||||
|
public FillMethodView() {
|
||||||
|
super("Настроить способ заполнения");
|
||||||
|
|
||||||
|
addItem("Пользовательские данные", () -> customAction.run());
|
||||||
|
|
||||||
|
addItem("Случайные данные", () -> randomAction.run());
|
||||||
|
|
||||||
|
addItem("Данные из файла", () -> fileAction.run());
|
||||||
|
|
||||||
|
addItem("Выйти", this::close);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomAction(Runnable action) {
|
||||||
|
customAction = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRandomAction(Runnable action) {
|
||||||
|
randomAction = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileAction(Runnable action) {
|
||||||
|
fileAction = action;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user