diff --git a/client/src/main/java/ru/trader/db/controllers/StationsController.java b/client/src/main/java/ru/trader/db/controllers/StationsController.java new file mode 100644 index 0000000..db4603c --- /dev/null +++ b/client/src/main/java/ru/trader/db/controllers/StationsController.java @@ -0,0 +1,122 @@ +package ru.trader.db.controllers; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ButtonType; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.ComboBoxTableCell; +import ru.trader.controllers.MainController; +import ru.trader.controllers.Screeners; +import ru.trader.core.*; +import ru.trader.model.StationModel; +import ru.trader.model.MarketModel; +import ru.trader.model.support.ChangeMarketListener; +import ru.trader.view.support.*; +import ru.trader.view.support.cells.CheckComboBoxTableCell; + +import java.util.Collection; +import java.util.Optional; + +public class StationsController { + + @FXML + private TableView tblStations; + @FXML + private TableColumn type; + @FXML + private TableColumn faction; + @FXML + private TableColumn government; + @FXML + private TableColumn economic; + @FXML + private TableColumn subEconomic; + @FXML + private TableColumn> services; + + + private ObservableList stations = FXCollections.observableArrayList(); + private MarketModel world = null; + + @FXML + private void initialize() { + tblStations.setItems(stations); + type.setCellFactory(ComboBoxTableCell.forTableColumn(new StationTypeStringConverter(), FXCollections.observableArrayList(STATION_TYPE.values()))); + faction.setCellFactory(ComboBoxTableCell.forTableColumn(new FactionStringConverter(), FXCollections.observableArrayList(FACTION.values()))); + government.setCellFactory(ComboBoxTableCell.forTableColumn(new GovernmentStringConverter(), FXCollections.observableArrayList(GOVERNMENT.values()))); + economic.setCellFactory(ComboBoxTableCell.forTableColumn(new EconomicTypeStringConverter(), FXCollections.observableArrayList(ECONOMIC_TYPE.values()))); + subEconomic.setCellFactory(ComboBoxTableCell.forTableColumn(new EconomicTypeStringConverter(), FXCollections.observableArrayList(ECONOMIC_TYPE.values()))); + services.setCellFactory(CheckComboBoxTableCell.forTableColumn(services, + FXCollections.observableArrayList(SERVICE_TYPE.values()), new ServiceTypeStringConverter(), this::setService) + ); + + init(); + } + + void init(){ + if (world != null) world.getNotificator().remove(marketChangeListener); + world = MainController.getWorld(); + world.getNotificator().add(marketChangeListener); + stations.clear(); + stations.addAll(world.getStations()); + } + + private void setService(StationModel station, SERVICE_TYPE service, boolean add){ + if (add){ + station.addService(service); + } else { + station.removeService(service); + } + } + + @FXML + private void add(){ + StationModel station = tblStations.getSelectionModel().getSelectedItem(); + if (station != null){ + Screeners.showAddStation(station.getSystem()); + } + } + + @FXML + private void edit(){ + StationModel station = tblStations.getSelectionModel().getSelectedItem(); + if (station != null){ + Screeners.showEditStation(station); + } + } + + @FXML + private void remove(){ + StationModel station = tblStations.getSelectionModel().getSelectedItem(); + if (station != null){ + remove(station); + } + } + + private void remove(StationModel station){ + Optional res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), station.getFullName())); + if (res.isPresent() && res.get() == ButtonType.YES) { + station.getSystem().remove(station); + } + } + + + private final ChangeMarketListener marketChangeListener = new ChangeMarketListener() { + @Override + public void add(StationModel station) { + ViewUtils.doFX(() -> { + StationsController.this.stations.add(station); + }); + } + + @Override + public void remove(StationModel station) { + ViewUtils.doFX(() -> { + StationsController.this.stations.remove(station); + }); + } + }; +} + diff --git a/client/src/main/java/ru/trader/db/controllers/SystemsController.java b/client/src/main/java/ru/trader/db/controllers/SystemsController.java new file mode 100644 index 0000000..67245f9 --- /dev/null +++ b/client/src/main/java/ru/trader/db/controllers/SystemsController.java @@ -0,0 +1,95 @@ +package ru.trader.db.controllers; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ButtonType; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.ComboBoxTableCell; +import ru.trader.controllers.MainController; +import ru.trader.controllers.Screeners; +import ru.trader.core.*; +import ru.trader.model.MarketModel; +import ru.trader.model.SystemModel; +import ru.trader.model.support.ChangeMarketListener; +import ru.trader.view.support.*; + +import java.util.Optional; + +public class SystemsController { + + @FXML + private TableView tblSystems; + @FXML + private TableColumn faction; + @FXML + private TableColumn government; + + + private ObservableList stations = FXCollections.observableArrayList(); + private MarketModel world = null; + + @FXML + private void initialize() { + tblSystems.setItems(stations); + faction.setCellFactory(ComboBoxTableCell.forTableColumn(new FactionStringConverter(), FXCollections.observableArrayList(FACTION.values()))); + government.setCellFactory(ComboBoxTableCell.forTableColumn(new GovernmentStringConverter(), FXCollections.observableArrayList(GOVERNMENT.values()))); + + init(); + } + + void init(){ + if (world != null) world.getNotificator().remove(marketChangeListener); + world = MainController.getWorld(); + world.getNotificator().add(marketChangeListener); + stations.clear(); + stations.addAll(world.getSystems()); + } + + @FXML + private void add(){ + Screeners.showSystemsEditor(null); + } + + @FXML + private void edit(){ + SystemModel system = tblSystems.getSelectionModel().getSelectedItem(); + if (system != null){ + Screeners.showSystemsEditor(system); + } + } + + @FXML + private void remove(){ + SystemModel system = tblSystems.getSelectionModel().getSelectedItem(); + if (system != null){ + remove(system); + } + } + + private void remove(SystemModel system){ + Optional res = Screeners.showConfirm(String.format(Localization.getString("dialog.confirm.remove"), system.getName())); + if (res.isPresent() && res.get() == ButtonType.YES) { + world.remove(system); + } + } + + + private final ChangeMarketListener marketChangeListener = new ChangeMarketListener() { + @Override + public void add(SystemModel system) { + ViewUtils.doFX(() -> { + SystemsController.this.stations.add(system); + }); + } + + @Override + public void remove(SystemModel system) { + ViewUtils.doFX(() -> { + SystemsController.this.stations.remove(system); + }); + } + }; +} + diff --git a/client/src/main/java/ru/trader/model/MarketModel.java b/client/src/main/java/ru/trader/model/MarketModel.java index d72cbd6..622c1f3 100644 --- a/client/src/main/java/ru/trader/model/MarketModel.java +++ b/client/src/main/java/ru/trader/model/MarketModel.java @@ -177,10 +177,18 @@ public class MarketModel { return BindingsHelper.observableList(analyzer.getOffers(offerType, ModelFabric.get(item), filter), modeler::get); } + public ObservableList getStations(){ + return BindingsHelper.observableList(market.getVendors(), modeler::get); + } + public ObservableList getStations(MarketFilter filter){ return BindingsHelper.observableList(analyzer.getVendors(filter), modeler::get); } + public ObservableList getSystems(){ + return BindingsHelper.observableList(market.get(), modeler::get); + } + public ObservableList getSystems(MarketFilter filter){ return BindingsHelper.observableList(analyzer.getSystems(filter), modeler::get); } diff --git a/client/src/main/java/ru/trader/view/support/ServiceTypeStringConverter.java b/client/src/main/java/ru/trader/view/support/ServiceTypeStringConverter.java new file mode 100644 index 0000000..9eede3a --- /dev/null +++ b/client/src/main/java/ru/trader/view/support/ServiceTypeStringConverter.java @@ -0,0 +1,24 @@ +package ru.trader.view.support; + + +import javafx.util.StringConverter; +import ru.trader.core.SERVICE_TYPE; + + +public class ServiceTypeStringConverter extends StringConverter { + + @Override + public String toString(SERVICE_TYPE type) { + return toLocalizationString(type); + } + + @Override + public SERVICE_TYPE fromString(String type) { + return SERVICE_TYPE.valueOf(type); + } + + public static String toLocalizationString(SERVICE_TYPE type){ + if (type == null) return null; + return Localization.getString("services." + type.toString(), type.toString()); + } +} diff --git a/client/src/main/resources/view/db/dbeditor.fxml b/client/src/main/resources/view/db/dbeditor.fxml index d49c7d3..6fbf8f5 100644 --- a/client/src/main/resources/view/db/dbeditor.fxml +++ b/client/src/main/resources/view/db/dbeditor.fxml @@ -7,7 +7,13 @@ fx:controller="ru.trader.db.controllers.DBEditorController" tabClosingPolicy="UNAVAILABLE" > - - - + + + + + + + + + diff --git a/client/src/main/resources/view/db/stations.fxml b/client/src/main/resources/view/db/stations.fxml new file mode 100644 index 0000000..3c1df67 --- /dev/null +++ b/client/src/main/resources/view/db/stations.fxml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/src/main/resources/view/db/systems.fxml b/client/src/main/resources/view/db/systems.fxml new file mode 100644 index 0000000..7f9189c --- /dev/null +++ b/client/src/main/resources/view/db/systems.fxml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +