fix wrong change editing cell on lost focus
This commit is contained in:
@@ -30,8 +30,11 @@ public class EditOfferCell extends TextFieldCell<StationUpdater.FakeOffer, Doubl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void outItem() {
|
protected void outItem() {
|
||||||
|
double d = 0;
|
||||||
StationUpdater.FakeOffer offer = (StationUpdater.FakeOffer) getTableRow().getItem();
|
StationUpdater.FakeOffer offer = (StationUpdater.FakeOffer) getTableRow().getItem();
|
||||||
double d = isSell? offer.getSprice() - offer.getOldSprice() : offer.getBprice() - offer.getOldBprice();
|
if (offer != null) {
|
||||||
|
d = isSell ? offer.getSprice() - offer.getOldSprice() : offer.getBprice() - offer.getOldBprice();
|
||||||
|
}
|
||||||
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();
|
||||||
|
|||||||
@@ -57,17 +57,13 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
|||||||
public void updateItem(T item, boolean empty) {
|
public void updateItem(T item, boolean empty) {
|
||||||
LOG.trace("Update edit");
|
LOG.trace("Update edit");
|
||||||
super.updateItem(item, empty);
|
super.updateItem(item, empty);
|
||||||
if (empty || getTableRow() == null) {
|
if (empty || item == null) {
|
||||||
setText(null);
|
setText(null);
|
||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (isEditing()) {
|
if (isEditing()) {
|
||||||
if (textField != null) {
|
cancelEdit();
|
||||||
textField.setText(getItemText());
|
|
||||||
}
|
|
||||||
setText(null);
|
|
||||||
setGraphic(textField);
|
|
||||||
} else {
|
} else {
|
||||||
outItem();
|
outItem();
|
||||||
}
|
}
|
||||||
@@ -77,6 +73,7 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
|||||||
@Override
|
@Override
|
||||||
public void cancelEdit() {
|
public void cancelEdit() {
|
||||||
LOG.trace("Cancel edit");
|
LOG.trace("Cancel edit");
|
||||||
|
//lost focus
|
||||||
if (!isCommit()) commit(false);
|
if (!isCommit()) commit(false);
|
||||||
if (isCommit()) {
|
if (isCommit()) {
|
||||||
super.cancelEdit();
|
super.cancelEdit();
|
||||||
@@ -93,12 +90,15 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
|
|||||||
textField = new TextField(getItemText());
|
textField = new TextField(getItemText());
|
||||||
textField.prefWidthProperty().bind(getTableColumn().widthProperty());
|
textField.prefWidthProperty().bind(getTableColumn().widthProperty());
|
||||||
textField.setPadding(Insets.EMPTY);
|
textField.setPadding(Insets.EMPTY);
|
||||||
textField.setOnKeyPressed(t -> {
|
textField.setOnAction(event -> {
|
||||||
if (t.getCode() == KeyCode.ENTER) {
|
|
||||||
if (commit(true)) ViewUtils.editNext(getTableView());
|
if (commit(true)) ViewUtils.editNext(getTableView());
|
||||||
} else if (t.getCode() == KeyCode.ESCAPE) {
|
event.consume();
|
||||||
|
});
|
||||||
|
textField.setOnKeyPressed(t -> {
|
||||||
|
if (t.getCode() == KeyCode.ESCAPE) {
|
||||||
textField = null;
|
textField = null;
|
||||||
cancelEdit();
|
cancelEdit();
|
||||||
|
t.consume();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user