use new dialog API
This commit is contained in:
@@ -3,13 +3,7 @@ package ru.trader.controllers;
|
|||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.CheckBox;
|
import javafx.scene.control.*;
|
||||||
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 org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.core.MarketFilter;
|
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.Localization;
|
||||||
import ru.trader.view.support.NumberField;
|
import ru.trader.view.support.NumberField;
|
||||||
import ru.trader.view.support.cells.CustomListCell;
|
import ru.trader.view.support.cells.CustomListCell;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class FilterController {
|
public class FilterController {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(FilterController.class);
|
private final static Logger LOG = LoggerFactory.getLogger(FilterController.class);
|
||||||
@@ -56,10 +50,9 @@ public class FilterController {
|
|||||||
@FXML
|
@FXML
|
||||||
private ListView<StationModel> excludes;
|
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 MarketModel market;
|
||||||
private MarketFilter filter;
|
private MarketFilter filter;
|
||||||
|
private Dialog<MarketFilter> dlg;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize(){
|
private void initialize(){
|
||||||
@@ -74,6 +67,23 @@ public class FilterController {
|
|||||||
system.setItems(market.systemsProperty());
|
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){
|
private void fill(MarketFilter filter){
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
center.setValue(market.getModeler().get(filter.getCenter()));
|
center.setValue(market.getModeler().get(filter.getCenter()));
|
||||||
@@ -90,6 +100,14 @@ public class FilterController {
|
|||||||
excludes.setItems(BindingsHelper.observableList(filter.getExcludes(), market.getModeler()::get));
|
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() {
|
private void save() {
|
||||||
SystemModel s = center.getValue();
|
SystemModel s = center.getValue();
|
||||||
LOG.trace("Old filter", filter);
|
LOG.trace("Old filter", filter);
|
||||||
@@ -109,17 +127,18 @@ public class FilterController {
|
|||||||
LOG.trace("New filter", filter);
|
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());
|
return showDialog(parent, content, new MarketFilter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action showDialog(Parent parent, Parent content, MarketFilter filter){
|
public Optional<MarketFilter> showDialog(Parent parent, Parent content, MarketFilter filter){
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString("filter.title"));
|
if (dlg == null){
|
||||||
dlg.setContent(content);
|
createDialog(parent, content);
|
||||||
dlg.getActions().addAll(actSave, Dialog.ACTION_CANCEL);
|
}
|
||||||
dlg.setResizable(false);
|
|
||||||
fill(filter);
|
fill(filter);
|
||||||
return dlg.show();
|
Optional<MarketFilter> result = dlg.showAndWait();
|
||||||
|
clear();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ActionEvent actionEvent) {
|
public void add(ActionEvent actionEvent) {
|
||||||
|
|||||||
@@ -1,43 +1,66 @@
|
|||||||
package ru.trader.controllers;
|
package ru.trader.controllers;
|
||||||
|
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.ButtonType;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.Dialog;
|
||||||
import javafx.scene.control.TextField;
|
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.core.GROUP_TYPE;
|
||||||
import ru.trader.model.GroupModel;
|
import ru.trader.model.GroupModel;
|
||||||
import ru.trader.model.MarketModel;
|
import ru.trader.model.MarketModel;
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
public class GroupAddController {
|
import java.util.Optional;
|
||||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
|
||||||
|
|
||||||
|
public class GroupAddController {
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<GROUP_TYPE> type;
|
private ComboBox<GROUP_TYPE> type;
|
||||||
@FXML
|
@FXML
|
||||||
private TextField name;
|
private TextField name;
|
||||||
|
|
||||||
|
private Dialog<GroupModel> dlg;
|
||||||
|
private MarketModel market;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
type.setItems(FXCollections.observableArrayList(GROUP_TYPE.values()));
|
type.setItems(FXCollections.observableArrayList(GROUP_TYPE.values()));
|
||||||
type.getSelectionModel().selectFirst();
|
|
||||||
name.clear();
|
name.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupModel showDialog(Parent parent, Parent content, MarketModel market) {
|
private void createDialog(Parent owner, Parent content){
|
||||||
|
dlg = new Dialog<>();
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString("dialog.group.title"));
|
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||||
dlg.setContent(content);
|
dlg.setTitle(Localization.getString("dialog.group.title"));
|
||||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
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);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
package ru.trader.controllers;
|
package ru.trader.controllers;
|
||||||
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.ButtonType;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.Dialog;
|
||||||
import javafx.scene.control.TextField;
|
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.GroupModel;
|
||||||
import ru.trader.model.ItemModel;
|
import ru.trader.model.ItemModel;
|
||||||
import ru.trader.model.MarketModel;
|
import ru.trader.model.MarketModel;
|
||||||
@@ -19,31 +16,54 @@ import java.util.Optional;
|
|||||||
|
|
||||||
|
|
||||||
public class ItemAddController {
|
public class ItemAddController {
|
||||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<GroupModel> group;
|
private ComboBox<GroupModel> group;
|
||||||
@FXML
|
@FXML
|
||||||
private TextField name;
|
private TextField name;
|
||||||
|
|
||||||
|
private Dialog<ItemModel> dlg;
|
||||||
|
private MarketModel market;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
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) {
|
private void createDialog(Parent owner, Parent content){
|
||||||
init(market);
|
dlg = new Dialog<>();
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString("dialog.item.title"));
|
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||||
dlg.setContent(content);
|
dlg.setTitle(Localization.getString("dialog.item.title"));
|
||||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
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);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +77,6 @@ public class ItemAddController {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void add(ActionEvent actionEvent) {
|
public void add(ActionEvent actionEvent) {
|
||||||
Optional<GroupModel> _group = Screeners.showAddGroup();
|
Optional<GroupModel> _group = Screeners.showAddGroup();
|
||||||
if (_group.isPresent()){
|
if (_group.isPresent()){
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import ru.trader.Main;
|
import ru.trader.Main;
|
||||||
import ru.trader.World;
|
import ru.trader.World;
|
||||||
|
import ru.trader.core.MarketFilter;
|
||||||
import ru.trader.maddavo.Parser;
|
import ru.trader.maddavo.Parser;
|
||||||
import ru.trader.model.*;
|
import ru.trader.model.*;
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
@@ -194,13 +195,11 @@ public class MainController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<GroupModel> addGroup(){
|
public Optional<GroupModel> addGroup(){
|
||||||
GroupModel group = Screeners.showAddGroup(market);
|
return Screeners.showAddGroup(market);
|
||||||
return Optional.ofNullable(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ItemModel> addItem(){
|
public Optional<ItemModel> addItem(){
|
||||||
ItemModel item = Screeners.showAddItem(market);
|
return Screeners.showAddItem(market);
|
||||||
return Optional.ofNullable(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -254,7 +253,10 @@ public class MainController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void editFilter(){
|
public void editFilter(){
|
||||||
Screeners.showFilter(market.getAnalyzer().getFilter());
|
Optional<MarketFilter> res = Screeners.showFilter(market.getAnalyzer().getFilter());
|
||||||
|
if (res.isPresent()){
|
||||||
|
Main.SETTINGS.setFilter(res.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void impMadSystems(ActionEvent actionEvent) {
|
public void impMadSystems(ActionEvent actionEvent) {
|
||||||
|
|||||||
@@ -5,24 +5,30 @@ import javafx.collections.ListChangeListener;
|
|||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.scene.control.Dialog;
|
||||||
import javafx.scene.control.TableView;
|
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.PathRouteModel;
|
import ru.trader.model.PathRouteModel;
|
||||||
import ru.trader.model.support.BindingsHelper;
|
import ru.trader.model.support.BindingsHelper;
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class PathsController {
|
public class PathsController {
|
||||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TableView<PathRouteModel> tblPaths;
|
private TableView<PathRouteModel> tblPaths;
|
||||||
private final List<PathRouteModel> paths = FXCollections.observableArrayList();
|
private final List<PathRouteModel> paths = FXCollections.observableArrayList();
|
||||||
|
private final ListChangeListener<PathRouteModel> PATHS_CHANGE_LISTENER = l -> {
|
||||||
|
while (l.next()) {
|
||||||
|
if (l.wasAdded()) {
|
||||||
|
this.paths.addAll(l.getAddedSubList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private Dialog<PathRouteModel> dlg;
|
||||||
|
private ObservableList<PathRouteModel> p;
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@@ -31,16 +37,42 @@ public class PathsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public PathRouteModel showDialog(Parent parent, Parent content, ObservableList<PathRouteModel> paths) {
|
private void createDialog(Parent owner, Parent content){
|
||||||
|
dlg = new Dialog<>();
|
||||||
init(paths);
|
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||||
|
dlg.setTitle(Localization.getString("paths.title"));
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString("paths.title"));
|
dlg.getDialogPane().setContent(content);
|
||||||
dlg.setContent(content);
|
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
dlg.setResultConverter(dialogButton -> {
|
||||||
|
if (dialogButton == ButtonType.OK) {
|
||||||
|
return getPath();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
dlg.setResizable(false);
|
dlg.setResizable(false);
|
||||||
PathRouteModel res = dlg.show() == OK ? getPath() : null;
|
}
|
||||||
paths.clear();
|
|
||||||
|
private void fill(ObservableList<PathRouteModel> 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<PathRouteModel> showDialog(Parent parent, Parent content, ObservableList<PathRouteModel> paths) {
|
||||||
|
if (dlg == null){
|
||||||
|
createDialog(parent, content);
|
||||||
|
}
|
||||||
|
fill(paths);
|
||||||
|
Optional<PathRouteModel> res = dlg.showAndWait();
|
||||||
|
clear();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,17 +80,4 @@ public class PathsController {
|
|||||||
return tblPaths.getSelectionModel().getSelectedItem();
|
return tblPaths.getSelectionModel().getSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(ObservableList<PathRouteModel> paths) {
|
|
||||||
tblPaths.getSelectionModel().clearSelection();
|
|
||||||
this.paths.clear();
|
|
||||||
this.paths.addAll(paths);
|
|
||||||
paths.addListener((ListChangeListener<PathRouteModel>) 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.application.Platform;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.scene.control.Dialog;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ProgressBar;
|
import javafx.scene.control.ProgressBar;
|
||||||
import javafx.scene.layout.VBox;
|
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 ru.trader.services.*;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -16,13 +14,16 @@ import java.util.function.Consumer;
|
|||||||
public class ProgressController {
|
public class ProgressController {
|
||||||
private Label text;
|
private Label text;
|
||||||
private ProgressBar bar;
|
private ProgressBar bar;
|
||||||
private Action cancel;
|
private Dialog<ButtonType> dlg;
|
||||||
private Dialog dlg;
|
private AnalyzerTask task;
|
||||||
private final static String TASK_KEY = "task";
|
|
||||||
|
|
||||||
|
|
||||||
public ProgressController(Parent owner, String title) {
|
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();
|
createStage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,21 +35,23 @@ public class ProgressController {
|
|||||||
vbox.setMaxWidth(Double.MAX_VALUE);
|
vbox.setMaxWidth(Double.MAX_VALUE);
|
||||||
vbox.setPrefSize(300, 100);
|
vbox.setPrefSize(300, 100);
|
||||||
|
|
||||||
dlg.setClosable(false);
|
dlg.getDialogPane().setContent(vbox);
|
||||||
dlg.setContent(vbox);
|
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL);
|
||||||
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.setResultConverter(dialogButton -> {
|
||||||
if (task != null){
|
if (dialogButton == ButtonType.OK) {
|
||||||
task.stop();
|
if (task != null){
|
||||||
|
task.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return dialogButton;
|
||||||
});
|
});
|
||||||
dlg.getActions().addAll(cancel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void bind(AnalyzerTask<T> task, Consumer<T> onSuccess){
|
private <T> void bind(AnalyzerTask<T> task, Consumer<T> onSuccess){
|
||||||
bar.progressProperty().bind(task.progressProperty());
|
bar.progressProperty().bind(task.progressProperty());
|
||||||
text.textProperty().bind(task.messageProperty());
|
text.textProperty().bind(task.messageProperty());
|
||||||
cancel.getProperties().put(TASK_KEY, task);
|
this.task = task;
|
||||||
task.setOnSucceeded(e -> {
|
task.setOnSucceeded(e -> {
|
||||||
Platform.runLater(dlg::hide);
|
Platform.runLater(dlg::hide);
|
||||||
onSuccess.accept(task.getValue());
|
onSuccess.accept(task.getValue());
|
||||||
@@ -69,7 +72,7 @@ public class ProgressController {
|
|||||||
private void unbind(){
|
private void unbind(){
|
||||||
bar.progressProperty().unbind();
|
bar.progressProperty().unbind();
|
||||||
text.textProperty().unbind();
|
text.textProperty().unbind();
|
||||||
cancel.getProperties().remove(TASK_KEY);
|
task = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void run(AnalyzerTask<T> task, Consumer<T> onSuccess){
|
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.NumberField;
|
||||||
import ru.trader.view.support.RouteNode;
|
import ru.trader.view.support.RouteNode;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
public class RouterController {
|
public class RouterController {
|
||||||
@@ -197,9 +198,9 @@ public class RouterController {
|
|||||||
OrderModel sel = tblOrders.getSelectionModel().getSelectedItem();
|
OrderModel sel = tblOrders.getSelectionModel().getSelectedItem();
|
||||||
int index = tblOrders.getSelectionModel().getSelectedIndex();
|
int index = tblOrders.getSelectionModel().getSelectedIndex();
|
||||||
market.getOrders(sel.getStation(), sel.getBuyer(), sel.getBalance(), result -> {
|
market.getOrders(sel.getStation(), sel.getBuyer(), sel.getBalance(), result -> {
|
||||||
OrderModel order = Screeners.showOrders(result);
|
Optional<OrderModel> order = Screeners.showOrders(result);
|
||||||
if (order!=null){
|
if (order.isPresent()){
|
||||||
orders.set(index, order);
|
orders.set(index, order.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -253,10 +254,10 @@ public class RouterController {
|
|||||||
|
|
||||||
public void showTopOrders(){
|
public void showTopOrders(){
|
||||||
market.getTop(totalBalance.getValue().doubleValue(), result -> {
|
market.getTop(totalBalance.getValue().doubleValue(), result -> {
|
||||||
OrderModel order = Screeners.showOrders(result);
|
Optional<OrderModel> order = Screeners.showOrders(result);
|
||||||
if (order!=null){
|
if (order.isPresent()){
|
||||||
orders.add(order);
|
orders.add(order.get());
|
||||||
addOrderToPath(order);
|
addOrderToPath(order.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -267,10 +268,10 @@ public class RouterController {
|
|||||||
StationModel sS = sStation.getValue();
|
StationModel sS = sStation.getValue();
|
||||||
StationModel tS = tStation.getValue();
|
StationModel tS = tStation.getValue();
|
||||||
market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue(), result -> {
|
market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue(), result -> {
|
||||||
OrderModel order = Screeners.showOrders(result);
|
Optional<OrderModel> order = Screeners.showOrders(result);
|
||||||
if (order!=null){
|
if (order.isPresent()){
|
||||||
orders.add(order);
|
orders.add(order.get());
|
||||||
addOrderToPath(order);
|
addOrderToPath(order.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -281,20 +282,20 @@ public class RouterController {
|
|||||||
StationModel sS = sStation.getValue();
|
StationModel sS = sStation.getValue();
|
||||||
StationModel tS = tStation.getValue();
|
StationModel tS = tStation.getValue();
|
||||||
market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue(), routes -> {
|
market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue(), routes -> {
|
||||||
PathRouteModel path = Screeners.showRouters(routes);
|
Optional<PathRouteModel> path = Screeners.showRouters(routes);
|
||||||
if (path!=null){
|
if (path.isPresent()){
|
||||||
orders.addAll(path.getOrders());
|
orders.addAll(path.get().getOrders());
|
||||||
addRouteToPath(path);
|
addRouteToPath(path.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showTopRoutes(){
|
public void showTopRoutes(){
|
||||||
market.getTopRoutes(totalBalance.getValue().doubleValue(), routes -> {
|
market.getTopRoutes(totalBalance.getValue().doubleValue(), routes -> {
|
||||||
PathRouteModel path = Screeners.showRouters(routes);
|
Optional<PathRouteModel> path = Screeners.showRouters(routes);
|
||||||
if (path!=null){
|
if (path.isPresent()){
|
||||||
orders.addAll(path.getOrders());
|
orders.addAll(path.get().getOrders());
|
||||||
addRouteToPath(path);
|
addRouteToPath(path.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import javafx.stage.Stage;
|
|||||||
import org.controlsfx.control.action.Action;
|
import org.controlsfx.control.action.Action;
|
||||||
import org.controlsfx.dialog.Dialogs;
|
import org.controlsfx.dialog.Dialogs;
|
||||||
import ru.trader.EMDNUpdater;
|
import ru.trader.EMDNUpdater;
|
||||||
import ru.trader.Main;
|
|
||||||
import ru.trader.core.MarketFilter;
|
import ru.trader.core.MarketFilter;
|
||||||
import ru.trader.model.*;
|
import ru.trader.model.*;
|
||||||
import ru.trader.view.support.CustomBuilderFactory;
|
import ru.trader.view.support.CustomBuilderFactory;
|
||||||
@@ -17,7 +16,6 @@ import ru.trader.view.support.Localization;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class Screeners {
|
public class Screeners {
|
||||||
@@ -25,8 +23,6 @@ public class Screeners {
|
|||||||
private static Parent mainScreen;
|
private static Parent mainScreen;
|
||||||
private static Parent itemDescScreen;
|
private static Parent itemDescScreen;
|
||||||
private static Parent vEditorScreen;
|
private static Parent vEditorScreen;
|
||||||
private static Parent editOffersScreen;
|
|
||||||
private static Parent ordersScreen;
|
|
||||||
private static Parent topOrdersScreen;
|
private static Parent topOrdersScreen;
|
||||||
private static Parent pathsScreen;
|
private static Parent pathsScreen;
|
||||||
private static Parent settingsScreen;
|
private static Parent settingsScreen;
|
||||||
@@ -38,8 +34,6 @@ public class Screeners {
|
|||||||
private static MainController mainController;
|
private static MainController mainController;
|
||||||
private static ItemDescController itemDescController;
|
private static ItemDescController itemDescController;
|
||||||
private static StationEditorController vEditorController;
|
private static StationEditorController vEditorController;
|
||||||
private static OffersEditorController oEditorController;
|
|
||||||
private static OrdersController ordersController;
|
|
||||||
private static TopOrdersController topOrdersController;
|
private static TopOrdersController topOrdersController;
|
||||||
private static PathsController pathsController;
|
private static PathsController pathsController;
|
||||||
private static SettingsController settingsController;
|
private static SettingsController settingsController;
|
||||||
@@ -83,24 +77,6 @@ public class Screeners {
|
|||||||
stage.setScene(new Scene(vEditorScreen));
|
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 {
|
public static void loadTopOrdersStage(URL fxml) throws IOException {
|
||||||
FXMLLoader loader = initLoader(fxml);
|
FXMLLoader loader = initLoader(fxml);
|
||||||
topOrdersScreen = loader.load();
|
topOrdersScreen = loader.load();
|
||||||
@@ -169,11 +145,11 @@ public class Screeners {
|
|||||||
return Dialogs.create().owner(mainScreen).message(text).showConfirm();
|
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);
|
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);
|
return itemAddController.showDialog(mainScreen, itemAddScreen, market);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,15 +169,6 @@ public class Screeners {
|
|||||||
return mainScreen;
|
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){
|
public static void changeItemDesc(ItemModel item){
|
||||||
itemDescController.setItemDesc(item);
|
itemDescController.setItemDesc(item);
|
||||||
}
|
}
|
||||||
@@ -222,11 +189,11 @@ public class Screeners {
|
|||||||
itemDescController.close();
|
itemDescController.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OrderModel showOrders(ObservableList<OrderModel> orders) {
|
public static Optional<OrderModel> showOrders(ObservableList<OrderModel> orders) {
|
||||||
return topOrdersController.showDialog(mainScreen, topOrdersScreen, orders);
|
return topOrdersController.showDialog(mainScreen, topOrdersScreen, orders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PathRouteModel showRouters(ObservableList<PathRouteModel> routers) {
|
public static Optional<PathRouteModel> showRouters(ObservableList<PathRouteModel> routers) {
|
||||||
return pathsController.showDialog(mainScreen, pathsScreen, routers);
|
return pathsController.showDialog(mainScreen, pathsScreen, routers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,16 +201,12 @@ public class Screeners {
|
|||||||
settingsController.showDialog(mainScreen, settingsScreen);
|
settingsController.showDialog(mainScreen, settingsScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MarketFilter showFilter() {
|
public static Optional<MarketFilter> showFilter() {
|
||||||
Action res = filterController.showDialog(mainScreen, filterScreen);
|
return filterController.showDialog(mainScreen, filterScreen);
|
||||||
return res == filterController.actSave ? filterController.getFilter() : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showFilter(MarketFilter filter) {
|
public static Optional<MarketFilter> showFilter(MarketFilter filter) {
|
||||||
Action res = filterController.showDialog(mainScreen, filterScreen, filter);
|
return filterController.showDialog(mainScreen, filterScreen, filter);
|
||||||
if (res == filterController.actSave){
|
|
||||||
Main.SETTINGS.setFilter(filter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reinitAll() {
|
public static void reinitAll() {
|
||||||
|
|||||||
@@ -2,18 +2,12 @@ package ru.trader.controllers;
|
|||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.CheckBox;
|
import javafx.scene.control.*;
|
||||||
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 org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.EMDNUpdater;
|
import ru.trader.EMDNUpdater;
|
||||||
import ru.trader.Main;
|
import ru.trader.Main;
|
||||||
import ru.trader.core.MarketAnalyzer;
|
import ru.trader.core.MarketAnalyzer;
|
||||||
import ru.trader.model.MarketModel;
|
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
import ru.trader.view.support.NumberField;
|
import ru.trader.view.support.NumberField;
|
||||||
|
|
||||||
@@ -34,8 +28,7 @@ public class SettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private NumberField pathsCount;
|
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
|
@FXML
|
||||||
private void initialize(){
|
private void initialize(){
|
||||||
@@ -51,6 +44,22 @@ public class SettingsController {
|
|||||||
pathsCount.setValue(Main.SETTINGS.getPathsCount());
|
pathsCount.setValue(Main.SETTINGS.getPathsCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
private void save() {
|
||||||
Main.SETTINGS.setEMDNSub(emdnSubServ.getText());
|
Main.SETTINGS.setEMDNSub(emdnSubServ.getText());
|
||||||
EMDNUpdater.setSub(emdnSubServ.getText());
|
EMDNUpdater.setSub(emdnSubServ.getText());
|
||||||
@@ -68,13 +77,12 @@ public class SettingsController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action showDialog(Parent parent, Parent content){
|
public void showDialog(Parent parent, Parent content){
|
||||||
|
if (dlg == null){
|
||||||
|
createDialog(parent, content);
|
||||||
|
}
|
||||||
init();
|
init();
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString("settings.title"));
|
dlg.showAndWait();
|
||||||
dlg.setContent(content);
|
|
||||||
dlg.getActions().addAll(actSave, Dialog.ACTION_CANCEL);
|
|
||||||
dlg.setResizable(false);
|
|
||||||
return dlg.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,8 @@ package ru.trader.controllers;
|
|||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.CheckBox;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.TableColumn;
|
|
||||||
import javafx.scene.control.TableView;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.util.converter.LongStringConverter;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.EMDNUpdater;
|
import ru.trader.EMDNUpdater;
|
||||||
@@ -65,16 +58,7 @@ public class StationEditorController {
|
|||||||
|
|
||||||
private StationUpdater updater;
|
private StationUpdater updater;
|
||||||
|
|
||||||
private final Action actSave = new DialogAction(Localization.getString("dialog.button.save"), ButtonBar.ButtonType.OK_DONE, false, true, false, (e) -> {
|
private Dialog<ButtonType> dlg;
|
||||||
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();
|
|
||||||
});
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
@@ -83,7 +67,6 @@ public class StationEditorController {
|
|||||||
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
|
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
|
||||||
demand.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
demand.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
||||||
supply.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
supply.setCellFactory(TextFieldCell.forTableColumn(new LongStringConverter()));
|
||||||
actSave.disabledProperty().bind(distance.wrongProperty());
|
|
||||||
name.setOnAction((v)->distance.requestFocus());
|
name.setOnAction((v)->distance.requestFocus());
|
||||||
distance.setOnAction((v) -> {
|
distance.setOnAction((v) -> {
|
||||||
items.requestFocus();
|
items.requestFocus();
|
||||||
@@ -111,17 +94,54 @@ public class StationEditorController {
|
|||||||
items.setItems(updater.getOffers());
|
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){
|
public void showDialog(Parent parent, Parent content, StationModel station){
|
||||||
showDialog(parent, content, station.getSystem(), station);
|
showDialog(parent, content, station.getSystem(), station);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog(Parent parent, Parent content, SystemModel system, StationModel 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);
|
updater.init(system, station);
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString(station == null ? "vEditor.title.add" : "vEditor.title.edit"));
|
dlg.showAndWait();
|
||||||
dlg.setContent(content);
|
|
||||||
dlg.getActions().addAll(actSave, actCancel);
|
|
||||||
dlg.setResizable(false);
|
|
||||||
dlg.show();
|
|
||||||
updater.reset();
|
updater.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,9 @@ import javafx.beans.property.StringProperty;
|
|||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.TableColumn;
|
|
||||||
import javafx.scene.control.TableView;
|
|
||||||
import javafx.util.converter.DefaultStringConverter;
|
import javafx.util.converter.DefaultStringConverter;
|
||||||
import javafx.util.converter.DoubleStringConverter;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.model.MarketModel;
|
import ru.trader.model.MarketModel;
|
||||||
@@ -63,13 +57,9 @@ public class SystemsEditorController {
|
|||||||
@FXML
|
@FXML
|
||||||
private ComboBox<SystemModel> system6;
|
private ComboBox<SystemModel> system6;
|
||||||
|
|
||||||
|
private Dialog<ButtonType> dlg;
|
||||||
private MarketModel market;
|
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
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
clnName.setCellFactory(TextFieldCell.forTableColumn(new DefaultStringConverter()));
|
clnName.setCellFactory(TextFieldCell.forTableColumn(new DefaultStringConverter()));
|
||||||
@@ -104,19 +94,43 @@ public class SystemsEditorController {
|
|||||||
system6.setItems(market.systemsProperty());
|
system6.setItems(market.systemsProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog(Parent parent, Parent content, SystemModel system){
|
private void createDialog(Parent owner, Parent content){
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString("sEditor.title"));
|
dlg = new Dialog<>();
|
||||||
dlg.setContent(content);
|
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||||
dlg.getActions().addAll(actSave, Dialog.ACTION_CANCEL);
|
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);
|
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){
|
if (system != null){
|
||||||
tblSystems.getItems().add(new SystemData(system));
|
tblSystems.getItems().add(new SystemData(system));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
add();
|
add();
|
||||||
}
|
}
|
||||||
dlg.show();
|
|
||||||
reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(){
|
public void add(){
|
||||||
@@ -153,7 +167,7 @@ public class SystemsEditorController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reset(){
|
private void clear(){
|
||||||
tblSystems.getItems().clear();
|
tblSystems.getItems().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,24 +3,21 @@ package ru.trader.controllers;
|
|||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.scene.control.Dialog;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.cell.TextFieldTableCell;
|
import javafx.scene.control.cell.TextFieldTableCell;
|
||||||
import javafx.util.converter.LongStringConverter;
|
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.OrderModel;
|
||||||
import ru.trader.model.support.BindingsHelper;
|
import ru.trader.model.support.BindingsHelper;
|
||||||
import ru.trader.view.support.Localization;
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class TopOrdersController {
|
public class TopOrdersController {
|
||||||
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TableView<OrderModel> tblOrders;
|
private TableView<OrderModel> tblOrders;
|
||||||
|
|
||||||
@@ -28,6 +25,7 @@ public class TopOrdersController {
|
|||||||
private TableColumn<OrderModel, Long> count;
|
private TableColumn<OrderModel, Long> count;
|
||||||
|
|
||||||
private OrderModel order;
|
private OrderModel order;
|
||||||
|
private Dialog<OrderModel> dlg;
|
||||||
|
|
||||||
private final List<OrderModel> orders = FXCollections.observableArrayList();
|
private final List<OrderModel> orders = FXCollections.observableArrayList();
|
||||||
|
|
||||||
@@ -38,26 +36,41 @@ public class TopOrdersController {
|
|||||||
BindingsHelper.setTableViewItems(tblOrders, orders);
|
BindingsHelper.setTableViewItems(tblOrders, orders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createDialog(Parent owner, Parent content){
|
||||||
public OrderModel showDialog(Parent parent, Parent content, Collection<OrderModel> orders) {
|
dlg = new Dialog<>();
|
||||||
|
if (owner != null) dlg.initOwner(owner.getScene().getWindow());
|
||||||
init(orders);
|
dlg.setTitle(Localization.getString("topOrders.title"));
|
||||||
|
dlg.getDialogPane().setContent(content);
|
||||||
Dialog dlg = new Dialog(parent, Localization.getString("topOrders.title"));
|
dlg.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||||
dlg.setContent(content);
|
dlg.setResultConverter(dialogButton -> {
|
||||||
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
|
if (dialogButton == ButtonType.OK) {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
dlg.setResizable(false);
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void init(Collection<OrderModel> orders) {
|
private void fill(Collection<OrderModel> orders) {
|
||||||
tblOrders.getSelectionModel().clearSelection();
|
tblOrders.getSelectionModel().clearSelection();
|
||||||
this.orders.addAll(orders);
|
this.orders.addAll(orders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clear(){
|
||||||
|
orders.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private void changeOrder(OrderModel order) {
|
private void changeOrder(OrderModel order) {
|
||||||
this.order = 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.confirm.remove=Are you sure you want to delete %s?
|
||||||
dialog.button.add=Add
|
dialog.button.add=Add
|
||||||
dialog.button.save=Save
|
dialog.button.save=Save
|
||||||
|
dialog.button.cancel=Cancel
|
||||||
dialog.button.edit=Edit
|
dialog.button.edit=Edit
|
||||||
dialog.button.remove=Remove
|
dialog.button.remove=Remove
|
||||||
dialog.button.clear=Clear
|
dialog.button.clear=Clear
|
||||||
|
|||||||
@@ -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.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.add=\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C
|
||||||
dialog.button.save=\u0421\u043E\u0445\u0440\u0430\u043D\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.edit=\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C
|
||||||
dialog.button.remove=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
|
dialog.button.remove=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
|
||||||
dialog.button.clear=\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C
|
dialog.button.clear=\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C
|
||||||
|
|||||||
Reference in New Issue
Block a user