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 @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();

View File

@@ -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.setOnAction(event -> {
if (commit(true)) ViewUtils.editNext(getTableView());
event.consume();
});
textField.setOnKeyPressed(t -> { textField.setOnKeyPressed(t -> {
if (t.getCode() == KeyCode.ENTER) { if (t.getCode() == KeyCode.ESCAPE) {
if (commit(true)) ViewUtils.editNext(getTableView());
} else if (t.getCode() == KeyCode.ESCAPE) {
textField = null; textField = null;
cancelEdit(); cancelEdit();
t.consume();
} }
}); });