add reset offer button on edit vendor
This commit is contained in:
@@ -1,18 +1,28 @@
|
|||||||
package ru.trader.view.support.cells;
|
package ru.trader.view.support.cells;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.TableCell;
|
import javafx.scene.control.TableCell;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.TableRow;
|
import javafx.scene.control.TableRow;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import javafx.scene.layout.Border;
|
||||||
|
import javafx.scene.layout.BorderStroke;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
|
import org.controlsfx.glyphfont.Glyph;
|
||||||
|
import org.controlsfx.glyphfont.GlyphFontRegistry;
|
||||||
import ru.trader.controllers.VendorEditorController;
|
import ru.trader.controllers.VendorEditorController;
|
||||||
|
|
||||||
public class EditOfferCell extends TextFieldCell<VendorEditorController.FakeOffer, Double> {
|
public class EditOfferCell extends TextFieldCell<VendorEditorController.FakeOffer, Double> {
|
||||||
private final static String CSS_CHANGE = "change";
|
private final static String CSS_CHANGE = "change";
|
||||||
private final static String CSS_ADD = "add";
|
private final static String CSS_ADD = "add";
|
||||||
private final static String CSS_REMOVE = "remove";
|
private final static String CSS_REMOVE = "remove";
|
||||||
|
private final static String CSS_RESET_ICON = "reset";
|
||||||
private boolean isSell;
|
private boolean isSell;
|
||||||
|
|
||||||
public EditOfferCell(StringConverter<Double> converter, boolean isSell) {
|
public EditOfferCell(StringConverter<Double> converter, boolean isSell) {
|
||||||
@@ -31,8 +41,8 @@ public class EditOfferCell extends TextFieldCell<VendorEditorController.FakeOffe
|
|||||||
getStyleClass().removeAll(CSS_ADD, CSS_CHANGE, CSS_REMOVE);
|
getStyleClass().removeAll(CSS_ADD, CSS_CHANGE, CSS_REMOVE);
|
||||||
if (d!=0){
|
if (d!=0){
|
||||||
HBox hBox = new HBox();
|
HBox hBox = new HBox();
|
||||||
|
hBox.prefWidthProperty().bind(getTableColumn().widthProperty());
|
||||||
Text nTxt = new Text(getConverter().toString(isSell ? offer.getSprice() : offer.getBprice()));
|
Text nTxt = new Text(getConverter().toString(isSell ? offer.getSprice() : offer.getBprice()));
|
||||||
Text diff = new Text(String.format(" (%+.0f)", d));
|
|
||||||
if (isSell){
|
if (isSell){
|
||||||
getStyleClass().add(offer.isNewSell()? CSS_ADD : offer.isRemoveSell() ? CSS_REMOVE : CSS_CHANGE);
|
getStyleClass().add(offer.isNewSell()? CSS_ADD : offer.isRemoveSell() ? CSS_REMOVE : CSS_CHANGE);
|
||||||
} else {
|
} else {
|
||||||
@@ -40,8 +50,24 @@ public class EditOfferCell extends TextFieldCell<VendorEditorController.FakeOffe
|
|||||||
}
|
}
|
||||||
hBox.getChildren().add(nTxt);
|
hBox.getChildren().add(nTxt);
|
||||||
if (!offer.isRemoveBuy() && !offer.isRemoveSell() && !offer.isNewBuy() && !offer.isNewSell()){
|
if (!offer.isRemoveBuy() && !offer.isRemoveSell() && !offer.isNewBuy() && !offer.isNewSell()){
|
||||||
|
Text diff = new Text(String.format(" (%+.0f)", d));
|
||||||
hBox.getChildren().add(diff);
|
hBox.getChildren().add(diff);
|
||||||
}
|
}
|
||||||
|
Glyph glyph = (Glyph) GlyphFontRegistry.glyph("FontAwesome|REMOVE");
|
||||||
|
glyph.addEventFilter(MouseEvent.MOUSE_CLICKED, (e) -> {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
if (isSell) {
|
||||||
|
offer.setSprice(offer.getOldSprice());
|
||||||
|
} else {
|
||||||
|
offer.setBprice(offer.getOldBprice());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
e.consume();
|
||||||
|
});
|
||||||
|
HBox icon = new HBox(glyph);
|
||||||
|
icon.getStyleClass().add(CSS_RESET_ICON);
|
||||||
|
HBox.setHgrow(icon, Priority.ALWAYS);
|
||||||
|
hBox.getChildren().add(icon);
|
||||||
setText(null);
|
setText(null);
|
||||||
setGraphic(hBox);
|
setGraphic(hBox);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -101,3 +101,16 @@ HBox.fields-group hbox-margin{
|
|||||||
#items .add {
|
#items .add {
|
||||||
-fx-background-color: lightblue;
|
-fx-background-color: lightblue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#items HBox.reset {
|
||||||
|
-fx-padding: 0 4;
|
||||||
|
-fx-alignment: top-right;
|
||||||
|
}
|
||||||
|
|
||||||
|
#items HBox.reset Glyph {
|
||||||
|
-fx-opacity: 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
#items HBox.reset Glyph:hover {
|
||||||
|
-fx-opacity: 1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user