Merge branch 'jdk8u45' into fastfinder
Conflicts: client/src/main/java/ru/trader/controllers/MainController.java client/src/main/java/ru/trader/controllers/PathsController.java client/src/main/java/ru/trader/controllers/RouterController.java client/src/main/java/ru/trader/controllers/Screeners.java client/src/main/java/ru/trader/controllers/SettingsController.java
This commit is contained in:
@@ -91,8 +91,6 @@ public class Main extends Application {
|
||||
private static void loadResources() throws IOException {
|
||||
Screeners.loadItemDescStage(getUrl(("itemDesc.fxml")));
|
||||
Screeners.loadVEditorStage(getUrl(("vEditor.fxml")));
|
||||
Screeners.loadAddOfferStage(getUrl(("oEditor.fxml")));
|
||||
Screeners.loadOrdersStage(getUrl(("orders.fxml")));
|
||||
Screeners.loadTopOrdersStage(getUrl(("topOrders.fxml")));
|
||||
Screeners.loadPathsStage(getUrl(("paths.fxml")));
|
||||
Screeners.loadSettingsStage(getUrl(("settings.fxml")));
|
||||
|
||||
@@ -3,13 +3,7 @@ package ru.trader.controllers;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.ListView;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import javafx.scene.control.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.core.MarketFilter;
|
||||
@@ -22,7 +16,7 @@ import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.Localization;
|
||||
import ru.trader.view.support.NumberField;
|
||||
import ru.trader.view.support.cells.CustomListCell;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class FilterController {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(FilterController.class);
|
||||
@@ -56,10 +50,9 @@ public class FilterController {
|
||||
@FXML
|
||||
private ListView<StationModel> excludes;
|
||||
|
||||
public final Action actSave = new DialogAction(Localization.getString("dialog.button.save"), ButtonBar.ButtonType.OK_DONE, false, true, false, (e) -> save());
|
||||
|
||||
private MarketModel market;
|
||||
private MarketFilter filter;
|
||||
private Dialog<MarketFilter> dlg;
|
||||
|
||||
@FXML
|
||||
private void initialize(){
|
||||
@@ -74,6 +67,23 @@ public class FilterController {
|
||||
system.setItems(market.systemsProperty());
|
||||
}
|
||||
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(Localization.getString("filter.title"));
|
||||
ButtonType saveButton = new ButtonType(Localization.getString("dialog.button.save"), ButtonBar.ButtonData.OK_DONE);
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(saveButton, ButtonType.CANCEL);
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == saveButton) {
|
||||
save();
|
||||
return this.filter;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
}
|
||||
|
||||
private void fill(MarketFilter filter){
|
||||
this.filter = filter;
|
||||
center.setValue(market.getModeler().get(filter.getCenter()));
|
||||
@@ -90,6 +100,14 @@ public class FilterController {
|
||||
excludes.setItems(BindingsHelper.observableList(filter.getExcludes(), market.getModeler()::get));
|
||||
}
|
||||
|
||||
private void clear(){
|
||||
this.filter = null;
|
||||
center.getSelectionModel().clearSelection();
|
||||
radius.clear();
|
||||
distance.clear();
|
||||
excludes.getItems().clear();
|
||||
}
|
||||
|
||||
private void save() {
|
||||
SystemModel s = center.getValue();
|
||||
LOG.trace("Old filter", filter);
|
||||
@@ -109,17 +127,18 @@ public class FilterController {
|
||||
LOG.trace("New filter", filter);
|
||||
}
|
||||
|
||||
public Action showDialog(Parent parent, Parent content){
|
||||
public Optional<MarketFilter> showDialog(Parent parent, Parent content){
|
||||
return showDialog(parent, content, new MarketFilter());
|
||||
}
|
||||
|
||||
public Action showDialog(Parent parent, Parent content, MarketFilter filter){
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("filter.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(actSave, Dialog.ACTION_CANCEL);
|
||||
dlg.setResizable(false);
|
||||
public Optional<MarketFilter> showDialog(Parent parent, Parent content, MarketFilter filter){
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
fill(filter);
|
||||
return dlg.show();
|
||||
Optional<MarketFilter> result = dlg.showAndWait();
|
||||
clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void add(ActionEvent actionEvent) {
|
||||
|
||||
@@ -1,43 +1,66 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Dialog;
|
||||
import javafx.scene.control.TextField;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import ru.trader.core.GROUP_TYPE;
|
||||
import ru.trader.model.GroupModel;
|
||||
import ru.trader.model.MarketModel;
|
||||
import ru.trader.view.support.Localization;
|
||||
|
||||
public class GroupAddController {
|
||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
||||
import java.util.Optional;
|
||||
|
||||
public class GroupAddController {
|
||||
@FXML
|
||||
private ComboBox<GROUP_TYPE> type;
|
||||
@FXML
|
||||
private TextField name;
|
||||
|
||||
private Dialog<GroupModel> dlg;
|
||||
private MarketModel market;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
type.setItems(FXCollections.observableArrayList(GROUP_TYPE.values()));
|
||||
type.getSelectionModel().selectFirst();
|
||||
name.clear();
|
||||
}
|
||||
|
||||
public GroupModel showDialog(Parent parent, Parent content, MarketModel market) {
|
||||
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("dialog.group.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(Localization.getString("dialog.group.title"));
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == ButtonType.OK) {
|
||||
return add(market);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
GroupModel res = dlg.show() == OK ? add(market) : null;
|
||||
}
|
||||
|
||||
private void clear(){
|
||||
this.market = null;
|
||||
name.clear();
|
||||
type.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
private void fill(MarketModel market){
|
||||
this.market = market;
|
||||
}
|
||||
|
||||
public Optional<GroupModel> showDialog(Parent parent, Parent content, MarketModel market) {
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
fill(market);
|
||||
Optional<GroupModel> res = dlg.showAndWait();
|
||||
clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Dialog;
|
||||
import javafx.scene.control.TextField;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import ru.trader.model.GroupModel;
|
||||
import ru.trader.model.ItemModel;
|
||||
import ru.trader.model.MarketModel;
|
||||
@@ -19,31 +16,54 @@ import java.util.Optional;
|
||||
|
||||
|
||||
public class ItemAddController {
|
||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
||||
|
||||
@FXML
|
||||
private ComboBox<GroupModel> group;
|
||||
@FXML
|
||||
private TextField name;
|
||||
|
||||
private Dialog<ItemModel> dlg;
|
||||
private MarketModel market;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
|
||||
}
|
||||
|
||||
private void init(MarketModel market) {
|
||||
group.setItems(market.getGroups());
|
||||
group.getSelectionModel().selectFirst();
|
||||
name.clear();
|
||||
}
|
||||
|
||||
public ItemModel showDialog(Parent parent, Parent content, MarketModel market) {
|
||||
init(market);
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("dialog.item.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(Localization.getString("dialog.item.title"));
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == ButtonType.OK) {
|
||||
return add(market);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
ItemModel res = dlg.show() == OK ? add(market) : null;
|
||||
}
|
||||
|
||||
private void fill(MarketModel market) {
|
||||
this.market = market;
|
||||
group.setItems(market.getGroups());
|
||||
}
|
||||
|
||||
private void clear(){
|
||||
this.market = null;
|
||||
name.clear();
|
||||
group.getSelectionModel().clearSelection();
|
||||
group.getItems().clear();
|
||||
}
|
||||
|
||||
public Optional<ItemModel> showDialog(Parent parent, Parent content, MarketModel market) {
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
fill(market);
|
||||
Optional<ItemModel> res = dlg.showAndWait();
|
||||
clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -57,7 +77,6 @@ public class ItemAddController {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public void add(ActionEvent actionEvent) {
|
||||
Optional<GroupModel> _group = Screeners.showAddGroup();
|
||||
if (_group.isPresent()){
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
public class ItemEditorController {
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
import ru.trader.Main;
|
||||
import ru.trader.World;
|
||||
import ru.trader.core.MarketFilter;
|
||||
import ru.trader.maddavo.Parser;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.view.support.Localization;
|
||||
@@ -194,13 +195,11 @@ public class MainController {
|
||||
}
|
||||
|
||||
public Optional<GroupModel> addGroup(){
|
||||
GroupModel group = Screeners.showAddGroup(market);
|
||||
return Optional.ofNullable(group);
|
||||
return Screeners.showAddGroup(market);
|
||||
}
|
||||
|
||||
public Optional<ItemModel> addItem(){
|
||||
ItemModel item = Screeners.showAddItem(market);
|
||||
return Optional.ofNullable(item);
|
||||
return Screeners.showAddItem(market);
|
||||
}
|
||||
|
||||
|
||||
@@ -254,8 +253,12 @@ public class MainController {
|
||||
}
|
||||
|
||||
public void editFilter(){
|
||||
//TODO: implement
|
||||
//Screeners.showFilter(market.getFilter());
|
||||
/*TODO: implement
|
||||
Optional<MarketFilter> res = Screeners.showFilter(market.getAnalyzer().getFilter());
|
||||
if (res.isPresent()){
|
||||
Main.SETTINGS.setFilter(res.get());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void impMadSystems(ActionEvent actionEvent) {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.Label;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import ru.trader.model.ItemModel;
|
||||
import ru.trader.view.support.NumberField;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class OffersEditorController {
|
||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
||||
|
||||
|
||||
@FXML
|
||||
private Label name;
|
||||
|
||||
@FXML
|
||||
private NumberField sell;
|
||||
|
||||
@FXML
|
||||
private NumberField buy;
|
||||
|
||||
|
||||
public Optional<DialogResult> showDialog(Parent parent, Parent content, ItemModel item, Number sell, Number buy) {
|
||||
name.setText(item.getName());
|
||||
|
||||
this.sell.setValue(sell);
|
||||
this.buy.setValue(buy);
|
||||
|
||||
OK.disabledProperty().bind(this.sell.wrongProperty().or(this.buy.wrongProperty()));
|
||||
|
||||
Dialog dlg = new Dialog(parent, "Создание заказов");
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
||||
dlg.setResizable(false);
|
||||
return Optional.ofNullable(dlg.show() == OK ? new DialogResult() : null);
|
||||
}
|
||||
|
||||
|
||||
public class DialogResult {
|
||||
|
||||
private double _sell;
|
||||
private double _buy;
|
||||
|
||||
public DialogResult() {
|
||||
_sell = sell.getValue().doubleValue();
|
||||
_buy = buy.getValue().doubleValue();
|
||||
}
|
||||
|
||||
public double getSell() {
|
||||
return _sell;
|
||||
}
|
||||
|
||||
public double getBuy() {
|
||||
return _buy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.util.converter.LongStringConverter;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import ru.trader.model.OfferModel;
|
||||
import ru.trader.model.OrderModel;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.Localization;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
public class OrdersController {
|
||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
||||
|
||||
@FXML
|
||||
private TableView<OrderModel> tblOrders;
|
||||
|
||||
@FXML
|
||||
private TableView<OfferModel> tblBuyers;
|
||||
|
||||
@FXML
|
||||
private TableColumn<OrderModel, Long> count;
|
||||
|
||||
@FXML
|
||||
private TableColumn<OrderModel, Long> maxCount;
|
||||
|
||||
@FXML
|
||||
private TableColumn<OfferModel, Number> curProfit;
|
||||
|
||||
@FXML
|
||||
private TableColumn<OfferModel, Double> curDistance;
|
||||
|
||||
private final List<OrderModel> orders = FXCollections.observableArrayList();
|
||||
private final List<OfferModel> buyers = FXCollections.observableArrayList();
|
||||
private OrderModel order;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
count.setCellFactory(TextFieldTableCell.forTableColumn(new LongStringConverter()));
|
||||
maxCount.setCellFactory(TextFieldTableCell.forTableColumn(new LongStringConverter()));
|
||||
tblOrders.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> changeOrder(n));
|
||||
tblBuyers.getSelectionModel().selectedItemProperty().addListener((v, o, n) -> setBuyer(n));
|
||||
curProfit.setCellValueFactory(param -> {
|
||||
OfferModel offer = param.getValue();
|
||||
return order !=null ? order.getProfit(offer) : new SimpleDoubleProperty(Double.NaN);
|
||||
});
|
||||
curDistance.setCellValueFactory(param -> {
|
||||
OfferModel offer = param.getValue();
|
||||
return new SimpleDoubleProperty(order !=null ? order.getStation().getDistance(offer.getStation()) :Double.NaN).asObject();
|
||||
});
|
||||
BindingsHelper.setTableViewItems(tblOrders, orders);
|
||||
BindingsHelper.setTableViewItems(tblBuyers, buyers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Collection<OrderModel> showDialog(Parent parent, Parent content, Collection<OfferModel> offers, double balance, long max) {
|
||||
|
||||
init(offers, balance, max);
|
||||
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("orders.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
||||
dlg.setResizable(false);
|
||||
Collection<OrderModel> res = dlg.show() == OK ? getOrders() : null;
|
||||
orders.clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
private List<OrderModel> getOrders() {
|
||||
return orders.stream().filter(o -> o.getCount() > 0 && o.getBuyOffer() != null).collect(toList());
|
||||
}
|
||||
|
||||
private void init(Collection<OfferModel> offers, double balance, long max) {
|
||||
orders.clear();
|
||||
offers.forEach(o -> orders.add(new OrderModel(o, balance, max)));
|
||||
}
|
||||
|
||||
private void changeOrder(OrderModel order) {
|
||||
this.order = order;
|
||||
buyers.clear();
|
||||
if (order != null) buyers.addAll(order.getBuyers());
|
||||
tblBuyers.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
private void setBuyer(OfferModel offer) {
|
||||
if (order != null && offer!=null) {
|
||||
order.setBuyOffer(offer);
|
||||
order.setCount(order.getMax());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,23 +5,30 @@ import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Dialog;
|
||||
import javafx.scene.control.TableView;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import ru.trader.model.RouteModel;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.Localization;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PathsController {
|
||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
||||
|
||||
@FXML
|
||||
private TableView<RouteModel> tblPaths;
|
||||
private final List<RouteModel> paths = FXCollections.observableArrayList();
|
||||
private final ListChangeListener<RouteModel> PATHS_CHANGE_LISTENER = l -> {
|
||||
while (l.next()) {
|
||||
if (l.wasAdded()) {
|
||||
this.paths.addAll(l.getAddedSubList());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Dialog<RouteModel> dlg;
|
||||
private ObservableList<RouteModel> p;
|
||||
|
||||
|
||||
@FXML
|
||||
@@ -30,16 +37,42 @@ public class PathsController {
|
||||
}
|
||||
|
||||
|
||||
public RouteModel showDialog(Parent parent, Parent content, ObservableList<RouteModel> paths) {
|
||||
|
||||
init(paths);
|
||||
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("paths.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(Localization.getString("paths.title"));
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == ButtonType.OK) {
|
||||
return getPath();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
RouteModel res = dlg.show() == OK ? getPath() : null;
|
||||
paths.clear();
|
||||
}
|
||||
|
||||
private void fill(ObservableList<RouteModel> paths){
|
||||
this.paths.clear();
|
||||
this.paths.addAll(paths);
|
||||
p = paths;
|
||||
p.addListener(PATHS_CHANGE_LISTENER);
|
||||
}
|
||||
|
||||
private void clear(){
|
||||
tblPaths.getSelectionModel().clearSelection();
|
||||
this.paths.clear();
|
||||
p.removeListener(PATHS_CHANGE_LISTENER);
|
||||
p = null;
|
||||
}
|
||||
|
||||
public Optional<RouteModel> showDialog(Parent parent, Parent content, ObservableList<RouteModel> paths) {
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
fill(paths);
|
||||
Optional<RouteModel> res = dlg.showAndWait();
|
||||
clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -47,17 +80,4 @@ public class PathsController {
|
||||
return tblPaths.getSelectionModel().getSelectedItem();
|
||||
}
|
||||
|
||||
private void init(ObservableList<RouteModel> paths) {
|
||||
tblPaths.getSelectionModel().clearSelection();
|
||||
this.paths.clear();
|
||||
this.paths.addAll(paths);
|
||||
paths.addListener((ListChangeListener<RouteModel>) l -> {
|
||||
while (l.next()) {
|
||||
if (l.wasAdded()) {
|
||||
this.paths.addAll(l.getAddedSubList());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@ package ru.trader.controllers;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Dialog;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.layout.VBox;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import ru.trader.services.*;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@@ -16,13 +14,16 @@ import java.util.function.Consumer;
|
||||
public class ProgressController {
|
||||
private Label text;
|
||||
private ProgressBar bar;
|
||||
private Action cancel;
|
||||
private Dialog dlg;
|
||||
private final static String TASK_KEY = "task";
|
||||
private Dialog<ButtonType> dlg;
|
||||
private AnalyzerTask task;
|
||||
|
||||
|
||||
public ProgressController(Parent owner, String title) {
|
||||
dlg = new Dialog(owner, title);
|
||||
dlg = new Dialog<>();
|
||||
dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(title);
|
||||
dlg.setResizable(false);
|
||||
|
||||
createStage();
|
||||
}
|
||||
|
||||
@@ -34,21 +35,23 @@ public class ProgressController {
|
||||
vbox.setMaxWidth(Double.MAX_VALUE);
|
||||
vbox.setPrefSize(300, 100);
|
||||
|
||||
dlg.setClosable(false);
|
||||
dlg.setContent(vbox);
|
||||
cancel = new DialogAction(impl.org.controlsfx.i18n.Localization.asKey("dlg.cancel.button"), ButtonBar.ButtonType.CANCEL_CLOSE, e -> {
|
||||
AnalyzerTask<?> task = (AnalyzerTask<?>) cancel.getProperties().get(TASK_KEY);
|
||||
dlg.getDialogPane().setContent(vbox);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL);
|
||||
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == ButtonType.OK) {
|
||||
if (task != null){
|
||||
task.stop();
|
||||
}
|
||||
}
|
||||
return dialogButton;
|
||||
});
|
||||
dlg.getActions().addAll(cancel);
|
||||
}
|
||||
|
||||
private <T> void bind(AnalyzerTask<T> task, Consumer<T> onSuccess){
|
||||
bar.progressProperty().bind(task.progressProperty());
|
||||
text.textProperty().bind(task.messageProperty());
|
||||
cancel.getProperties().put(TASK_KEY, task);
|
||||
this.task = task;
|
||||
task.setOnSucceeded(e -> {
|
||||
Platform.runLater(dlg::hide);
|
||||
onSuccess.accept(task.getValue());
|
||||
@@ -69,7 +72,7 @@ public class ProgressController {
|
||||
private void unbind(){
|
||||
bar.progressProperty().unbind();
|
||||
text.textProperty().unbind();
|
||||
cancel.getProperties().remove(TASK_KEY);
|
||||
task = null;
|
||||
}
|
||||
|
||||
public <T> void run(AnalyzerTask<T> task, Consumer<T> onSuccess){
|
||||
|
||||
@@ -16,6 +16,7 @@ import ru.trader.model.support.ChangeMarketListener;
|
||||
import ru.trader.view.support.NumberField;
|
||||
import ru.trader.view.support.RouteNode;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class RouterController {
|
||||
@@ -184,9 +185,9 @@ public class RouterController {
|
||||
int index = tblOrders.getSelectionModel().getSelectedIndex();
|
||||
//TODO: implement
|
||||
/* market.getOrders(sel.getStation(), sel.getBuyer(), sel.getBalance(), result -> {
|
||||
OrderModel order = Screeners.showOrders(result);
|
||||
if (order!=null){
|
||||
orders.set(index, order);
|
||||
Optional<OrderModel> order = Screeners.showOrders(result);
|
||||
if (order.isPresent()){
|
||||
orders.set(index, order.get());
|
||||
}
|
||||
|
||||
});*/
|
||||
@@ -241,10 +242,10 @@ public class RouterController {
|
||||
|
||||
public void showTopOrders(){
|
||||
market.getTop(totalBalance.getValue().doubleValue(), result -> {
|
||||
OrderModel order = Screeners.showOrders(result);
|
||||
if (order!=null){
|
||||
orders.add(order);
|
||||
addOrderToPath(order);
|
||||
Optional<OrderModel> order = Screeners.showOrders(result);
|
||||
if (order.isPresent()){
|
||||
orders.add(order.get());
|
||||
addOrderToPath(order.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -255,10 +256,10 @@ public class RouterController {
|
||||
StationModel sS = sStation.getValue();
|
||||
StationModel tS = tStation.getValue();
|
||||
market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue(), result -> {
|
||||
OrderModel order = Screeners.showOrders(result);
|
||||
if (order!=null){
|
||||
orders.add(order);
|
||||
addOrderToPath(order);
|
||||
Optional<OrderModel> order = Screeners.showOrders(result);
|
||||
if (order.isPresent()){
|
||||
orders.add(order.get());
|
||||
addOrderToPath(order.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -269,20 +270,20 @@ public class RouterController {
|
||||
StationModel sS = sStation.getValue();
|
||||
StationModel tS = tStation.getValue();
|
||||
market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue(), routes -> {
|
||||
RouteModel path = Screeners.showRouters(routes);
|
||||
if (path!=null){
|
||||
orders.addAll(path.getOrders());
|
||||
addRouteToPath(path);
|
||||
Optional<RouteModel> path = Screeners.showRouters(routes);
|
||||
if (path.isPresent()){
|
||||
orders.addAll(path.get().getOrders());
|
||||
addRouteToPath(path.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void showTopRoutes(){
|
||||
market.getTopRoutes(totalBalance.getValue().doubleValue(), routes -> {
|
||||
RouteModel path = Screeners.showRouters(routes);
|
||||
if (path!=null){
|
||||
orders.addAll(path.getOrders());
|
||||
addRouteToPath(path);
|
||||
Optional<RouteModel> path = Screeners.showRouters(routes);
|
||||
if (path.isPresent()){
|
||||
orders.addAll(path.get().getOrders());
|
||||
addRouteToPath(path.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import javafx.stage.Stage;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialogs;
|
||||
import ru.trader.EMDNUpdater;
|
||||
import ru.trader.Main;
|
||||
import ru.trader.core.MarketFilter;
|
||||
import ru.trader.model.*;
|
||||
import ru.trader.view.support.CustomBuilderFactory;
|
||||
@@ -17,7 +16,6 @@ import ru.trader.view.support.Localization;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Screeners {
|
||||
@@ -25,8 +23,6 @@ public class Screeners {
|
||||
private static Parent mainScreen;
|
||||
private static Parent itemDescScreen;
|
||||
private static Parent vEditorScreen;
|
||||
private static Parent editOffersScreen;
|
||||
private static Parent ordersScreen;
|
||||
private static Parent topOrdersScreen;
|
||||
private static Parent pathsScreen;
|
||||
private static Parent settingsScreen;
|
||||
@@ -38,8 +34,6 @@ public class Screeners {
|
||||
private static MainController mainController;
|
||||
private static ItemDescController itemDescController;
|
||||
private static StationEditorController vEditorController;
|
||||
private static OffersEditorController oEditorController;
|
||||
private static OrdersController ordersController;
|
||||
private static TopOrdersController topOrdersController;
|
||||
private static PathsController pathsController;
|
||||
private static SettingsController settingsController;
|
||||
@@ -83,24 +77,6 @@ public class Screeners {
|
||||
stage.setScene(new Scene(vEditorScreen));
|
||||
}
|
||||
|
||||
public static void loadAddOfferStage(URL fxml) throws IOException {
|
||||
FXMLLoader loader = initLoader(fxml);
|
||||
editOffersScreen = loader.load();
|
||||
addStylesheet(editOffersScreen);
|
||||
oEditorController = loader.getController();
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(editOffersScreen));
|
||||
}
|
||||
|
||||
public static void loadOrdersStage(URL fxml) throws IOException {
|
||||
FXMLLoader loader = initLoader(fxml);
|
||||
ordersScreen = loader.load();
|
||||
addStylesheet(ordersScreen);
|
||||
ordersController = loader.getController();
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(ordersScreen));
|
||||
}
|
||||
|
||||
public static void loadTopOrdersStage(URL fxml) throws IOException {
|
||||
FXMLLoader loader = initLoader(fxml);
|
||||
topOrdersScreen = loader.load();
|
||||
@@ -169,11 +145,11 @@ public class Screeners {
|
||||
return Dialogs.create().owner(mainScreen).message(text).showConfirm();
|
||||
}
|
||||
|
||||
public static GroupModel showAddGroup(MarketModel market){
|
||||
public static Optional<GroupModel> showAddGroup(MarketModel market){
|
||||
return groupAddController.showDialog(mainScreen, groupAddScreen, market);
|
||||
}
|
||||
|
||||
public static ItemModel showAddItem(MarketModel market){
|
||||
public static Optional<ItemModel> showAddItem(MarketModel market){
|
||||
return itemAddController.showDialog(mainScreen, itemAddScreen, market);
|
||||
}
|
||||
|
||||
@@ -193,15 +169,6 @@ public class Screeners {
|
||||
return mainScreen;
|
||||
}
|
||||
|
||||
public static Optional<OffersEditorController.DialogResult> showEditOffers(ItemModel item, Number sell, Number buy) {
|
||||
return oEditorController.showDialog(vEditorScreen, editOffersScreen, item, sell, buy);
|
||||
}
|
||||
|
||||
|
||||
public static Collection<OrderModel> showOrders(Collection<OfferModel> offers, double balance, long cargo) {
|
||||
return ordersController.showDialog(mainScreen, ordersScreen, offers, balance, cargo);
|
||||
}
|
||||
|
||||
public static void changeItemDesc(ItemModel item){
|
||||
itemDescController.setItemDesc(item);
|
||||
}
|
||||
@@ -222,11 +189,11 @@ public class Screeners {
|
||||
itemDescController.close();
|
||||
}
|
||||
|
||||
public static OrderModel showOrders(ObservableList<OrderModel> orders) {
|
||||
public static Optional<OrderModel> showOrders(ObservableList<OrderModel> orders) {
|
||||
return topOrdersController.showDialog(mainScreen, topOrdersScreen, orders);
|
||||
}
|
||||
|
||||
public static RouteModel showRouters(ObservableList<RouteModel> routers) {
|
||||
public static Optional<RouteModel> showRouters(ObservableList<RouteModel> routers) {
|
||||
return pathsController.showDialog(mainScreen, pathsScreen, routers);
|
||||
}
|
||||
|
||||
@@ -234,16 +201,12 @@ public class Screeners {
|
||||
settingsController.showDialog(mainScreen, settingsScreen);
|
||||
}
|
||||
|
||||
public static MarketFilter showFilter() {
|
||||
Action res = filterController.showDialog(mainScreen, filterScreen);
|
||||
return res == filterController.actSave ? filterController.getFilter() : null;
|
||||
public static Optional<MarketFilter> showFilter() {
|
||||
return filterController.showDialog(mainScreen, filterScreen);
|
||||
}
|
||||
|
||||
public static void showFilter(MarketFilter filter) {
|
||||
Action res = filterController.showDialog(mainScreen, filterScreen, filter);
|
||||
if (res == filterController.actSave){
|
||||
Main.SETTINGS.setFilter(filter);
|
||||
}
|
||||
public static Optional<MarketFilter> showFilter(MarketFilter filter) {
|
||||
return filterController.showDialog(mainScreen, filterScreen, filter);
|
||||
}
|
||||
|
||||
public static void reinitAll() {
|
||||
|
||||
@@ -2,12 +2,7 @@ package ru.trader.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.TextField;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import javafx.scene.control.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.EMDNUpdater;
|
||||
@@ -32,8 +27,7 @@ public class SettingsController {
|
||||
@FXML
|
||||
private NumberField pathsCount;
|
||||
|
||||
private final Action actSave = new DialogAction(Localization.getString("dialog.button.save"), ButtonBar.ButtonType.OK_DONE, false, true, false, (e) -> save());
|
||||
|
||||
private Dialog<ButtonType> dlg;
|
||||
|
||||
@FXML
|
||||
private void initialize(){
|
||||
@@ -48,6 +42,22 @@ public class SettingsController {
|
||||
pathsCount.setValue(Main.SETTINGS.getRoutesCount());
|
||||
}
|
||||
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(Localization.getString("settings.title"));
|
||||
ButtonType saveButton = new ButtonType(Localization.getString("dialog.button.save"), ButtonBar.ButtonData.OK_DONE);
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(saveButton, ButtonType.CANCEL);
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == saveButton) {
|
||||
save();
|
||||
}
|
||||
return dialogButton;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
}
|
||||
|
||||
private void save() {
|
||||
Main.SETTINGS.setEMDNSub(emdnSubServ.getText());
|
||||
EMDNUpdater.setSub(emdnSubServ.getText());
|
||||
@@ -59,13 +69,12 @@ public class SettingsController {
|
||||
EMDNUpdater.setInterval(emdnUpdateTime.getValue().longValue());
|
||||
}
|
||||
|
||||
public Action showDialog(Parent parent, Parent content){
|
||||
public void showDialog(Parent parent, Parent content){
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
init();
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("settings.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(actSave, Dialog.ACTION_CANCEL);
|
||||
dlg.setResizable(false);
|
||||
return dlg.show();
|
||||
dlg.showAndWait();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,8 @@ package ru.trader.controllers;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.util.converter.LongStringConverter;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.EMDNUpdater;
|
||||
@@ -65,16 +58,7 @@ public class StationEditorController {
|
||||
|
||||
private StationUpdater updater;
|
||||
|
||||
private final Action actSave = new DialogAction(Localization.getString("dialog.button.save"), ButtonBar.ButtonType.OK_DONE, false, true, false, (e) -> {
|
||||
items.getSelectionModel().selectFirst();
|
||||
updater.commit();
|
||||
items.getSelectionModel().clearSelection();
|
||||
});
|
||||
|
||||
private final Action actCancel = new DialogAction(impl.org.controlsfx.i18n.Localization.asKey("dlg.cancel.button"), ButtonBar.ButtonType.CANCEL_CLOSE, true, true, true, (e) -> {
|
||||
items.getSelectionModel().selectFirst();
|
||||
items.getSelectionModel().clearSelection();
|
||||
});
|
||||
private Dialog<ButtonType> dlg;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
@@ -83,7 +67,6 @@ public class StationEditorController {
|
||||
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
|
||||
demand.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
||||
supply.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
||||
actSave.disabledProperty().bind(distance.wrongProperty());
|
||||
name.setOnAction((v)->distance.requestFocus());
|
||||
distance.setOnAction((v) -> {
|
||||
items.requestFocus();
|
||||
@@ -111,17 +94,54 @@ public class StationEditorController {
|
||||
items.setItems(updater.getOffers());
|
||||
}
|
||||
|
||||
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
|
||||
ButtonType saveButton = new ButtonType(Localization.getString("dialog.button.save"), ButtonBar.ButtonData.OK_DONE);
|
||||
ButtonType cancelButton = new ButtonType(Localization.getString("dialog.button.cancel"), ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(saveButton, cancelButton);
|
||||
|
||||
Button bSave = (Button) dlg.getDialogPane().lookupButton(saveButton);
|
||||
bSave.disableProperty().bind(distance.wrongProperty());
|
||||
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == saveButton) {
|
||||
save();
|
||||
}
|
||||
if (dialogButton == cancelButton) {
|
||||
cancel();
|
||||
}
|
||||
return dialogButton;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
}
|
||||
|
||||
private void save(){
|
||||
items.getSelectionModel().selectFirst();
|
||||
updater.commit();
|
||||
items.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
private void cancel(){
|
||||
items.getSelectionModel().selectFirst();
|
||||
items.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
public void showDialog(Parent parent, Parent content, StationModel station){
|
||||
showDialog(parent, content, station.getSystem(), station);
|
||||
}
|
||||
|
||||
public void showDialog(Parent parent, Parent content, SystemModel system, StationModel station){
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
dlg.setTitle(Localization.getString(station == null ? "vEditor.title.add" : "vEditor.title.edit"));
|
||||
updater.init(system, station);
|
||||
Dialog dlg = new Dialog(parent, Localization.getString(station == null ? "vEditor.title.add" : "vEditor.title.edit"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(actSave, actCancel);
|
||||
dlg.setResizable(false);
|
||||
dlg.show();
|
||||
dlg.showAndWait();
|
||||
updater.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,15 +7,9 @@ import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.util.converter.DefaultStringConverter;
|
||||
import javafx.util.converter.DoubleStringConverter;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.trader.model.MarketModel;
|
||||
@@ -63,13 +57,9 @@ public class SystemsEditorController {
|
||||
@FXML
|
||||
private ComboBox<SystemModel> system6;
|
||||
|
||||
private Dialog<ButtonType> dlg;
|
||||
private MarketModel market;
|
||||
|
||||
private final Action actSave = new DialogAction(Localization.getString("dialog.button.save"), ButtonBar.ButtonType.OK_DONE, false, true, false, (e) -> {
|
||||
tblSystems.getSelectionModel().selectFirst();
|
||||
commit();
|
||||
});
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
clnName.setCellFactory(TextFieldCell.forTableColumn(new DefaultStringConverter()));
|
||||
@@ -104,19 +94,43 @@ public class SystemsEditorController {
|
||||
system6.setItems(market.systemsProperty());
|
||||
}
|
||||
|
||||
public void showDialog(Parent parent, Parent content, SystemModel system){
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("sEditor.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(actSave, Dialog.ACTION_CANCEL);
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(Localization.getString("sEditor.title"));
|
||||
ButtonType saveButton = new ButtonType(Localization.getString("dialog.button.save"), ButtonBar.ButtonData.OK_DONE);
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(saveButton, ButtonType.CANCEL);
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == saveButton) {
|
||||
save();
|
||||
}
|
||||
return dialogButton;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
}
|
||||
|
||||
private void save(){
|
||||
tblSystems.getSelectionModel().selectFirst();
|
||||
commit();
|
||||
}
|
||||
|
||||
public void showDialog(Parent parent, Parent content, SystemModel system){
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
fill(system);
|
||||
dlg.showAndWait();
|
||||
clear();
|
||||
}
|
||||
|
||||
private void fill(SystemModel system){
|
||||
if (system != null){
|
||||
tblSystems.getItems().add(new SystemData(system));
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
add();
|
||||
}
|
||||
dlg.show();
|
||||
reset();
|
||||
}
|
||||
|
||||
public void add(){
|
||||
@@ -153,7 +167,7 @@ public class SystemsEditorController {
|
||||
}
|
||||
}
|
||||
|
||||
private void reset(){
|
||||
private void clear(){
|
||||
tblSystems.getItems().clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,21 @@ package ru.trader.controllers;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Dialog;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.cell.TextFieldTableCell;
|
||||
import javafx.util.converter.LongStringConverter;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.controlsfx.dialog.DialogAction;
|
||||
import ru.trader.model.OrderModel;
|
||||
import ru.trader.model.support.BindingsHelper;
|
||||
import ru.trader.view.support.Localization;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TopOrdersController {
|
||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
||||
|
||||
@FXML
|
||||
private TableView<OrderModel> tblOrders;
|
||||
|
||||
@@ -28,6 +25,7 @@ public class TopOrdersController {
|
||||
private TableColumn<OrderModel, Long> count;
|
||||
|
||||
private OrderModel order;
|
||||
private Dialog<OrderModel> dlg;
|
||||
|
||||
private final List<OrderModel> orders = FXCollections.observableArrayList();
|
||||
|
||||
@@ -38,26 +36,41 @@ public class TopOrdersController {
|
||||
BindingsHelper.setTableViewItems(tblOrders, orders);
|
||||
}
|
||||
|
||||
|
||||
public OrderModel showDialog(Parent parent, Parent content, Collection<OrderModel> orders) {
|
||||
|
||||
init(orders);
|
||||
|
||||
Dialog dlg = new Dialog(parent, Localization.getString("topOrders.title"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
||||
private void createDialog(Parent owner, Parent content){
|
||||
dlg = new Dialog<>();
|
||||
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||
dlg.setTitle(Localization.getString("topOrders.title"));
|
||||
dlg.getDialogPane().setContent(content);
|
||||
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||
dlg.setResultConverter(dialogButton -> {
|
||||
if (dialogButton == ButtonType.OK) {
|
||||
return order;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
dlg.setResizable(false);
|
||||
OrderModel res = dlg.show() == OK ? order : null;
|
||||
this.orders.clear();
|
||||
}
|
||||
|
||||
public Optional<OrderModel> showDialog(Parent parent, Parent content, Collection<OrderModel> orders) {
|
||||
if (dlg == null){
|
||||
createDialog(parent, content);
|
||||
}
|
||||
fill(orders);
|
||||
Optional<OrderModel> res = dlg.showAndWait();
|
||||
clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
private void init(Collection<OrderModel> orders) {
|
||||
private void fill(Collection<OrderModel> orders) {
|
||||
tblOrders.getSelectionModel().clearSelection();
|
||||
this.orders.addAll(orders);
|
||||
}
|
||||
|
||||
private void clear(){
|
||||
orders.clear();
|
||||
}
|
||||
|
||||
private void changeOrder(OrderModel order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ dialog.confirm.save=Changes were not saved, save changes?
|
||||
dialog.confirm.remove=Are you sure you want to delete %s?
|
||||
dialog.button.add=Add
|
||||
dialog.button.save=Save
|
||||
dialog.button.cancel=Cancel
|
||||
dialog.button.edit=Edit
|
||||
dialog.button.remove=Remove
|
||||
dialog.button.clear=Clear
|
||||
@@ -81,19 +82,12 @@ dialog.group.type=Type:
|
||||
itemDesc.sellers=Sellers:
|
||||
itemDesc.buyers=Buyers:
|
||||
|
||||
# oEditor.fxml
|
||||
oEditor.sell=Sell:
|
||||
oEditor.buy=Buy:
|
||||
|
||||
# offers.fxml
|
||||
offers.text.distance=Distance:
|
||||
offers.text.services=Services:
|
||||
offers.pane.sell=Selling commodities
|
||||
offers.pane.buy=Buying commodities
|
||||
|
||||
# orders.fxml
|
||||
orders.title=Create orders
|
||||
|
||||
# topOrders.fxml
|
||||
topOrders.title=TOP orders
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ dialog.confirm.save=\u0418\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u044F \u043
|
||||
dialog.confirm.remove=\u0412\u044B \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0445\u043E\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043B\u0438\u0442\u044C %s?
|
||||
dialog.button.add=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C
|
||||
dialog.button.save=\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C
|
||||
dialog.button.cancel=\u041E\u0442\u043C\u0435\u043D\u0430
|
||||
dialog.button.edit=\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C
|
||||
dialog.button.remove=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
|
||||
dialog.button.clear=\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C
|
||||
@@ -82,19 +83,12 @@ dialog.group.type=\u0422\u0438\u043F:
|
||||
itemDesc.sellers=\u041F\u0440\u043E\u0434\u0430\u0432\u0446\u044B:
|
||||
itemDesc.buyers=\u041F\u043E\u043A\u0443\u043F\u0430\u0442\u0435\u043B\u0438:
|
||||
|
||||
# oEditor.fxml
|
||||
oEditor.sell=\u041F\u0440\u043E\u0434\u0430\u0436\u0430:
|
||||
oEditor.buy=\u041F\u043E\u043A\u0443\u043F\u043A\u0430:
|
||||
|
||||
# offers.fxml
|
||||
offers.text.distance=\u0414\u0438\u0441\u0442\u0430\u043D\u0446\u0438\u044F:
|
||||
offers.text.services=\u0421\u0435\u0440\u0432\u0438\u0441\u044B:
|
||||
offers.pane.sell=\u041F\u0440\u043E\u0434\u0430\u0432\u0430\u0435\u043C\u044B\u0435 \u0442\u043E\u0432\u0430\u0440\u044B
|
||||
offers.pane.buy=\u041F\u043E\u043A\u0443\u043F\u0430\u0435\u043C\u044B\u0435 \u0442\u043E\u0432\u0430\u0440\u044B
|
||||
|
||||
# orders.fxml
|
||||
orders.title=\u0421\u043E\u0437\u0434\u0430\u043D\u0438\u0435 \u0437\u0430\u043A\u0430\u0437\u043E\u0432
|
||||
|
||||
# topOrders.fxml
|
||||
topOrders.title=TOP \u0437\u0430\u043A\u0430\u0437\u043E\u0432
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import ru.trader.view.support.NumberField?>
|
||||
<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="ru.trader.controllers.OffersEditorController">
|
||||
<Label fx:id="name"/>
|
||||
<HBox>
|
||||
<Label text="%oEditor.sell"/>
|
||||
<NumberField fx:id="sell"/>
|
||||
<Label text="%oEditor.buy"/>
|
||||
<NumberField fx:id="buy"/>
|
||||
</HBox>
|
||||
</VBox>
|
||||
@@ -1,75 +0,0 @@
|
||||
<?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.DoubleCell?>
|
||||
|
||||
<?import ru.trader.view.support.cells.OfferCellValueImpl?>
|
||||
<?import ru.trader.view.support.cells.OfferTableCell?>
|
||||
<?import ru.trader.view.support.cells.DistanceCell?>
|
||||
<HBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="ru.trader.controllers.OrdersController" styleClass="dialog"
|
||||
prefWidth="1010">
|
||||
<TableView fx:id="tblOrders" editable="true">
|
||||
<columns>
|
||||
<TableColumn minWidth="160.0" text="%market.item.name">
|
||||
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn minWidth="60.0" text="%market.offer.price">
|
||||
<cellFactory><DoubleCell/></cellFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn fx:id="count" minWidth="60.0" prefWidth="60.0" text="%market.order.count">
|
||||
<cellValueFactory><PropertyValueFactory property="count"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn minWidth="160.0" text="%market.order.buyer">
|
||||
<cellValueFactory><OfferCellValueImpl property="buyOffer"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn minWidth="80.0" text="%market.order.profit">
|
||||
<cellFactory><DoubleCell/></cellFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="profit"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
|
||||
<TableColumn resizable="false" text="%market.offer.max.full">
|
||||
<columns>
|
||||
<TableColumn fx:id="maxCount" minWidth="60.0" prefWidth="60.0" text="%market.order.count">
|
||||
<cellValueFactory><PropertyValueFactory property="max"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn fx:id="bestProfit" minWidth="80.0" text="%market.order.profit" sortType="DESCENDING">
|
||||
<cellFactory><DoubleCell/></cellFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="bestProfit"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
</columns>
|
||||
</TableColumn>
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
||||
</columnResizePolicy>
|
||||
<sortOrder>
|
||||
<fx:reference source="bestProfit"/>
|
||||
</sortOrder>
|
||||
</TableView>
|
||||
<TableView fx:id="tblBuyers" minWidth="335">
|
||||
<columns>
|
||||
<TableColumn minWidth="160.0" text="%market.order.buyer">
|
||||
<cellFactory><OfferTableCell/></cellFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn fx:id="curDistance" minWidth="80.0" text="%market.order.distance">
|
||||
<cellFactory><DistanceCell/></cellFactory>
|
||||
</TableColumn>
|
||||
<TableColumn fx:id="curProfit" minWidth="80.0" text="%market.order.profit" sortType="DESCENDING">
|
||||
<cellFactory><DoubleCell/></cellFactory>
|
||||
</TableColumn>
|
||||
</columns>
|
||||
<columnResizePolicy>
|
||||
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
|
||||
</columnResizePolicy>
|
||||
<sortOrder>
|
||||
<fx:reference source="curProfit"/>
|
||||
</sortOrder>
|
||||
</TableView>
|
||||
</HBox>
|
||||
Reference in New Issue
Block a user