implement systems and stations edit table
This commit is contained in:
@@ -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<StationModel> tblStations;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<StationModel, STATION_TYPE> type;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<StationModel, FACTION> faction;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<StationModel, GOVERNMENT> government;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<StationModel, ECONOMIC_TYPE> economic;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<StationModel, ECONOMIC_TYPE> subEconomic;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<StationModel, Collection<SERVICE_TYPE>> services;
|
||||||
|
|
||||||
|
|
||||||
|
private ObservableList<StationModel> 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<ButtonType> 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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<SystemModel> tblSystems;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<SystemModel, FACTION> faction;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<SystemModel, GOVERNMENT> government;
|
||||||
|
|
||||||
|
|
||||||
|
private ObservableList<SystemModel> 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<ButtonType> 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@@ -177,10 +177,18 @@ public class MarketModel {
|
|||||||
return BindingsHelper.observableList(analyzer.getOffers(offerType, ModelFabric.get(item), filter), modeler::get);
|
return BindingsHelper.observableList(analyzer.getOffers(offerType, ModelFabric.get(item), filter), modeler::get);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableList<StationModel> getStations(){
|
||||||
|
return BindingsHelper.observableList(market.getVendors(), modeler::get);
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableList<StationModel> getStations(MarketFilter filter){
|
public ObservableList<StationModel> getStations(MarketFilter filter){
|
||||||
return BindingsHelper.observableList(analyzer.getVendors(filter), modeler::get);
|
return BindingsHelper.observableList(analyzer.getVendors(filter), modeler::get);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableList<SystemModel> getSystems(){
|
||||||
|
return BindingsHelper.observableList(market.get(), modeler::get);
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableList<SystemModel> getSystems(MarketFilter filter){
|
public ObservableList<SystemModel> getSystems(MarketFilter filter){
|
||||||
return BindingsHelper.observableList(analyzer.getSystems(filter), modeler::get);
|
return BindingsHelper.observableList(analyzer.getSystems(filter), modeler::get);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ru.trader.view.support;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
import ru.trader.core.SERVICE_TYPE;
|
||||||
|
|
||||||
|
|
||||||
|
public class ServiceTypeStringConverter extends StringConverter<SERVICE_TYPE> {
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,13 @@
|
|||||||
fx:controller="ru.trader.db.controllers.DBEditorController"
|
fx:controller="ru.trader.db.controllers.DBEditorController"
|
||||||
tabClosingPolicy="UNAVAILABLE"
|
tabClosingPolicy="UNAVAILABLE"
|
||||||
>
|
>
|
||||||
<Tab text="%market.items">
|
<Tab text="%market.items">
|
||||||
<fx:include fx:id="items" source="items.fxml"/>
|
<fx:include fx:id="items" source="items.fxml"/>
|
||||||
</Tab>
|
</Tab>
|
||||||
|
<Tab text="Системы">
|
||||||
|
<fx:include fx:id="systems" source="systems.fxml"/>
|
||||||
|
</Tab>
|
||||||
|
<Tab text="Станции">
|
||||||
|
<fx:include fx:id="stations" source="stations.fxml"/>
|
||||||
|
</Tab>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
|
|||||||
56
client/src/main/resources/view/db/stations.fxml
Normal file
56
client/src/main/resources/view/db/stations.fxml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.cell.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
|
||||||
|
|
||||||
|
<?import ru.trader.view.support.cells.OfferCellValueImpl?>
|
||||||
|
<?import ru.trader.view.support.cells.DoubleCell?>
|
||||||
|
|
||||||
|
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="ru.trader.db.controllers.StationsController">
|
||||||
|
<TableView fx:id="tblStations" editable="true" VBox.vgrow="ALWAYS" prefWidth="800">
|
||||||
|
<columns>
|
||||||
|
<TableColumn minWidth="100" text="Система">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="system"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn minWidth="200" text="Название">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="type" minWidth="100" text="%market.station.type">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="type"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="faction" minWidth="100" text="%market.allegiance">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="faction"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="government" minWidth="100" text="%market.government">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="government"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="economic" minWidth="100" text="%market.economic">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="economic"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="subEconomic" minWidth="100" text="%market.economic">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="subEconomic"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn minWidth="100" text="Дистанция">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="distance"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="services" minWidth="100" text="Сервисы">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="services"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
</columns>
|
||||||
|
<columnResizePolicy>
|
||||||
|
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
||||||
|
</columnResizePolicy>
|
||||||
|
<contextMenu>
|
||||||
|
<ContextMenu>
|
||||||
|
<items>
|
||||||
|
<MenuItem text="Добавить" onAction="#add" />
|
||||||
|
<MenuItem text="Редактировать" onAction="#edit" />
|
||||||
|
<MenuItem text="Удалить" onAction="#remove" />
|
||||||
|
</items>
|
||||||
|
</ContextMenu>
|
||||||
|
</contextMenu>
|
||||||
|
</TableView>
|
||||||
|
</VBox>
|
||||||
47
client/src/main/resources/view/db/systems.fxml
Normal file
47
client/src/main/resources/view/db/systems.fxml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.cell.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
|
||||||
|
|
||||||
|
<?import ru.trader.view.support.cells.OfferCellValueImpl?>
|
||||||
|
<?import ru.trader.view.support.cells.DoubleCell?>
|
||||||
|
|
||||||
|
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="ru.trader.db.controllers.SystemsController">
|
||||||
|
<TableView fx:id="tblSystems" editable="true" VBox.vgrow="ALWAYS" prefWidth="800">
|
||||||
|
<columns>
|
||||||
|
<TableColumn minWidth="200" text="Название">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn minWidth="60" text="X">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="x"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn minWidth="60" text="Y">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="y"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn minWidth="60" text="Z">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="z"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="faction" minWidth="100" text="%market.allegiance">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="faction"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn fx:id="government" minWidth="100" text="%market.government">
|
||||||
|
<cellValueFactory><PropertyValueFactory property="government"/></cellValueFactory>
|
||||||
|
</TableColumn>
|
||||||
|
</columns>
|
||||||
|
<columnResizePolicy>
|
||||||
|
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
||||||
|
</columnResizePolicy>
|
||||||
|
<contextMenu>
|
||||||
|
<ContextMenu>
|
||||||
|
<items>
|
||||||
|
<MenuItem text="Добавить" onAction="#add" />
|
||||||
|
<MenuItem text="Редактировать" onAction="#edit" />
|
||||||
|
<MenuItem text="Удалить" onAction="#remove" />
|
||||||
|
</items>
|
||||||
|
</ContextMenu>
|
||||||
|
</contextMenu>
|
||||||
|
</TableView>
|
||||||
|
</VBox>
|
||||||
Reference in New Issue
Block a user