feat(ui): add sort field configuration and parity sort settings
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package ru.project.model;
|
||||||
|
|
||||||
|
public enum SortField {
|
||||||
|
GROUP_NUMBER,
|
||||||
|
AVERAGE_GRADE,
|
||||||
|
RECORD_BOOK_NUMBER
|
||||||
|
}
|
||||||
@@ -6,9 +6,12 @@ import com.googlecode.lanterna.gui2.LinearLayout;
|
|||||||
import com.googlecode.lanterna.gui2.Panel;
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
import ru.project.model.AppState;
|
import ru.project.model.AppState;
|
||||||
|
import ru.project.model.SortField;
|
||||||
import ru.project.model.SortMethod;
|
import ru.project.model.SortMethod;
|
||||||
import ru.project.ui.base.BaseModalWindow;
|
import ru.project.ui.base.BaseModalWindow;
|
||||||
import ru.project.ui.window.MessageWindow;
|
import ru.project.ui.window.MessageWindow;
|
||||||
|
import ru.project.ui.window.NormalSortSettingsWindow;
|
||||||
|
import ru.project.ui.window.ParitySortSettingsWindow;
|
||||||
import ru.project.ui.window.SortMethodSelectionWindow;
|
import ru.project.ui.window.SortMethodSelectionWindow;
|
||||||
|
|
||||||
public class SortCollectionMenu extends BaseModalWindow {
|
public class SortCollectionMenu extends BaseModalWindow {
|
||||||
@@ -16,9 +19,14 @@ public class SortCollectionMenu extends BaseModalWindow {
|
|||||||
private final AppState state;
|
private final AppState state;
|
||||||
|
|
||||||
private final Label sortMethodLabel;
|
private final Label sortMethodLabel;
|
||||||
|
private final Label sortFieldLabel;
|
||||||
|
|
||||||
private final SortMethodSelectionWindow sortMethodSelectionWindow;
|
private final SortMethodSelectionWindow sortMethodSelectionWindow;
|
||||||
|
private final NormalSortSettingsWindow normalSortSettingsWindow;
|
||||||
|
private final ParitySortSettingsWindow paritySortSettingsWindow;
|
||||||
|
|
||||||
private SortMethod selectedSortMethod;
|
private SortMethod selectedSortMethod;
|
||||||
|
private SortField selectedSortField;
|
||||||
|
|
||||||
public SortCollectionMenu(WindowBasedTextGUI gui, AppState state) {
|
public SortCollectionMenu(WindowBasedTextGUI gui, AppState state) {
|
||||||
|
|
||||||
@@ -26,12 +34,15 @@ public class SortCollectionMenu extends BaseModalWindow {
|
|||||||
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.selectedSortMethod = SortMethod.NORMAL;
|
this.selectedSortMethod = SortMethod.NORMAL;
|
||||||
|
this.selectedSortField = SortField.GROUP_NUMBER;
|
||||||
|
|
||||||
Panel panel = new Panel();
|
Panel panel = new Panel();
|
||||||
panel.setLayoutManager(new LinearLayout());
|
panel.setLayoutManager(new LinearLayout());
|
||||||
|
|
||||||
this.sortMethodLabel = new Label("Способ сортировки: " + getSortMethodName(selectedSortMethod));
|
this.sortMethodLabel = new Label("Способ сортировки: " + getSortMethodName(selectedSortMethod));
|
||||||
|
|
||||||
|
this.sortFieldLabel = new Label("Сортировать по: " + getSortFieldName(selectedSortField));
|
||||||
|
|
||||||
this.sortMethodSelectionWindow =
|
this.sortMethodSelectionWindow =
|
||||||
new SortMethodSelectionWindow(
|
new SortMethodSelectionWindow(
|
||||||
gui,
|
gui,
|
||||||
@@ -42,7 +53,17 @@ public class SortCollectionMenu extends BaseModalWindow {
|
|||||||
"Способ сортировки: " + getSortMethodName(selectedSortMethod));
|
"Способ сортировки: " + getSortMethodName(selectedSortMethod));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.normalSortSettingsWindow =
|
||||||
|
new NormalSortSettingsWindow(
|
||||||
|
gui,
|
||||||
|
sortField -> {
|
||||||
|
selectedSortField = sortField;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.paritySortSettingsWindow = new ParitySortSettingsWindow(gui);
|
||||||
|
|
||||||
panel.addComponent(sortMethodLabel);
|
panel.addComponent(sortMethodLabel);
|
||||||
|
panel.addComponent(sortFieldLabel);
|
||||||
|
|
||||||
panel.addComponent(new Button("Выбрать способ сортировки", this::selectSortMethod));
|
panel.addComponent(new Button("Выбрать способ сортировки", this::selectSortMethod));
|
||||||
|
|
||||||
@@ -57,7 +78,11 @@ public class SortCollectionMenu extends BaseModalWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupCurrentSortMethod() {
|
private void setupCurrentSortMethod() {
|
||||||
MessageWindow.showModal(gui, "Настройка способа сортировки пока не реализована.");
|
switch (selectedSortMethod) {
|
||||||
|
case NORMAL -> normalSortSettingsWindow.showModal();
|
||||||
|
|
||||||
|
case PARITY -> paritySortSettingsWindow.showModal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectSortMethod() {
|
private void selectSortMethod() {
|
||||||
@@ -68,17 +93,14 @@ public class SortCollectionMenu extends BaseModalWindow {
|
|||||||
if (state.getMainCollection() == null || state.getMainCollection().isEmpty()) {
|
if (state.getMainCollection() == null || state.getMainCollection().isEmpty()) {
|
||||||
|
|
||||||
MessageWindow.showModal(gui, "Текущая коллекция пуста.");
|
MessageWindow.showModal(gui, "Текущая коллекция пуста.");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (selectedSortMethod) {
|
switch (selectedSortMethod) {
|
||||||
case NORMAL:
|
case NORMAL -> sortNormally();
|
||||||
sortNormally();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PARITY:
|
case PARITY -> sortByParity();
|
||||||
sortByParity();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,4 +120,12 @@ public class SortCollectionMenu extends BaseModalWindow {
|
|||||||
case PARITY -> "Сортировка по чётности";
|
case PARITY -> "Сортировка по чётности";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSortFieldName(SortField sortField) {
|
||||||
|
return switch (sortField) {
|
||||||
|
case GROUP_NUMBER -> "номеру группы";
|
||||||
|
case AVERAGE_GRADE -> "среднему баллу";
|
||||||
|
case RECORD_BOOK_NUMBER -> "номеру зачётной книжки";
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package ru.project.ui.window;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.ActionListBox;
|
||||||
|
import com.googlecode.lanterna.gui2.Button;
|
||||||
|
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import ru.project.model.SortField;
|
||||||
|
import ru.project.ui.base.BaseModalWindow;
|
||||||
|
|
||||||
|
public class NormalSortSettingsWindow extends BaseModalWindow {
|
||||||
|
|
||||||
|
private final Consumer<SortField> onSortFieldSelected;
|
||||||
|
|
||||||
|
public NormalSortSettingsWindow(WindowBasedTextGUI gui, Consumer<SortField> onSortFieldSelected) {
|
||||||
|
|
||||||
|
super("Обычная сортировка", gui);
|
||||||
|
|
||||||
|
this.onSortFieldSelected = onSortFieldSelected;
|
||||||
|
|
||||||
|
Panel panel = new Panel();
|
||||||
|
panel.setLayoutManager(new LinearLayout());
|
||||||
|
|
||||||
|
ActionListBox menu = new ActionListBox();
|
||||||
|
|
||||||
|
menu.addItem("Сортировать по номеру группы", () -> selectSortField(SortField.GROUP_NUMBER));
|
||||||
|
|
||||||
|
menu.addItem("Сортировать по среднему баллу", () -> selectSortField(SortField.AVERAGE_GRADE));
|
||||||
|
|
||||||
|
menu.addItem(
|
||||||
|
"Сортировать по номеру зачётной книжки",
|
||||||
|
() -> selectSortField(SortField.RECORD_BOOK_NUMBER));
|
||||||
|
|
||||||
|
panel.addComponent(menu);
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Выйти", this::close));
|
||||||
|
|
||||||
|
setComponent(panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectSortField(SortField sortField) {
|
||||||
|
onSortFieldSelected.accept(sortField);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ru.project.ui.window;
|
||||||
|
|
||||||
|
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.ui.base.BaseModalWindow;
|
||||||
|
|
||||||
|
public class ParitySortSettingsWindow extends BaseModalWindow {
|
||||||
|
|
||||||
|
public ParitySortSettingsWindow(WindowBasedTextGUI gui) {
|
||||||
|
super("Настройка сортировки по чётности", gui);
|
||||||
|
|
||||||
|
Panel panel = new Panel();
|
||||||
|
panel.setLayoutManager(new LinearLayout());
|
||||||
|
|
||||||
|
panel.addComponent(new Label("Сортировка выполняется по номеру зачётной книжки."));
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Назад", this::close));
|
||||||
|
|
||||||
|
setComponent(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user