- add group item
- add color indication on edit offer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package ru.trader.controllers;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyStringProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
@@ -12,6 +13,7 @@ import javafx.scene.control.TextField;
|
||||
import org.controlsfx.control.ButtonBar;
|
||||
import org.controlsfx.control.action.AbstractAction;
|
||||
import org.controlsfx.control.action.Action;
|
||||
import org.controlsfx.dialog.DefaultDialogAction;
|
||||
import org.controlsfx.dialog.Dialog;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -25,7 +27,7 @@ import ru.trader.view.support.Localization;
|
||||
import ru.trader.view.support.NumberField;
|
||||
import ru.trader.view.support.PriceStringConverter;
|
||||
import ru.trader.view.support.ViewUtils;
|
||||
import ru.trader.view.support.cells.TextFieldCell;
|
||||
import ru.trader.view.support.cells.EditOfferCell;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -48,6 +50,18 @@ public class VendorEditorController {
|
||||
}
|
||||
};
|
||||
|
||||
private final Action actCancel = new DefaultDialogAction(impl.org.controlsfx.i18n.Localization.asKey("dlg.cancel.button")) {
|
||||
{
|
||||
ButtonBar.setType(this, ButtonBar.ButtonType.CANCEL_CLOSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
items.getSelectionModel().selectFirst();
|
||||
super.handle(event);
|
||||
}
|
||||
};
|
||||
|
||||
@FXML
|
||||
private TextField name;
|
||||
|
||||
@@ -69,8 +83,8 @@ public class VendorEditorController {
|
||||
@FXML
|
||||
private void initialize() {
|
||||
items.getSelectionModel().setCellSelectionEnabled(true);
|
||||
buy.setCellFactory(TextFieldCell.forTableColumn(new PriceStringConverter()));
|
||||
sell.setCellFactory(TextFieldCell.forTableColumn(new PriceStringConverter()));
|
||||
buy.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), false));
|
||||
sell.setCellFactory(EditOfferCell.forTable(new PriceStringConverter(), true));
|
||||
actSave.disabledProperty().bind(x.wrongProperty().or(y.wrongProperty().or(z.wrongProperty())));
|
||||
fillItems();
|
||||
name.setOnAction((v)->x.requestFocus());
|
||||
@@ -90,7 +104,7 @@ public class VendorEditorController {
|
||||
}
|
||||
Dialog dlg = new Dialog(parent, Localization.getString(vendor == null ? "vEditor.title.add" : "vEditor.title.edit"));
|
||||
dlg.setContent(content);
|
||||
dlg.getActions().addAll(actSave, Dialog.Actions.CANCEL);
|
||||
dlg.getActions().addAll(actSave, actCancel);
|
||||
dlg.setResizable(false);
|
||||
return dlg.show();
|
||||
}
|
||||
@@ -111,6 +125,7 @@ public class VendorEditorController {
|
||||
y.setValue(0);
|
||||
z.setValue(0);
|
||||
items.getItems().forEach(FakeOffer::reset);
|
||||
items.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
private void fillItems() {
|
||||
@@ -226,14 +241,21 @@ public class VendorEditorController {
|
||||
|
||||
public void updateFromEMDN(){
|
||||
Station emdnData = World.getEMDN(vendor.getName());
|
||||
LOG.debug("Update from EMDN");
|
||||
if (emdnData == null) return;
|
||||
LOG.debug("Update {} from EMDN", vendor.getName());
|
||||
if (emdnData == null){
|
||||
LOG.trace("Not found in EMDN");
|
||||
return;
|
||||
}
|
||||
for (FakeOffer offer : items.getItems()) {
|
||||
ItemData data = emdnData.getData(offer.item.getId());
|
||||
LOG.debug("Update item {} to {}", offer.item.getName(), data);
|
||||
if (data != null){
|
||||
offer.setSprice(data.getBuy());
|
||||
offer.setBprice(data.getSell());
|
||||
if (offer.item.isMarketItem()){
|
||||
ItemData data = emdnData.getData(offer.item.getId());
|
||||
LOG.debug("Update item {} to {}", offer.item.getName(), data);
|
||||
if (data != null){
|
||||
offer.setSprice(data.getBuy());
|
||||
offer.setBprice(data.getSell());
|
||||
}
|
||||
} else {
|
||||
LOG.trace("Is not market item, skip");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,6 +335,14 @@ public class VendorEditorController {
|
||||
return this.item.equals(item);
|
||||
}
|
||||
|
||||
public double getOldSprice() {
|
||||
return sell != null ? sell.getPrice() : 0;
|
||||
}
|
||||
|
||||
public double getOldBprice() {
|
||||
return buy != null ? buy.getPrice() : 0;
|
||||
}
|
||||
|
||||
public void setSell(OfferModel sell) {
|
||||
this.sell = sell;
|
||||
sprice.set(sell.getPrice());
|
||||
@@ -324,10 +354,10 @@ public class VendorEditorController {
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
sprice.setValue(0);
|
||||
bprice.setValue(0);
|
||||
this.sell = null;
|
||||
this.buy = null;
|
||||
sprice.setValue(0);
|
||||
bprice.setValue(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,10 @@ public class ItemModel{
|
||||
|
||||
public String getId() {return item.getName();}
|
||||
|
||||
public boolean isMarketItem(){
|
||||
return item.getGroup() != null && item.getGroup().isMarket();
|
||||
}
|
||||
|
||||
public void setName(String value) {
|
||||
LOG.info("Change name of item {} to {}", item, name);
|
||||
market.updateName(this, value);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package ru.trader.view.support.cells;
|
||||
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableRow;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Callback;
|
||||
import javafx.util.StringConverter;
|
||||
import ru.trader.controllers.VendorEditorController;
|
||||
|
||||
public class EditOfferCell extends TextFieldCell<VendorEditorController.FakeOffer, Double> {
|
||||
private final static String CSS_CHANGE = "change";
|
||||
private final static String CSS_ADD = "add";
|
||||
private final static String CSS_REMOVE = "remove";
|
||||
private boolean isSell;
|
||||
|
||||
public EditOfferCell(StringConverter<Double> converter, boolean isSell) {
|
||||
super(converter);
|
||||
this.isSell = isSell;
|
||||
}
|
||||
|
||||
public static Callback<TableColumn<VendorEditorController.FakeOffer,Double>, TableCell<VendorEditorController.FakeOffer,Double>> forTable(final StringConverter<Double> converter, boolean isSell) {
|
||||
return list -> new EditOfferCell(converter, isSell);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void outItem() {
|
||||
VendorEditorController.FakeOffer offer = (VendorEditorController.FakeOffer) getTableRow().getItem();
|
||||
double d = isSell? offer.getSprice() - offer.getOldSprice() : offer.getBprice() - offer.getOldBprice();
|
||||
getStyleClass().removeAll(CSS_ADD, CSS_CHANGE, CSS_REMOVE);
|
||||
if (d!=0){
|
||||
HBox hBox = new HBox();
|
||||
Text nTxt = new Text(getConverter().toString(isSell ? offer.getSprice() : offer.getBprice()));
|
||||
Text diff = new Text(String.format(" (%+.0f)", d));
|
||||
if (isSell){
|
||||
getStyleClass().add(offer.isNewSell()? CSS_ADD : offer.isRemoveSell() ? CSS_REMOVE : CSS_CHANGE);
|
||||
} else {
|
||||
getStyleClass().add(offer.isNewBuy()? CSS_ADD : offer.isRemoveBuy() ? CSS_REMOVE : CSS_CHANGE);
|
||||
}
|
||||
hBox.getChildren().add(nTxt);
|
||||
if (!offer.isRemoveBuy() && !offer.isRemoveSell() && !offer.isNewBuy() && !offer.isNewSell()){
|
||||
hBox.getChildren().add(diff);
|
||||
}
|
||||
setText(null);
|
||||
setGraphic(hBox);
|
||||
} else {
|
||||
setText(getItemText());
|
||||
setGraphic(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.trader.view.support.cells;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.MouseButton;
|
||||
@@ -56,7 +57,7 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
||||
public void updateItem(T item, boolean empty) {
|
||||
LOG.trace("Update edit");
|
||||
super.updateItem(item, empty);
|
||||
if (empty) {
|
||||
if (empty || getTableRow() == null) {
|
||||
setText(null);
|
||||
setGraphic(null);
|
||||
|
||||
@@ -89,9 +90,9 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
||||
}
|
||||
|
||||
private void createTextField(){
|
||||
this.textField = new TextField(getItemText());
|
||||
this.setGraphic(textField);
|
||||
textField.prefWidthProperty().bind(this.getTableColumn().widthProperty());
|
||||
textField = new TextField(getItemText());
|
||||
textField.prefWidthProperty().bind(getTableColumn().widthProperty());
|
||||
textField.setPadding(Insets.EMPTY);
|
||||
textField.setOnKeyPressed(t -> {
|
||||
if (t.getCode() == KeyCode.ENTER) {
|
||||
if (commit(true)) ViewUtils.editNext(getTableView());
|
||||
@@ -104,7 +105,7 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
||||
}
|
||||
|
||||
|
||||
private String getItemText(){
|
||||
protected String getItemText(){
|
||||
return converter.toString(getItem());
|
||||
}
|
||||
|
||||
@@ -132,4 +133,7 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
||||
return textField == null;
|
||||
}
|
||||
|
||||
public StringConverter<T> getConverter() {
|
||||
return converter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,4 +83,21 @@ HBox.fields-group hbox-margin{
|
||||
.path-pane {
|
||||
-fx-padding: 10;
|
||||
-fx-alignment: center-left;
|
||||
}
|
||||
|
||||
/* EditOfferCell */
|
||||
#items .change {
|
||||
-fx-background-color: lightgreen;
|
||||
}
|
||||
|
||||
#items .remove {
|
||||
-fx-background-color: lightsalmon;
|
||||
}
|
||||
|
||||
#items .remove .text{
|
||||
-fx-strikethrough: true;
|
||||
}
|
||||
|
||||
#items .add {
|
||||
-fx-background-color: lightblue;
|
||||
}
|
||||
@@ -28,15 +28,15 @@
|
||||
<Button prefWidth="30" onAction="#add"><graphic><Glyph text="FontAwesome|PLUS"/></graphic></Button>
|
||||
<Button prefWidth="30" onAction="#updateFromEMDN"><graphic><Glyph text="FontAwesome|REFRESH"/></graphic></Button>
|
||||
</VBox>
|
||||
<TableView fx:id="items" prefWidth="375.0" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||
<TableView fx:id="items" prefWidth="395.0" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||
<columns>
|
||||
<TableColumn minWidth="200.0" text="%market.item.name" editable="false">
|
||||
<cellValueFactory><PropertyValueFactory property="name"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn fx:id="buy" minWidth="80.0" text="%market.offer.sell">
|
||||
<TableColumn fx:id="buy" minWidth="90.0" text="%market.offer.sell">
|
||||
<cellValueFactory><PropertyValueFactory property="bprice"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn fx:id="sell" minWidth="80.0" text="%market.offer.buy">
|
||||
<TableColumn fx:id="sell" minWidth="90.0" text="%market.offer.buy">
|
||||
<cellValueFactory><PropertyValueFactory property="sprice"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
</columns>
|
||||
|
||||
Reference in New Issue
Block a user