Archived
0

fix wrong change editing cell on lost focus

This commit is contained in:
iMoHax
2014-11-08 22:30:05 +03:00
parent 151eb05a67
commit 659d59df97
2 changed files with 13 additions and 10 deletions

View File

@@ -30,8 +30,11 @@ public class EditOfferCell extends TextFieldCell<StationUpdater.FakeOffer, Doubl
@Override
protected void outItem() {
double d = 0;
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);
if (d !=0 ){
HBox hBox = new HBox();

View File

@@ -57,17 +57,13 @@ 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 || getTableRow() == null) {
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
if (isEditing()) {
if (textField != null) {
textField.setText(getItemText());
}
setText(null);
setGraphic(textField);
cancelEdit();
} else {
outItem();
}
@@ -77,6 +73,7 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
@Override
public void cancelEdit() {
LOG.trace("Cancel edit");
//lost focus
if (!isCommit()) commit(false);
if (isCommit()) {
super.cancelEdit();
@@ -93,12 +90,15 @@ public class TextFieldCell<S,T> extends TableCell<S,T> {
textField = new TextField(getItemText());
textField.prefWidthProperty().bind(getTableColumn().widthProperty());
textField.setPadding(Insets.EMPTY);
textField.setOnAction(event -> {
if (commit(true)) ViewUtils.editNext(getTableView());
event.consume();
});
textField.setOnKeyPressed(t -> {
if (t.getCode() == KeyCode.ENTER) {
if (commit(true)) ViewUtils.editNext(getTableView());
} else if (t.getCode() == KeyCode.ESCAPE) {
if (t.getCode() == KeyCode.ESCAPE) {
textField = null;
cancelEdit();
t.consume();
}
});